Updated Rector to commit b047c81634f8325b94d6e5b39fae6a599f65bca8

b047c81634 [automated] Re-Generate Nodes/Rectors Documentation (#2706)
This commit is contained in:
Tomas Votruba 2022-07-24 00:40:22 +00:00
parent d6319ec783
commit 8e5d4128e7
15 changed files with 122 additions and 189 deletions

View File

@ -1,4 +1,4 @@
# 413 Rules Overview
# 409 Rules Overview
<br>
@ -14,7 +14,7 @@
- [Composer](#composer) (6)
- [DeadCode](#deadcode) (50)
- [DeadCode](#deadcode) (49)
- [DependencyInjection](#dependencyinjection) (2)
@ -56,7 +56,7 @@
- [PostRector](#postrector) (6)
- [Privatization](#privatization) (10)
- [Privatization](#privatization) (8)
- [Removing](#removing) (6)
@ -70,7 +70,7 @@
- [Transform](#transform) (35)
- [TypeDeclaration](#typedeclaration) (30)
- [TypeDeclaration](#typedeclaration) (29)
- [Visibility](#visibility) (3)
@ -3758,30 +3758,6 @@ Change ternary of bool : false to && bool
<br>
### UnwrapFutureCompatibleIfFunctionExistsRector
Remove functions exists if with else for always existing
- class: [`Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfFunctionExistsRector`](../rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfFunctionExistsRector.php)
```diff
class SomeClass
{
public function run()
{
// session locking trough other addons
- if (function_exists('session_abort')) {
- session_abort();
- } else {
- session_write_close();
- }
+ session_abort();
}
}
```
<br>
### UnwrapFutureCompatibleIfPhpVersionRector
Remove php version checks if they are passed
@ -4275,16 +4251,16 @@ Renames value variable name in foreach loop to match expression variable
```diff
class SomeClass
{
public function run()
{
$array = [];
- foreach ($variables as $property) {
- $array[] = $property;
+ foreach ($variables as $variable) {
+ $array[] = $variable;
public function run()
{
$array = [];
- foreach ($variables as $property) {
- $array[] = $property;
+ foreach ($variables as $variable) {
+ $array[] = $variable;
}
}
}
}
```
<br>
@ -6688,28 +6664,6 @@ Change global `$variables` to private properties
<br>
### ChangeLocalPropertyToVariableRector
Change local property used in single method to local variable
- class: [`Rector\Privatization\Rector\Class_\ChangeLocalPropertyToVariableRector`](../rules/Privatization/Rector/Class_/ChangeLocalPropertyToVariableRector.php)
```diff
class SomeClass
{
- private $count;
public function run()
{
- $this->count = 5;
- return $this->count;
+ $count = 5;
+ return $count;
}
}
```
<br>
### ChangeReadOnlyPropertyWithDefaultValueToConstantRector
Change property with read only status with default value to constant
@ -6857,32 +6811,6 @@ Privatize getter of local property to property
<br>
### RepeatedLiteralToClassConstantRector
Replace repeated strings with constant
- class: [`Rector\Privatization\Rector\Class_\RepeatedLiteralToClassConstantRector`](../rules/Privatization/Rector/Class_/RepeatedLiteralToClassConstantRector.php)
```diff
class SomeClass
{
+ /**
+ * @var string
+ */
+ private const REQUIRES = 'requires';
public function run($key, $items)
{
- if ($key === 'requires') {
- return $items['requires'];
+ if ($key === self::REQUIRES) {
+ return $items[self::REQUIRES];
}
}
}
```
<br>
### ReplaceStringWithClassConstantRector
Replace string values in specific method call by constant of provided class
@ -9256,6 +9184,30 @@ return static function (RectorConfig $rectorConfig): void {
<br>
### AddReturnTypeDeclarationBasedOnParentClassMethodRector
Add missing return type declaration based on parent class method
- class: [`Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationBasedOnParentClassMethodRector`](../rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php)
```diff
class A
{
public function execute(): int
{
}
}
class B extends A{
- public function execute()
+ public function execute(): int
{
}
}
```
<br>
### AddReturnTypeDeclarationRector
Changes defined return typehint of method and class.
@ -9349,29 +9301,6 @@ Add array shape exact types based on constant keys of array
<br>
### FormerNullableArgumentToScalarTypedRector
Change null in argument, that is now not nullable anymore
- class: [`Rector\TypeDeclaration\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector`](../rules/TypeDeclaration/Rector/MethodCall/FormerNullableArgumentToScalarTypedRector.php)
```diff
final class SomeClass
{
public function run()
{
- $this->setValue(null);
+ $this->setValue('');
}
public function setValue(string $value)
{
}
}
```
<br>
### ParamAnnotationIncorrectNullableRector
Add or remove null type from `@param` phpdoc typehint based on php parameter type declaration
@ -9677,30 +9606,6 @@ Add strict return array type based on created empty array and returned
<br>
### ReturnTypeFromStrictTypedCallRector
Add return type from strict return type of call
- class: [`Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector`](../rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php)
```diff
final class SomeClass
{
- public function getData()
+ public function getData(): int
{
return $this->getNumber();
}
private function getNumber(): int
{
return 1000;
}
}
```
<br>
### ReturnTypeFromStrictTypedPropertyRector
Add return method return type based on strict typed property

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '0.13.9';
public const PACKAGE_VERSION = 'b047c81634f8325b94d6e5b39fae6a599f65bca8';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-07-23 10:56:14';
public const RELEASE_DATE = '2022-07-24 00:33:27';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitcbec1f9f3f687d5f66e55b545df16d48::getLoader();
return ComposerAutoloaderInit6fccf0f35ac80d124b584b10cea4b02b::getLoader();

View File

@ -1075,6 +1075,7 @@ return array(
'RectorPrefix202207\\Symplify\\Astral\\StaticFactory\\SimpleNameResolverStaticFactory' => $vendorDir . '/symplify/astral/src/StaticFactory/SimpleNameResolverStaticFactory.php',
'RectorPrefix202207\\Symplify\\Astral\\TypeAnalyzer\\ClassMethodReturnTypeResolver' => $vendorDir . '/symplify/astral/src/TypeAnalyzer/ClassMethodReturnTypeResolver.php',
'RectorPrefix202207\\Symplify\\Astral\\TypeAnalyzer\\ContainsTypeAnalyser' => $vendorDir . '/symplify/astral/src/TypeAnalyzer/ContainsTypeAnalyser.php',
'RectorPrefix202207\\Symplify\\Astral\\TypeAwareNodeFinder' => $vendorDir . '/symplify/astral/src/TypeAwareNodeFinder.php',
'RectorPrefix202207\\Symplify\\Astral\\ValueObject\\AstralConfig' => $vendorDir . '/symplify/astral/src/ValueObject/AstralConfig.php',
'RectorPrefix202207\\Symplify\\Astral\\ValueObject\\AttributeKey' => $vendorDir . '/symplify/astral/src/ValueObject/AttributeKey.php',
'RectorPrefix202207\\Symplify\\Astral\\ValueObject\\NodeBuilder\\ClassBuilder' => $vendorDir . '/symplify/astral/src/ValueObject/NodeBuilder/ClassBuilder.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitcbec1f9f3f687d5f66e55b545df16d48
class ComposerAutoloaderInit6fccf0f35ac80d124b584b10cea4b02b
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitcbec1f9f3f687d5f66e55b545df16d48
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitcbec1f9f3f687d5f66e55b545df16d48', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit6fccf0f35ac80d124b584b10cea4b02b', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitcbec1f9f3f687d5f66e55b545df16d48', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit6fccf0f35ac80d124b584b10cea4b02b', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitcbec1f9f3f687d5f66e55b545df16d48::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit6fccf0f35ac80d124b584b10cea4b02b::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitcbec1f9f3f687d5f66e55b545df16d48::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit6fccf0f35ac80d124b584b10cea4b02b::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirecbec1f9f3f687d5f66e55b545df16d48($fileIdentifier, $file);
composerRequire6fccf0f35ac80d124b584b10cea4b02b($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitcbec1f9f3f687d5f66e55b545df16d48
* @param string $file
* @return void
*/
function composerRequirecbec1f9f3f687d5f66e55b545df16d48($fileIdentifier, $file)
function composerRequire6fccf0f35ac80d124b584b10cea4b02b($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitcbec1f9f3f687d5f66e55b545df16d48
class ComposerStaticInit6fccf0f35ac80d124b584b10cea4b02b
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -1382,6 +1382,7 @@ class ComposerStaticInitcbec1f9f3f687d5f66e55b545df16d48
'RectorPrefix202207\\Symplify\\Astral\\StaticFactory\\SimpleNameResolverStaticFactory' => __DIR__ . '/..' . '/symplify/astral/src/StaticFactory/SimpleNameResolverStaticFactory.php',
'RectorPrefix202207\\Symplify\\Astral\\TypeAnalyzer\\ClassMethodReturnTypeResolver' => __DIR__ . '/..' . '/symplify/astral/src/TypeAnalyzer/ClassMethodReturnTypeResolver.php',
'RectorPrefix202207\\Symplify\\Astral\\TypeAnalyzer\\ContainsTypeAnalyser' => __DIR__ . '/..' . '/symplify/astral/src/TypeAnalyzer/ContainsTypeAnalyser.php',
'RectorPrefix202207\\Symplify\\Astral\\TypeAwareNodeFinder' => __DIR__ . '/..' . '/symplify/astral/src/TypeAwareNodeFinder.php',
'RectorPrefix202207\\Symplify\\Astral\\ValueObject\\AstralConfig' => __DIR__ . '/..' . '/symplify/astral/src/ValueObject/AstralConfig.php',
'RectorPrefix202207\\Symplify\\Astral\\ValueObject\\AttributeKey' => __DIR__ . '/..' . '/symplify/astral/src/ValueObject/AttributeKey.php',
'RectorPrefix202207\\Symplify\\Astral\\ValueObject\\NodeBuilder\\ClassBuilder' => __DIR__ . '/..' . '/symplify/astral/src/ValueObject/NodeBuilder/ClassBuilder.php',
@ -3403,9 +3404,9 @@ class ComposerStaticInitcbec1f9f3f687d5f66e55b545df16d48
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitcbec1f9f3f687d5f66e55b545df16d48::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitcbec1f9f3f687d5f66e55b545df16d48::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitcbec1f9f3f687d5f66e55b545df16d48::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit6fccf0f35ac80d124b584b10cea4b02b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6fccf0f35ac80d124b584b10cea4b02b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6fccf0f35ac80d124b584b10cea4b02b::$classMap;
}, null, ClassLoader::class);
}

View File

@ -3329,12 +3329,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/symplify\/astral.git",
"reference": "41af155f03a9afc053ea6dfcb7b913b23ae147e3"
"reference": "f067c3f0eed8feb114b106d1350d2ab089a589a1"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symplify\/astral\/zipball\/41af155f03a9afc053ea6dfcb7b913b23ae147e3",
"reference": "41af155f03a9afc053ea6dfcb7b913b23ae147e3",
"url": "https:\/\/api.github.com\/repos\/symplify\/astral\/zipball\/f067c3f0eed8feb114b106d1350d2ab089a589a1",
"reference": "f067c3f0eed8feb114b106d1350d2ab089a589a1",
"shasum": ""
},
"require": {
@ -3375,7 +3375,7 @@
"phpunit\/phpunit": "^9.5.21",
"symplify\/easy-testing": "^11.1"
},
"time": "2022-07-21T11:41:12+00:00",
"time": "2022-07-23T20:06:40+00:00",
"default-branch": true,
"type": "phpstan-extension",
"extra": {
@ -3501,12 +3501,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/symplify\/composer-json-manipulator.git",
"reference": "a362564587a10933302b01aaf69d5e44471d0aaa"
"reference": "05b7fa14b312a300493307a3640339ae017f80e9"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symplify\/composer-json-manipulator\/zipball\/a362564587a10933302b01aaf69d5e44471d0aaa",
"reference": "a362564587a10933302b01aaf69d5e44471d0aaa",
"url": "https:\/\/api.github.com\/repos\/symplify\/composer-json-manipulator\/zipball\/05b7fa14b312a300493307a3640339ae017f80e9",
"reference": "05b7fa14b312a300493307a3640339ae017f80e9",
"shasum": ""
},
"require": {
@ -3543,7 +3543,7 @@
"require-dev": {
"phpunit\/phpunit": "^9.5.21"
},
"time": "2022-07-21T11:41:06+00:00",
"time": "2022-07-23T20:06:46+00:00",
"default-branch": true,
"type": "symfony-bundle",
"extra": {
@ -3984,12 +3984,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/symplify\/smart-file-system.git",
"reference": "bc70f946fbc31096d46ed12694f50f9dc3a74990"
"reference": "1587dc4e25e228b54c536857044cd86fbc3493c0"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symplify\/smart-file-system\/zipball\/bc70f946fbc31096d46ed12694f50f9dc3a74990",
"reference": "bc70f946fbc31096d46ed12694f50f9dc3a74990",
"url": "https:\/\/api.github.com\/repos\/symplify\/smart-file-system\/zipball\/1587dc4e25e228b54c536857044cd86fbc3493c0",
"reference": "1587dc4e25e228b54c536857044cd86fbc3493c0",
"shasum": ""
},
"require": {
@ -4025,7 +4025,7 @@
"nette\/finder": "^2.5.3",
"phpunit\/phpunit": "^9.5.21"
},
"time": "2022-07-21T11:41:17+00:00",
"time": "2022-07-23T20:07:13+00:00",
"default-branch": true,
"type": "library",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@ services:
- Symplify\SmartFileSystem\Finder\FinderSanitizer
- Symplify\Astral\Reflection\ReflectionParser
- Symplify\Astral\TypeAwareNodeFinder
- Symplify\Astral\PhpParser\SmartPhpParserFactory
-
type: Symplify\Astral\PhpParser\SmartPhpParser

View File

@ -3,17 +3,16 @@
declare (strict_types=1);
namespace RectorPrefix202207\Symplify\Astral\Reflection;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use PhpParser\NodeFinder;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
use RectorPrefix202207\Symplify\Astral\PhpParser\SmartPhpParser;
use RectorPrefix202207\Symplify\Astral\TypeAwareNodeFinder;
use Throwable;
/**
* @api
@ -29,26 +28,13 @@ final class ReflectionParser
*/
private $smartPhpParser;
/**
* @var \PhpParser\NodeFinder
* @var \Symplify\Astral\TypeAwareNodeFinder
*/
private $nodeFinder;
public function __construct(SmartPhpParser $smartPhpParser, NodeFinder $nodeFinder)
private $typeAwareNodeFinder;
public function __construct(SmartPhpParser $smartPhpParser, TypeAwareNodeFinder $typeAwareNodeFinder)
{
$this->smartPhpParser = $smartPhpParser;
$this->nodeFinder = $nodeFinder;
}
public function parsePHPStanMethodReflection(MethodReflection $methodReflection) : ?ClassMethod
{
$classReflection = $methodReflection->getDeclaringClass();
$fileName = $classReflection->getFileName();
if ($fileName === null) {
return null;
}
$class = $this->parseFilenameToClass($fileName);
if (!$class instanceof Node) {
return null;
}
return $class->getMethod($methodReflection->getName());
$this->typeAwareNodeFinder = $typeAwareNodeFinder;
}
/**
* @param \ReflectionMethod|\PHPStan\Reflection\MethodReflection $reflectionMethod
@ -105,11 +91,11 @@ final class ReflectionParser
// not reachable
return null;
}
$class = $this->nodeFinder->findFirstInstanceOf($stmts, ClassLike::class);
if (!$class instanceof ClassLike) {
$classLike = $this->typeAwareNodeFinder->findFirstInstanceOf($stmts, ClassLike::class);
if (!$classLike instanceof ClassLike) {
return null;
}
$this->classesByFilename[$fileName] = $class;
return $class;
$this->classesByFilename[$fileName] = $classLike;
return $classLike;
}
}

View File

@ -36,10 +36,10 @@ final class ClassMethodReturnTypeResolver
return new MixedType();
}
$extendedMethodReflection = $classReflection->getMethod($methodName, $scope);
$functionVariant = ParametersAcceptorSelector::selectSingle($extendedMethodReflection->getVariants());
if (!$functionVariant instanceof FunctionVariant) {
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($extendedMethodReflection->getVariants());
if (!$parametersAcceptor instanceof FunctionVariant) {
return new MixedType();
}
return $functionVariant->getReturnType();
return $parametersAcceptor->getReturnType();
}
}

View File

@ -0,0 +1,40 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202207\Symplify\Astral;
use PhpParser\Node;
use PhpParser\NodeFinder;
final class TypeAwareNodeFinder
{
/**
* @var \PhpParser\NodeFinder
*/
private $nodeFinder;
public function __construct(NodeFinder $nodeFinder)
{
$this->nodeFinder = $nodeFinder;
}
/**
* @template TNode as Node
*
* @param mixed[]|\PhpParser\Node $nodes
* @param class-string<TNode> $type
* @return TNode|null
*/
public function findFirstInstanceOf($nodes, string $type) : ?Node
{
return $this->nodeFinder->findFirstInstanceOf($nodes, $type);
}
/**
* @template TNode as Node
*
* @param mixed[]|\PhpParser\Node $nodes
* @param class-string<TNode> $type
* @return TNode[]
*/
public function findInstanceOf($nodes, string $type) : array
{
return $this->nodeFinder->findInstanceOf($nodes, $type);
}
}

View File

@ -29,7 +29,7 @@ final class JsonInliner
$inlineSections = $this->parameterProvider->provideArrayParameter(Option::INLINE_SECTIONS);
foreach ($inlineSections as $inlineSection) {
$pattern = '#("' . \preg_quote($inlineSection, '#') . '": )\\[(.*?)\\](,)#ms';
$jsonContent = Strings::replace($jsonContent, $pattern, function (array $match) : string {
$jsonContent = Strings::replace($jsonContent, $pattern, static function (array $match) : string {
$inlined = Strings::replace($match[2], self::SPACE_REGEX, ' ');
$inlined = \trim($inlined);
$inlined = '[' . $inlined . ']';

View File

@ -39,7 +39,7 @@ final class ComposerPackageSorter
private function createNameWithPriority(string $requirementName) : string
{
if ($this->isPlatformPackage($requirementName)) {
return Strings::replace($requirementName, self::REQUIREMENT_TYPE_REGEX, function (array $match) : string {
return Strings::replace($requirementName, self::REQUIREMENT_TYPE_REGEX, static function (array $match) : string {
$name = $match['name'];
if ($name === 'php') {
return '0-' . $name;

View File

@ -14,7 +14,7 @@ final class FileSystemFilter
*/
public function filterDirectories(array $filesAndDirectories) : array
{
$directories = \array_filter($filesAndDirectories, function (string $path) : bool {
$directories = \array_filter($filesAndDirectories, static function (string $path) : bool {
return !\is_file($path);
});
return \array_values($directories);
@ -25,7 +25,7 @@ final class FileSystemFilter
*/
public function filterFiles(array $filesAndDirectories) : array
{
$files = \array_filter($filesAndDirectories, function (string $path) : bool {
$files = \array_filter($filesAndDirectories, static function (string $path) : bool {
return \is_file($path);
});
return \array_values($files);