Skip to content

Commit

Permalink
[Php73] Skip Encapsed on StringifyStrNeedlesRector + Temporary Pin P…
Browse files Browse the repository at this point in the history
…HPStan 1.6.9 (#2352)

* [Php73] Skip Encapsed on StringifyStrNeedlesRector

* phpstan

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* Fixed 🎉

* eol

* update requirement to PHPStan 1.7.0

* temporary pin to 1.6.9

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed May 24, 2022
1 parent 1691157 commit f25715b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/target-repository/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"require": {
"php": "^7.2|^8.0",
"phpstan/phpstan": "^1.6.8"
"phpstan/phpstan": "1.6.9"
},
"autoload": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"nikic/php-parser": "^4.13.2",
"ondram/ci-detector": "^4.1",
"phpstan/phpdoc-parser": "^1.5.1",
"phpstan/phpstan": "^1.6.8",
"phpstan/phpstan": "1.6.9",
"phpstan/phpstan-phpunit": "^1.0",
"psr/log": "^2.0",
"react/child-process": "^0.6.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Rector\Tests\Php73\Rector\FuncCall\StringifyStrNeedlesRector\Fixture;

function skipEncapsed()
{
$str = 'bar';
strpos('foo bar', " {$str}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function refactor(Node $node): ?Node
continue;
}

/** @var ReflectionMethod $parentReflectionMethod */
$parentReflectionMethod = $nativeClassReflection->getMethod($methodName);
if ($this->isClassMethodCompatibleWithParentReflectionMethod($classMethod, $parentReflectionMethod)) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions rules/DowngradePhp72/NodeManipulator/BitwiseFlagCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
) {
}

public function cleanFuncCall(FuncCall $funcCall, BitwiseOr $bitwiseOr, Expr $expr = null, string $flag): void
public function cleanFuncCall(FuncCall $funcCall, BitwiseOr $bitwiseOr, string $flag, Expr $expr = null): void
{
if ($bitwiseOr->left instanceof BitwiseOr) {
/** @var BitwiseOr $leftLeft */
Expand All @@ -36,7 +36,7 @@ public function cleanFuncCall(FuncCall $funcCall, BitwiseOr $bitwiseOr, Expr $ex
}

if ($bitwiseOr->left instanceof BitwiseOr) {
$this->cleanFuncCall($funcCall, $bitwiseOr->left, $bitwiseOr->right, $flag);
$this->cleanFuncCall($funcCall, $bitwiseOr->left, $flag, $bitwiseOr->right);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function refactor(Node $node): ?Node
$variable = $args[2]->value;

if ($flags instanceof BitwiseOr) {
$this->bitwiseFlagCleaner->cleanFuncCall($node, $flags, null, self::UNMATCHED_NULL_FLAG);
$this->bitwiseFlagCleaner->cleanFuncCall($node, $flags, self::UNMATCHED_NULL_FLAG, null);
if (! $this->nodeComparator->areNodesEqual($flags, $args[3]->value)) {
return $this->handleEmptyStringToNullMatch($node, $variable);
}
Expand Down
5 changes: 5 additions & 0 deletions rules/Php73/Rector/FuncCall/StringifyStrNeedlesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Cast\String_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\Encapsed;
use PHPStan\Type\StringType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand Down Expand Up @@ -106,6 +107,10 @@ public function refactor(Node $node): ?Node
return null;
}

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

$node->args[1]->value = new String_($node->args[1]->value);

return $node;
Expand Down

0 comments on commit f25715b

Please sign in to comment.