Skip to content

Commit

Permalink
[Php81] Skip Encapsed on NullToStrictStringFuncCallArgRector (#2744)
Browse files Browse the repository at this point in the history
* Add failing test fixture for NullToStrictStringFuncCallArgRector

# Failing Test for NullToStrictStringFuncCallArgRector

Based on https://getrector.org/demo/b778fb29-98e6-4992-b4fa-b14a0be26429

In this case, the first argument of the mb_strlen function cannot be something else than a string, so the cast to string is useless

* Closes #2742

Co-authored-by: Grégoire Pineau <lyrixx@lyrixx.info>
  • Loading branch information
samsonasik and lyrixx committed Aug 9, 2022
1 parent 93b63b0 commit d7be258
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;

final class SkipEncapsed
{
public function foo(string $bar): array
{
mb_strlen("foo:{$bar}:");
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Trait_;
use PHPStan\Analyser\Scope;
Expand Down Expand Up @@ -408,6 +409,10 @@ private function processNullToStrictStringOnNodePosition(
return null;
}

if ($argValue instanceof Encapsed) {
return null;
}

if ($this->isAnErrorTypeFromParentScope($argValue)) {
return null;
}
Expand Down

0 comments on commit d7be258

Please sign in to comment.