[Php72] Handle crash on PreInc usage on CreateFunctionToAnonymousFunctionRector (#2456)

* [Php72] Handle crash on PreInc usage on CreateFunctionToAnonymousFunctionRector

* Fixed 🎉

* phpstan

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Abdul Malik Ikhsan 2022-06-09 14:52:34 +07:00 committed by GitHub
parent cb1473a3ac
commit f2300baf89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 10 deletions

View File

@ -0,0 +1,37 @@
<?php
namespace Rector\Tests\Php72\Rector\FuncCall\CreateFunctionToAnonymousFunctionRector\Fixture;
class UseIncrement
{
private array $_quoteIdentifierCallbacks = array();
private int $_qiCallbacksCount = 0;
public function getQuoteIdentifierCallback($adapter)
{
$callback = create_function('$v', 'return Mage::helper(\'customgrid/collection\')->callQuoteIdentifier($v, '.++$this->_qiCallbacksCount.');');
}
}
?>
-----
<?php
namespace Rector\Tests\Php72\Rector\FuncCall\CreateFunctionToAnonymousFunctionRector\Fixture;
class UseIncrement
{
private array $_quoteIdentifierCallbacks = array();
private int $_qiCallbacksCount = 0;
public function getQuoteIdentifierCallback($adapter)
{
$callback = function ($v) {
return Mage::helper('customgrid/collection')->callQuoteIdentifier($v, ++$this->_qiCallbacksCount);
};
}
}
?>

View File

@ -7,15 +7,10 @@ namespace Rector\Core\PhpParser\Parser;
use Nette\Utils\Strings;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use PhpParser\Parser;
use Rector\Core\Contract\PhpParser\NodePrinterInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Util\StringUtils;
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;
use Symplify\SmartFileSystem\SmartFileSystem;
@ -91,10 +86,6 @@ final class InlineCodeParser
return $this->stringify($expr->left) . $this->stringify($expr->right);
}
if ($expr instanceof Variable || $expr instanceof PropertyFetch || $expr instanceof StaticPropertyFetch) {
return $this->nodePrinter->print($expr);
}
throw new ShouldNotHappenException($expr::class . ' ' . __METHOD__);
return $this->nodePrinter->print($expr);
}
}