Skip to content

Commit 393f026

Browse files
committed
Updated Rector to commit dfb760f8b4df920d881992cda5727e30930dd71a
rectorphp/rector-src@dfb760f [CodingStyle] Add StrictInArrayRector (#7921)
1 parent 868d2da commit 393f026

11 files changed

Lines changed: 121 additions & 41 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\CodingStyle\Rector\FuncCall;
5+
6+
use PhpParser\Node;
7+
use PhpParser\Node\Arg;
8+
use PhpParser\Node\Expr\FuncCall;
9+
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
10+
use Rector\Rector\AbstractRector;
11+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
12+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
13+
/**
14+
* @see \Rector\Tests\CodingStyle\Rector\FuncCall\StrictInArrayRector\StrictInArrayRectorTest
15+
*/
16+
final class StrictInArrayRector extends AbstractRector
17+
{
18+
/**
19+
* @readonly
20+
*/
21+
private TypeComparator $typeComparator;
22+
public function __construct(TypeComparator $typeComparator)
23+
{
24+
$this->typeComparator = $typeComparator;
25+
}
26+
public function getRuleDefinition(): RuleDefinition
27+
{
28+
return new RuleDefinition('Set in_array strict to true when defined on similar type', [new CodeSample(<<<'CODE_SAMPLE'
29+
class BothStrings
30+
{
31+
public function run(string $value)
32+
{
33+
return in_array($value, ['one', 'two', 'three']);
34+
}
35+
}
36+
CODE_SAMPLE
37+
, <<<'CODE_SAMPLE'
38+
class BothStrings
39+
{
40+
public function run(string $value)
41+
{
42+
return in_array($value, ['one', 'two', 'three'], true);
43+
}
44+
}
45+
CODE_SAMPLE
46+
)]);
47+
}
48+
/**
49+
* @return array<class-string<Node>>
50+
*/
51+
public function getNodeTypes(): array
52+
{
53+
return [FuncCall::class];
54+
}
55+
/**
56+
* @param FuncCall $node
57+
*/
58+
public function refactor(Node $node): ?Node
59+
{
60+
if (!$this->isName($node, 'in_array')) {
61+
return null;
62+
}
63+
if ($node->isFirstClassCallable()) {
64+
return null;
65+
}
66+
$args = $node->getArgs();
67+
if (count($args) !== 2) {
68+
return null;
69+
}
70+
$firstArgType = $this->nodeTypeResolver->getNativeType($args[0]->value);
71+
$secondArgType = $this->nodeTypeResolver->getNativeType($args[1]->value);
72+
if (!$secondArgType->isArray()->yes()) {
73+
return null;
74+
}
75+
if ($this->typeComparator->isSubtype($secondArgType->getIterableValueType(), $firstArgType)) {
76+
$node->args[] = new Arg($this->nodeFactory->createTrue());
77+
return $node;
78+
}
79+
return null;
80+
}
81+
}

rules/DeadCode/Rector/FuncCall/RemoveFilterVarOnExactTypeRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function refactor(Node $node): ?Node
6060
if ($constantFilterName === 'FILTER_VALIDATE_FLOAT' && $valueType->isFloat()->yes()) {
6161
return $firstArgValue;
6262
}
63-
if (in_array($constantFilterName, ['FILTER_VALIDATE_BOOLEAN', 'FILTER_VALIDATE_BOOL']) && $valueType->isBoolean()->yes()) {
63+
if (in_array($constantFilterName, ['FILTER_VALIDATE_BOOLEAN', 'FILTER_VALIDATE_BOOL'], \true) && $valueType->isBoolean()->yes()) {
6464
return $firstArgValue;
6565
}
6666
return null;

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '64ba1b31738854b34b1455cf14ca54777984e052';
22+
public const PACKAGE_VERSION = 'dfb760f8b4df920d881992cda5727e30930dd71a';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2026-02-27 00:03:10';
27+
public const RELEASE_DATE = '2026-02-28 19:33:12';
2828
/**
2929
* @var int
3030
*/

src/Config/Level/CodingStyleLevel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector;
2020
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
2121
use Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
22+
use Rector\CodingStyle\Rector\FuncCall\StrictInArrayRector;
2223
use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
2324
use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector;
2425
use Rector\CodingStyle\Rector\Property\SplitGroupedPropertiesRector;
@@ -51,7 +52,7 @@ final class CodingStyleLevel
5152
*
5253
* @var array<class-string<RectorInterface>>
5354
*/
54-
public const RULES = [SeparateMultiUseImportsRector::class, NewlineBetweenClassLikeStmtsRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, NullableCompareToNullRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SimplifyQuoteEscapeRector::class, StringClassNameToClassConstantRector::class, CatchExceptionNameMatchingTypeRector::class, SplitDoubleAssignRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, CountArrayToEmptyArrayComparisonRector::class, CallUserFuncToMethodCallRector::class, FuncGetArgsToVariadicParamRector::class, StrictArraySearchRector::class, UseClassKeywordForClassNameResolutionRector::class, SplitGroupedPropertiesRector::class, SplitGroupedClassConstantsRector::class, ExplicitPublicClassMethodRector::class, RemoveUselessAliasInUseStatementRector::class, BinaryOpStandaloneAssignsToDirectRector::class];
55+
public const RULES = [SeparateMultiUseImportsRector::class, NewlineBetweenClassLikeStmtsRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, NullableCompareToNullRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SimplifyQuoteEscapeRector::class, StringClassNameToClassConstantRector::class, CatchExceptionNameMatchingTypeRector::class, SplitDoubleAssignRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, CountArrayToEmptyArrayComparisonRector::class, CallUserFuncToMethodCallRector::class, FuncGetArgsToVariadicParamRector::class, StrictArraySearchRector::class, StrictInArrayRector::class, UseClassKeywordForClassNameResolutionRector::class, SplitGroupedPropertiesRector::class, SplitGroupedClassConstantsRector::class, ExplicitPublicClassMethodRector::class, RemoveUselessAliasInUseStatementRector::class, BinaryOpStandaloneAssignsToDirectRector::class];
5556
/**
5657
* @var array<class-string<RectorInterface>, mixed[]>
5758
*/

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@
13031303
'Rector\\CodingStyle\\Rector\\FuncCall\\CountArrayToEmptyArrayComparisonRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php',
13041304
'Rector\\CodingStyle\\Rector\\FuncCall\\FunctionFirstClassCallableRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/FunctionFirstClassCallableRector.php',
13051305
'Rector\\CodingStyle\\Rector\\FuncCall\\StrictArraySearchRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/StrictArraySearchRector.php',
1306+
'Rector\\CodingStyle\\Rector\\FuncCall\\StrictInArrayRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/StrictInArrayRector.php',
13061307
'Rector\\CodingStyle\\Rector\\FuncCall\\VersionCompareFuncCallToConstantRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php',
13071308
'Rector\\CodingStyle\\Rector\\FunctionLike\\FunctionLikeToFirstClassCallableRector' => $baseDir . '/rules/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector.php',
13081309
'Rector\\CodingStyle\\Rector\\If_\\NullableCompareToNullRector' => $baseDir . '/rules/CodingStyle/Rector/If_/NullableCompareToNullRector.php',

vendor/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,7 @@ class ComposerStaticInitb27afa3b28f0dbd33d77e76beab014f6
15631563
'Rector\\CodingStyle\\Rector\\FuncCall\\CountArrayToEmptyArrayComparisonRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php',
15641564
'Rector\\CodingStyle\\Rector\\FuncCall\\FunctionFirstClassCallableRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/FunctionFirstClassCallableRector.php',
15651565
'Rector\\CodingStyle\\Rector\\FuncCall\\StrictArraySearchRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/StrictArraySearchRector.php',
1566+
'Rector\\CodingStyle\\Rector\\FuncCall\\StrictInArrayRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/StrictInArrayRector.php',
15661567
'Rector\\CodingStyle\\Rector\\FuncCall\\VersionCompareFuncCallToConstantRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php',
15671568
'Rector\\CodingStyle\\Rector\\FunctionLike\\FunctionLikeToFirstClassCallableRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector.php',
15681569
'Rector\\CodingStyle\\Rector\\If_\\NullableCompareToNullRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/If_/NullableCompareToNullRector.php',

vendor/composer/installed.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,17 +3301,17 @@
33013301
},
33023302
{
33033303
"name": "webmozart\/assert",
3304-
"version": "2.1.5",
3305-
"version_normalized": "2.1.5.0",
3304+
"version": "2.1.6",
3305+
"version_normalized": "2.1.6.0",
33063306
"source": {
33073307
"type": "git",
33083308
"url": "https:\/\/github.com\/webmozarts\/assert.git",
3309-
"reference": "79155f94852fa27e2f73b459f6503f5e87e2c188"
3309+
"reference": "ff31ad6efc62e66e518fbab1cde3453d389bcdc8"
33103310
},
33113311
"dist": {
33123312
"type": "zip",
3313-
"url": "https:\/\/api.github.com\/repos\/webmozarts\/assert\/zipball\/79155f94852fa27e2f73b459f6503f5e87e2c188",
3314-
"reference": "79155f94852fa27e2f73b459f6503f5e87e2c188",
3313+
"url": "https:\/\/api.github.com\/repos\/webmozarts\/assert\/zipball\/ff31ad6efc62e66e518fbab1cde3453d389bcdc8",
3314+
"reference": "ff31ad6efc62e66e518fbab1cde3453d389bcdc8",
33153315
"shasum": ""
33163316
},
33173317
"require": {
@@ -3325,7 +3325,7 @@
33253325
"ext-simplexml": "",
33263326
"ext-spl": ""
33273327
},
3328-
"time": "2026-02-18T14:09:36+00:00",
3328+
"time": "2026-02-27T10:28:38+00:00",
33293329
"type": "library",
33303330
"extra": {
33313331
"branch-alias": {
@@ -3360,7 +3360,7 @@
33603360
],
33613361
"support": {
33623362
"issues": "https:\/\/github.com\/webmozarts\/assert\/issues",
3363-
"source": "https:\/\/github.com\/webmozarts\/assert\/tree\/2.1.5"
3363+
"source": "https:\/\/github.com\/webmozarts\/assert\/tree\/2.1.6"
33643364
},
33653365
"install-path": "..\/webmozart\/assert"
33663366
}

0 commit comments

Comments
 (0)