Skip to content

Commit 013e048

Browse files
committed
skip casted bool
1 parent a21d865 commit 013e048

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeSubstrFalsyRector\Fixture;
4+
5+
class SkipCastedBool
6+
{
7+
public function run(string $name)
8+
{
9+
return (bool) substr($name, 2);
10+
}
11+
}

rules/DowngradePhp80/Rector/FuncCall/DowngradeSubstrFalsyRector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Expr;
99
use PhpParser\Node\Expr\BooleanNot;
10+
use PhpParser\Node\Expr\Cast;
1011
use PhpParser\Node\Expr\Cast\String_;
1112
use PhpParser\Node\Expr\Empty_;
1213
use PhpParser\Node\Expr\FuncCall;
@@ -39,15 +40,15 @@ public function getRuleDefinition(): RuleDefinition
3940
*/
4041
public function getNodeTypes(): array
4142
{
42-
return [String_::class, Empty_::class, BooleanNot::class, Ternary::class, FuncCall::class];
43+
return [Cast::class, Empty_::class, BooleanNot::class, Ternary::class, FuncCall::class];
4344
}
4445

4546
/**
46-
* @param String_|Empty_|BooleanNot|Ternary|FuncCall $node
47+
* @param Cast|Empty_|BooleanNot|Ternary|FuncCall $node
4748
*/
4849
public function refactor(Node $node): ?Node
4950
{
50-
if ($node instanceof String_ || $node instanceof Empty_ || $node instanceof BooleanNot) {
51+
if ($node instanceof Cast || $node instanceof Empty_ || $node instanceof BooleanNot) {
5152
$node->expr->setAttribute(self::IS_UNCASTABLE, true);
5253
return null;
5354
}

0 commit comments

Comments
 (0)