File tree Expand file tree Collapse file tree 4 files changed +35
-26
lines changed
rules-tests/DeadCode/Rector/Cast/RecastingRemovalRector/Fixture
rules/DeadCode/Rector/Cast Expand file tree Collapse file tree 4 files changed +35
-26
lines changed Original file line number Diff line number Diff line change 44
55use Rector \CodingStyle \Rector \String_ \UseClassKeywordForClassNameResolutionRector ;
66use Rector \Config \RectorConfig ;
7+ use Rector \DeadCode \Rector \Cast \RecastingRemovalRector ;
78use Rector \DeadCode \Rector \ConstFetch \RemovePhpVersionIdCheckRector ;
89use Rector \Php55 \Rector \String_ \StringClassNameToClassConstantRector ;
910
5253 __DIR__ . '/src/Configuration/RectorConfigBuilder.php ' ,
5354 __DIR__ . '/src/Console/Notifier.php ' ,
5455 ],
56+
57+ // on php 7.x, substr() result can return false, so force (string) is needed
58+ RecastingRemovalRector::class => [
59+ __DIR__ . '/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php ' ,
60+ ],
5561 ]);
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DeadCode \Rector \Cast \RecastingRemovalRector \Fixture ;
4+
5+ class WithSubstr
6+ {
7+ public function run (): string
8+ {
9+ $ className = 'Exception ' ;
10+ return (string ) substr ($ className , 0 , -strlen ($ className ) - 1 );
11+ }
12+ }
13+
14+ ?>
15+ -----
16+ <?php
17+
18+ namespace Rector \Tests \DeadCode \Rector \Cast \RecastingRemovalRector \Fixture ;
19+
20+ class WithSubstr
21+ {
22+ public function run (): string
23+ {
24+ $ className = 'Exception ' ;
25+ return substr ($ className , 0 , -strlen ($ className ) - 1 );
26+ }
27+ }
28+
29+ ?>
Original file line number Diff line number Diff line change 1313use PhpParser \Node \Expr \Cast \Int_ ;
1414use PhpParser \Node \Expr \Cast \Object_ ;
1515use PhpParser \Node \Expr \Cast \String_ ;
16- use PhpParser \Node \Expr \FuncCall ;
1716use PhpParser \Node \Expr \MethodCall ;
1817use PhpParser \Node \Expr \StaticCall ;
1918use PHPStan \Reflection \Php \PhpPropertyReflection ;
2019use PHPStan \Type \ArrayType ;
2120use PHPStan \Type \BooleanType ;
2221use PHPStan \Type \Constant \ConstantArrayType ;
23- use PHPStan \Type \Constant \ConstantBooleanType ;
2422use PHPStan \Type \FloatType ;
2523use PHPStan \Type \IntegerType ;
2624use PHPStan \Type \MixedType ;
@@ -105,13 +103,6 @@ public function refactor(Node $node): ?Node
105103 return null ;
106104 }
107105
108- // substr can return false on php 7.x
109- if ($ node ->expr instanceof FuncCall
110- && $ this ->isName ($ node ->expr , 'substr ' )
111- && ! $ node ->expr ->isFirstClassCallable ()) {
112- $ nodeType = new UnionType ([new StringType (), new ConstantBooleanType (false )]);
113- }
114-
115106 if ($ nodeType instanceof ConstantArrayType && $ nodeClass === Array_::class) {
116107 if ($ this ->shouldSkip ($ node ->expr )) {
117108 return null ;
You can’t perform that action at this time.
0 commit comments