Skip to content

Commit bbdcc97

Browse files
ArshidArshid
authored andcommitted
MbStrContainsRector
1 parent 22cabd0 commit bbdcc97

1 file changed

Lines changed: 3 additions & 35 deletions

File tree

rules/Php80/Rector/NotIdentical/StrContainsRector.php

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PhpParser\Node\Expr\FuncCall;
1616
use PhpParser\Node\Name;
1717
use PhpParser\Node\Scalar\Int_;
18+
use Rector\Php80\NodeResolver\StrFalseComparisonResolver;
1819
use Rector\PhpParser\Node\Value\ValueResolver;
1920
use Rector\Rector\AbstractRector;
2021
use Rector\ValueObject\PhpVersionFeature;
@@ -35,7 +36,7 @@ final class StrContainsRector extends AbstractRector implements MinPhpVersionInt
3536
private const OLD_STR_NAMES = ['strpos', 'strstr'];
3637

3738
public function __construct(
38-
private readonly ValueResolver $valueResolver
39+
private readonly StrFalseComparisonResolver $strFalseComparisonResolver
3940
) {
4041
}
4142

@@ -87,7 +88,7 @@ public function getNodeTypes(): array
8788
*/
8889
public function refactor(Node $node): ?Node
8990
{
90-
$funcCall = $this->matchIdenticalOrNotIdenticalToFalse($node);
91+
$funcCall = $this->strFalseComparisonResolver->resolve($node, self::OLD_STR_NAMES);
9192

9293
if (! $funcCall instanceof FuncCall) {
9394
return null;
@@ -124,39 +125,6 @@ public function providePolyfillPackage(): string
124125
return PolyfillPackage::PHP_80;
125126
}
126127

127-
private function matchIdenticalOrNotIdenticalToFalse(Identical | NotIdentical | Equal | NotEqual $expr): ?FuncCall
128-
{
129-
if ($this->valueResolver->isFalse($expr->left)) {
130-
if (! $expr->right instanceof FuncCall) {
131-
return null;
132-
}
133-
134-
if (! $this->isNames($expr->right, self::OLD_STR_NAMES)) {
135-
return null;
136-
}
137-
138-
/** @var FuncCall $funcCall */
139-
$funcCall = $expr->right;
140-
return $funcCall;
141-
}
142-
143-
if ($this->valueResolver->isFalse($expr->right)) {
144-
if (! $expr->left instanceof FuncCall) {
145-
return null;
146-
}
147-
148-
if (! $this->isNames($expr->left, self::OLD_STR_NAMES)) {
149-
return null;
150-
}
151-
152-
/** @var FuncCall $funcCall */
153-
$funcCall = $expr->left;
154-
return $funcCall;
155-
}
156-
157-
return null;
158-
}
159-
160128
private function isIntegerZero(Expr $expr): bool
161129
{
162130
if (! $expr instanceof Int_) {

0 commit comments

Comments
 (0)