Skip to content

Commit a21d865

Browse files
committed
skip negated
1 parent ccd2180 commit a21d865

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeSubstrFalsyRector\Fixture;
4+
5+
/**
6+
* negation can be false or empty string ""
7+
*/
8+
class SkipNegated
9+
{
10+
public function run()
11+
{
12+
return ! substr('a', 2);
13+
}
14+
}

rules/DowngradePhp80/Rector/FuncCall/DowngradeSubstrFalsyRector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpParser\Node;
88
use PhpParser\Node\Expr;
9+
use PhpParser\Node\Expr\BooleanNot;
910
use PhpParser\Node\Expr\Cast\String_;
1011
use PhpParser\Node\Expr\Empty_;
1112
use PhpParser\Node\Expr\FuncCall;
@@ -38,15 +39,15 @@ public function getRuleDefinition(): RuleDefinition
3839
*/
3940
public function getNodeTypes(): array
4041
{
41-
return [String_::class, Empty_::class, Ternary::class, FuncCall::class];
42+
return [String_::class, Empty_::class, BooleanNot::class, Ternary::class, FuncCall::class];
4243
}
4344

4445
/**
45-
* @param String_|Empty_|Ternary|FuncCall $node
46+
* @param String_|Empty_|BooleanNot|Ternary|FuncCall $node
4647
*/
4748
public function refactor(Node $node): ?Node
4849
{
49-
if ($node instanceof String_ || $node instanceof Empty_) {
50+
if ($node instanceof String_ || $node instanceof Empty_ || $node instanceof BooleanNot) {
5051
$node->expr->setAttribute(self::IS_UNCASTABLE, true);
5152
return null;
5253
}

0 commit comments

Comments
 (0)