mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 00:10:51 +00:00
Updated Rector to commit 790889c4c7
790889c4c7
[TypedPropertyRector] Remove private property only, to keep other rules work separately (#1496)
This commit is contained in:
parent
79317e0a0f
commit
b54d1ce71e
|
@ -1,4 +1,4 @@
|
|||
# 505 Rules Overview
|
||||
# 506 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
- [DowngradePhp74](#downgradephp74) (12)
|
||||
|
||||
- [DowngradePhp80](#downgradephp80) (23)
|
||||
- [DowngradePhp80](#downgradephp80) (24)
|
||||
|
||||
- [DowngradePhp81](#downgradephp81) (8)
|
||||
|
||||
|
@ -5411,6 +5411,25 @@ Remove reflection `getAttributes()` class method code
|
|||
|
||||
<br>
|
||||
|
||||
### DowngradeReflectionPropertyGetDefaultValueRector
|
||||
|
||||
Downgrade `ReflectionProperty->getDefaultValue()`
|
||||
|
||||
- class: [`Rector\DowngradePhp80\Rector\MethodCall\DowngradeReflectionPropertyGetDefaultValueRector`](../rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionPropertyGetDefaultValueRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run(ReflectionProperty $reflectionProperty)
|
||||
{
|
||||
- return $reflectionProperty->getDefaultValue();
|
||||
+ return $reflectionProperty->getDeclaringClass()->getDefaultProperties()[$reflectionProperty->getName()] ?? null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeStaticTypeDeclarationRector
|
||||
|
||||
Remove "static" return and param type, add a `"@param` `$this"` and `"@return` `$this"` tag instead
|
||||
|
@ -7747,26 +7766,8 @@ Add null default to properties with PHP 7.4 property nullable type
|
|||
|
||||
Changes property `@var` annotations from annotation to type.
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Php74\Rector\Property\TypedPropertyRector`](../rules/Php74/Rector/Property/TypedPropertyRector.php)
|
||||
|
||||
```php
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(TypedPropertyRector::class)
|
||||
->configure([
|
||||
TypedPropertyRector::PRIVATE_PROPERTY_ONLY => false,
|
||||
]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
|
@ -8247,10 +8248,10 @@ Change docs to intersection types, where possible (properties are covered by Typ
|
|||
final class SomeClass
|
||||
{
|
||||
- /**
|
||||
- * @param string&int $types
|
||||
- * @param Foo&Bar $types
|
||||
- */
|
||||
- public function process($types)
|
||||
+ public function process(string&int $types)
|
||||
+ public function process(Foo&Bar $types)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,13 @@ use PhpParser\Node\Stmt\Class_;
|
|||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Trait_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Type\Generic\TemplateType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\NodeAnalyzer\PropertyAnalyzer;
|
||||
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
|
@ -30,7 +31,7 @@ use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
|||
use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer;
|
||||
use Rector\VendorLocker\VendorLockResolver;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://wiki.php.net/rfc/typed_properties_v2#proposal
|
||||
|
@ -40,18 +41,8 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
* @see \Rector\Tests\Php74\Rector\Property\TypedPropertyRector\DoctrineTypedPropertyRectorTest
|
||||
* @see \Rector\Tests\Php74\Rector\Property\TypedPropertyRector\ImportedTest
|
||||
*/
|
||||
final class TypedPropertyRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface, \Rector\VersionBonding\Contract\MinPhpVersionInterface
|
||||
final class TypedPropertyRector extends \Rector\Core\Rector\AbstractRector implements \Rector\VersionBonding\Contract\MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PRIVATE_PROPERTY_ONLY = 'PRIVATE_PROPERTY_ONLY';
|
||||
/**
|
||||
* If want to keep BC, it can be set to true
|
||||
* @see https://3v4l.org/spl4P
|
||||
* @var bool
|
||||
*/
|
||||
private $privatePropertyOnly = \false;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer
|
||||
|
@ -111,7 +102,7 @@ final class TypedPropertyRector extends \Rector\Core\Rector\AbstractRector imple
|
|||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Changes property `@var` annotations from annotation to type.', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Changes property `@var` annotations from annotation to type.', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
/**
|
||||
|
@ -126,7 +117,7 @@ final class SomeClass
|
|||
private int $count;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [self::PRIVATE_PROPERTY_ONLY => \false])]);
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
|
@ -140,7 +131,8 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if ($this->shouldSkipProperty($node)) {
|
||||
$scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
|
||||
if ($this->shouldSkipProperty($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$varType = $this->propertyTypeInferer->inferProperty($node);
|
||||
|
@ -172,13 +164,6 @@ CODE_SAMPLE
|
|||
$node->type = $propertyTypeNode;
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$this->privatePropertyOnly = $configuration[self::PRIVATE_PROPERTY_ONLY] ?? \false;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return \Rector\Core\ValueObject\PhpVersionFeature::TYPED_PROPERTIES;
|
||||
|
@ -226,7 +211,7 @@ CODE_SAMPLE
|
|||
}
|
||||
$onlyProperty->default = $this->nodeFactory->createNull();
|
||||
}
|
||||
private function shouldSkipProperty(\PhpParser\Node\Stmt\Property $property) : bool
|
||||
private function shouldSkipProperty(\PhpParser\Node\Stmt\Property $property, \PHPStan\Analyser\Scope $scope) : bool
|
||||
{
|
||||
// type is already set → skip
|
||||
if ($property->type !== null) {
|
||||
|
@ -236,8 +221,12 @@ CODE_SAMPLE
|
|||
if (\count($property->props) > 1) {
|
||||
return \true;
|
||||
}
|
||||
$trait = $this->betterNodeFinder->findParentType($property, \PhpParser\Node\Stmt\Trait_::class);
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
|
||||
return \true;
|
||||
}
|
||||
// skip trait properties, as they ar unpredictable based on class context they appear in
|
||||
$trait = $this->betterNodeFinder->findParentType($property, \PhpParser\Node\Stmt\Trait_::class);
|
||||
if ($trait instanceof \PhpParser\Node\Stmt\Trait_) {
|
||||
return \true;
|
||||
}
|
||||
|
@ -246,13 +235,11 @@ CODE_SAMPLE
|
|||
if ($classLike instanceof \PhpParser\Node\Stmt\ClassLike && $this->isModifiedByTrait($classLike, $propertyName)) {
|
||||
return \true;
|
||||
}
|
||||
if (!$this->privatePropertyOnly) {
|
||||
return $this->propertyAnalyzer->hasForbiddenType($property);
|
||||
}
|
||||
if ($property->isPrivate()) {
|
||||
return $this->propertyAnalyzer->hasForbiddenType($property);
|
||||
}
|
||||
return \true;
|
||||
// is we're in final class, the type can be changed
|
||||
return !($property->isProtected() && $classReflection->isFinal() && $classReflection->getParents() === []);
|
||||
}
|
||||
private function isModifiedByTrait(\PhpParser\Node\Stmt\ClassLike $classLike, string $propertyName) : bool
|
||||
{
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f6c3e95d7bc61d0baeef95fa98721000871db0df';
|
||||
public const PACKAGE_VERSION = '790889c4c7e69271200ee6bea82d97a72d84e3ee';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-12-14 15:15:08';
|
||||
public const RELEASE_DATE = '2021-12-14 23:48:05';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20211214\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36::getLoader();
|
||||
return ComposerAutoloaderInit1ecfa85b9e38c1acb2536938ceb51633::getLoader();
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36
|
||||
class ComposerAutoloaderInit1ecfa85b9e38c1acb2536938ceb51633
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1ecfa85b9e38c1acb2536938ceb51633', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1ecfa85b9e38c1acb2536938ceb51633', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit12bb9e769debccf33e537fe22597fd36::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1ecfa85b9e38c1acb2536938ceb51633::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit12bb9e769debccf33e537fe22597fd36::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit1ecfa85b9e38c1acb2536938ceb51633::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire12bb9e769debccf33e537fe22597fd36($fileIdentifier, $file);
|
||||
composerRequire1ecfa85b9e38c1acb2536938ceb51633($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire12bb9e769debccf33e537fe22597fd36($fileIdentifier, $file)
|
||||
function composerRequire1ecfa85b9e38c1acb2536938ceb51633($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit12bb9e769debccf33e537fe22597fd36
|
||||
class ComposerStaticInit1ecfa85b9e38c1acb2536938ceb51633
|
||||
{
|
||||
public static $files = array (
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
|
@ -3821,9 +3821,9 @@ class ComposerStaticInit12bb9e769debccf33e537fe22597fd36
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit12bb9e769debccf33e537fe22597fd36::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit12bb9e769debccf33e537fe22597fd36::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit12bb9e769debccf33e537fe22597fd36::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1ecfa85b9e38c1acb2536938ceb51633::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1ecfa85b9e38c1acb2536938ceb51633::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1ecfa85b9e38c1acb2536938ceb51633::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20211214\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36', false) && !interface_exists('ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36', false) && !trait_exists('ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36', false)) {
|
||||
spl_autoload_call('RectorPrefix20211214\ComposerAutoloaderInit12bb9e769debccf33e537fe22597fd36');
|
||||
if (!class_exists('ComposerAutoloaderInit1ecfa85b9e38c1acb2536938ceb51633', false) && !interface_exists('ComposerAutoloaderInit1ecfa85b9e38c1acb2536938ceb51633', false) && !trait_exists('ComposerAutoloaderInit1ecfa85b9e38c1acb2536938ceb51633', false)) {
|
||||
spl_autoload_call('RectorPrefix20211214\ComposerAutoloaderInit1ecfa85b9e38c1acb2536938ceb51633');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20211214\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -78,9 +78,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20211214\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire12bb9e769debccf33e537fe22597fd36')) {
|
||||
function composerRequire12bb9e769debccf33e537fe22597fd36() {
|
||||
return \RectorPrefix20211214\composerRequire12bb9e769debccf33e537fe22597fd36(...func_get_args());
|
||||
if (!function_exists('composerRequire1ecfa85b9e38c1acb2536938ceb51633')) {
|
||||
function composerRequire1ecfa85b9e38c1acb2536938ceb51633() {
|
||||
return \RectorPrefix20211214\composerRequire1ecfa85b9e38c1acb2536938ceb51633(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user