mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-11 19:15:10 +01:00
[CodeQualityStrict] Skip MoveVariableDeclarationNearReferenceRector on pass impure function (#6090)
This commit is contained in:
parent
f82a8dc995
commit
723bd2b1b6
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
|
||||
|
||||
final class SkipPassBcdiv
|
||||
{
|
||||
public function run($data, $options)
|
||||
{
|
||||
$a = bcscale(3);
|
||||
echo bcdiv('105', '6.55957');
|
||||
echo $a;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
|
||||
|
||||
final class SkipPassJsonLastError
|
||||
{
|
||||
public function run($data, $options)
|
||||
{
|
||||
$result = json_encode($data, $options, 512);
|
||||
|
||||
if (json_last_error()) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
echo $result;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ class StaticCallNextException
|
||||
function myMethod()
|
||||
{
|
||||
$var = do_something();
|
||||
if (rand(0, 1)) {
|
||||
if (mktime() === false) {
|
||||
throw MyException::notFound();
|
||||
}
|
||||
echo $var;
|
||||
@ -28,7 +28,7 @@ class StaticCallNextException
|
||||
{
|
||||
function myMethod()
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
if (mktime() === false) {
|
||||
throw MyException::notFound();
|
||||
}
|
||||
$var = do_something();
|
||||
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodeQualityStrict\Rector\Variable;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
@ -28,6 +27,7 @@ use PhpParser\Node\Stmt\TryCatch;
|
||||
use PhpParser\Node\Stmt\While_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DeadCode\SideEffect\PureFunctionDetector;
|
||||
use Rector\NodeNestingScope\NodeFinder\ScopeAwareNodeFinder;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
@ -43,9 +43,15 @@ final class MoveVariableDeclarationNearReferenceRector extends AbstractRector
|
||||
*/
|
||||
private $scopeAwareNodeFinder;
|
||||
|
||||
public function __construct(ScopeAwareNodeFinder $scopeAwareNodeFinder)
|
||||
/**
|
||||
* @var PureFunctionDetector
|
||||
*/
|
||||
private $pureFunctionDetector;
|
||||
|
||||
public function __construct(ScopeAwareNodeFinder $scopeAwareNodeFinder, PureFunctionDetector $pureFunctionDetector)
|
||||
{
|
||||
$this->scopeAwareNodeFinder = $scopeAwareNodeFinder;
|
||||
$this->pureFunctionDetector = $pureFunctionDetector;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
@ -297,7 +303,7 @@ CODE_SAMPLE
|
||||
return false;
|
||||
}
|
||||
|
||||
return Strings::startsWith($funcName, 'ob_');
|
||||
return ! $this->pureFunctionDetector->detect($n);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -100,6 +100,12 @@ final class PureFunctionDetector
|
||||
|
||||
// ftp
|
||||
'ftp_close',
|
||||
|
||||
// bcmath
|
||||
'bcscale', 'bcdiv',
|
||||
|
||||
// json
|
||||
'json_encode', 'json_decode', 'json_last_error',
|
||||
];
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user