Skip to content

Commit

Permalink
[Php72] Handle crash on PreInc usage on CreateFunctionToAnonymousFunc…
Browse files Browse the repository at this point in the history
…tionRector (#2456)

* [Php72] Handle crash on PreInc usage on CreateFunctionToAnonymousFunctionRector

* Fixed 🎉

* phpstan

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Jun 9, 2022
1 parent cb1473a commit f2300ba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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);
};
}

}

?>
11 changes: 1 addition & 10 deletions src/PhpParser/Parser/InlineCodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
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;
Expand Down Expand Up @@ -91,10 +86,6 @@ public function stringify(Expr $expr): string
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);
}
}

0 comments on commit f2300ba

Please sign in to comment.