mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
Updated Rector to commit 00edfa77a0dcfabb55daca82e7e0b51063ad68e6
00edfa77a0
[TypeDeclaration] Add StrictStringParamConcatRector (#4624)
This commit is contained in:
parent
d9fb45c92e
commit
64fc640e30
|
@ -30,6 +30,7 @@ use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictParamRector;
|
|||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector;
|
||||
use Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
|
||||
use Rector\TypeDeclaration\Rector\FunctionLike\AddParamTypeSplFixedArrayRector;
|
||||
|
@ -43,4 +44,5 @@ use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector;
|
|||
use Rector\TypeDeclaration\Rector\Property\VarAnnotationIncorrectNullableRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([AddClosureReturnTypeRector::class, AddArrowFunctionReturnTypeRector::class, ParamTypeByMethodCallTypeRector::class, TypedPropertyFromAssignsRector::class, ReturnAnnotationIncorrectNullableRector::class, VarAnnotationIncorrectNullableRector::class, ParamAnnotationIncorrectNullableRector::class, AddReturnTypeDeclarationBasedOnParentClassMethodRector::class, ReturnTypeFromStrictTypedPropertyRector::class, TypedPropertyFromStrictConstructorRector::class, TypedPropertyFromStrictConstructorReadonlyClassRector::class, ParamTypeFromStrictTypedPropertyRector::class, AddVoidReturnTypeWhereNoReturnRector::class, ReturnTypeFromReturnNewRector::class, TypedPropertyFromStrictGetterMethodReturnTypeRector::class, AddMethodCallBasedStrictParamTypeRector::class, ReturnTypeFromStrictBoolReturnExprRector::class, ReturnTypeFromStrictNativeCallRector::class, ReturnTypeFromStrictNewArrayRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, ReturnTypeFromStrictParamRector::class, TypedPropertyFromStrictSetUpRector::class, ParamTypeByParentCallTypeRector::class, AddParamTypeSplFixedArrayRector::class, AddParamTypeBasedOnPHPUnitDataProviderRector::class, AddParamTypeFromPropertyTypeRector::class, AddReturnTypeDeclarationFromYieldsRector::class, ReturnTypeFromReturnDirectArrayRector::class, ReturnTypeFromStrictConstantReturnRector::class, ReturnTypeFromStrictTypedCallRector::class, ReturnNeverTypeRector::class, EmptyOnNullableObjectToInstanceOfRector::class, PropertyTypeFromStrictSetterGetterRector::class, ReturnTypeFromStrictTernaryRector::class, BoolReturnTypeFromStrictScalarReturnsRector::class, NumericReturnTypeFromStrictScalarReturnsRector::class, StrictArrayParamDimFetchRector::class]);
|
||||
$rectorConfig->rule(StrictStringParamConcatRector::class);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 363 Rules Overview
|
||||
# 364 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -52,7 +52,7 @@
|
|||
|
||||
- [Transform](#transform) (22)
|
||||
|
||||
- [TypeDeclaration](#typedeclaration) (44)
|
||||
- [TypeDeclaration](#typedeclaration) (45)
|
||||
|
||||
- [Visibility](#visibility) (3)
|
||||
|
||||
|
@ -8226,6 +8226,25 @@ Add array type based on array dim fetch use
|
|||
|
||||
<br>
|
||||
|
||||
### StrictStringParamConcatRector
|
||||
|
||||
Add string type based on concat use
|
||||
|
||||
- class: [`Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector`](../rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function resolve($item)
|
||||
+ public function resolve(string $item)
|
||||
{
|
||||
return $item . ' world';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### TypedPropertyFromAssignsRector
|
||||
|
||||
Add typed property from assigned types
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\TypeDeclaration\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\AssignOp\Concat;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector\StrictStringParamConcatRectorTest
|
||||
*/
|
||||
final class StrictStringParamConcatRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\VendorLocker\ParentClassMethodTypeOverrideGuard
|
||||
*/
|
||||
private $parentClassMethodTypeOverrideGuard;
|
||||
public function __construct(ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard)
|
||||
{
|
||||
$this->parentClassMethodTypeOverrideGuard = $parentClassMethodTypeOverrideGuard;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Add string type based on concat use', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function resolve($item)
|
||||
{
|
||||
return $item . ' world';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function resolve(string $item)
|
||||
{
|
||||
return $item . ' world';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class, Function_::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($node instanceof ClassMethod && $this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($node)) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
foreach ($node->getParams() as $param) {
|
||||
if ($param->type instanceof Node) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isParamConcatted($param, $node)) {
|
||||
continue;
|
||||
}
|
||||
$param->type = new Identifier('string');
|
||||
$hasChanged = \true;
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function isParamConcatted(Param $param, $functionLike) : bool
|
||||
{
|
||||
if ($functionLike->stmts === null) {
|
||||
return \false;
|
||||
}
|
||||
$paramName = $this->getName($param);
|
||||
$isParamConcatted = \false;
|
||||
$this->traverseNodesWithCallable($functionLike->stmts, function (Node $node) use($paramName, &$isParamConcatted) : ?int {
|
||||
// skip nested class and function nodes
|
||||
if ($node instanceof FunctionLike || $node instanceof Class_) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
if ($this->isAssignConcat($node, $paramName)) {
|
||||
$isParamConcatted = \true;
|
||||
}
|
||||
if ($this->isBinaryConcat($node, $paramName)) {
|
||||
$isParamConcatted = \true;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return $isParamConcatted;
|
||||
}
|
||||
private function isVariableWithSameParam(Expr $expr, string $paramName) : bool
|
||||
{
|
||||
if (!$expr instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isName($expr, $paramName);
|
||||
}
|
||||
private function isAssignConcat(Node $node, string $paramName) : bool
|
||||
{
|
||||
if (!$node instanceof Concat) {
|
||||
return \false;
|
||||
}
|
||||
if ($this->isVariableWithSameParam($node->var, $paramName)) {
|
||||
return \true;
|
||||
}
|
||||
return $this->isVariableWithSameParam($node->expr, $paramName);
|
||||
}
|
||||
private function isBinaryConcat(Node $node, string $paramName) : bool
|
||||
{
|
||||
if (!$node instanceof Expr\BinaryOp\Concat) {
|
||||
return \false;
|
||||
}
|
||||
if ($this->isVariableWithSameParam($node->left, $paramName)) {
|
||||
return \true;
|
||||
}
|
||||
return $this->isVariableWithSameParam($node->right, $paramName);
|
||||
}
|
||||
}
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'e8bba86e071c527045951c0ed5edd852d80776af';
|
||||
public const PACKAGE_VERSION = '00edfa77a0dcfabb55daca82e7e0b51063ad68e6';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-30 18:03:23';
|
||||
public const RELEASE_DATE = '2023-07-31 11:06:56';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit1fdf8cda4f009d53c0b435a0a24d5641::getLoader();
|
||||
return ComposerAutoloaderInitc6238ef1ffdb65c7e37f8864f482566d::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2698,6 +2698,7 @@ return array(
|
|||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnTypeFromStrictTypedCallRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnTypeFromStrictTypedPropertyRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedPropertyRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictArrayParamDimFetchRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictStringParamConcatRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\Class_\\PropertyTypeFromStrictSetterGetterRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\Class_\\ReturnTypeFromStrictTernaryRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\Closure\\AddClosureReturnTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/Closure/AddClosureReturnTypeRector.php',
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit1fdf8cda4f009d53c0b435a0a24d5641
|
||||
class ComposerAutoloaderInitc6238ef1ffdb65c7e37f8864f482566d
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit1fdf8cda4f009d53c0b435a0a24d5641
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1fdf8cda4f009d53c0b435a0a24d5641', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitc6238ef1ffdb65c7e37f8864f482566d', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1fdf8cda4f009d53c0b435a0a24d5641', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitc6238ef1ffdb65c7e37f8864f482566d', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1fdf8cda4f009d53c0b435a0a24d5641::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitc6238ef1ffdb65c7e37f8864f482566d::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit1fdf8cda4f009d53c0b435a0a24d5641::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitc6238ef1ffdb65c7e37f8864f482566d::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit1fdf8cda4f009d53c0b435a0a24d5641
|
||||
class ComposerStaticInitc6238ef1ffdb65c7e37f8864f482566d
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2952,6 +2952,7 @@ class ComposerStaticInit1fdf8cda4f009d53c0b435a0a24d5641
|
|||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnTypeFromStrictTypedCallRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnTypeFromStrictTypedPropertyRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedPropertyRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictArrayParamDimFetchRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictStringParamConcatRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\Class_\\PropertyTypeFromStrictSetterGetterRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\Class_\\ReturnTypeFromStrictTernaryRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php',
|
||||
'Rector\\TypeDeclaration\\Rector\\Closure\\AddClosureReturnTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Closure/AddClosureReturnTypeRector.php',
|
||||
|
@ -3023,9 +3024,9 @@ class ComposerStaticInit1fdf8cda4f009d53c0b435a0a24d5641
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1fdf8cda4f009d53c0b435a0a24d5641::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1fdf8cda4f009d53c0b435a0a24d5641::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1fdf8cda4f009d53c0b435a0a24d5641::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitc6238ef1ffdb65c7e37f8864f482566d::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitc6238ef1ffdb65c7e37f8864f482566d::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitc6238ef1ffdb65c7e37f8864f482566d::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
14
vendor/composer/installed.json
vendored
14
vendor/composer/installed.json
vendored
|
@ -2696,17 +2696,17 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony\/finder",
|
||||
"version": "v6.3.2",
|
||||
"version_normalized": "6.3.2.0",
|
||||
"version": "v6.3.3",
|
||||
"version_normalized": "6.3.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/symfony\/finder.git",
|
||||
"reference": "78ce4c29757d657d2b41a91c328923b9a0d6b43d"
|
||||
"reference": "9915db259f67d21eefee768c1abcf1cc61b1fc9e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/symfony\/finder\/zipball\/78ce4c29757d657d2b41a91c328923b9a0d6b43d",
|
||||
"reference": "78ce4c29757d657d2b41a91c328923b9a0d6b43d",
|
||||
"url": "https:\/\/api.github.com\/repos\/symfony\/finder\/zipball\/9915db259f67d21eefee768c1abcf1cc61b1fc9e",
|
||||
"reference": "9915db259f67d21eefee768c1abcf1cc61b1fc9e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2715,7 +2715,7 @@
|
|||
"require-dev": {
|
||||
"symfony\/filesystem": "^6.0"
|
||||
},
|
||||
"time": "2023-07-13T14:29:38+00:00",
|
||||
"time": "2023-07-31T08:31:44+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
|
@ -2743,7 +2743,7 @@
|
|||
"description": "Finds files and directories via an intuitive fluent interface",
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"support": {
|
||||
"source": "https:\/\/github.com\/symfony\/finder\/tree\/v6.3.2"
|
||||
"source": "https:\/\/github.com\/symfony\/finder\/tree\/v6.3.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
|
@ -63,7 +63,7 @@ class ExcludeDirectoryFilterIterator extends \FilterIterator implements \Recursi
|
|||
*/
|
||||
public function accept() : bool
|
||||
{
|
||||
if (isset($this->excludedDirs[$this->getFilename()]) && $this->hasChildren()) {
|
||||
if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) {
|
||||
return \false;
|
||||
}
|
||||
if ($this->excludedPattern) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user