mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-18 14:29:42 +01:00
add skip assign expr
This commit is contained in:
parent
66a3ecd8d9
commit
0c64e0a3ab
@ -66,7 +66,9 @@ class SomeEventSubscriber implements EventSubscriberInterface
|
||||
PHP
|
||||
,
|
||||
[
|
||||
'EventSubscriberInterface' => ['getSubscribedEvents'],
|
||||
'$methodsByType' => [
|
||||
'EventSubscriberInterface' => ['getSubscribedEvents'],
|
||||
],
|
||||
]
|
||||
),
|
||||
]);
|
||||
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Rector\NetteCodeQuality\Rector\ArrayDimFetch;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
@ -127,6 +128,10 @@ PHP
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($this->isBeingAssigned($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$controlName = $this->controlDimFetchAnalyzer->matchName($node);
|
||||
if ($controlName === null) {
|
||||
return null;
|
||||
@ -192,4 +197,14 @@ PHP
|
||||
|
||||
return new ObjectType($controlType);
|
||||
}
|
||||
|
||||
private function isBeingAssigned(Expr $expr): bool
|
||||
{
|
||||
$parent = $expr->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (! $parent instanceof Assign) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $parent->expr === $expr;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\NetteCodeQuality\Tests\Rector\ArrayDimFetch\ChangeControlArrayAccessToAnnotatedControlVariableRector\Fixture;
|
||||
|
||||
use Nette\Application\UI\Presenter;
|
||||
use Nette\Application\UI\Form;
|
||||
|
||||
final class SkipAlreadyPresenter extends Presenter
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
/** @var \Nette\Application\UI\Form $someForm */
|
||||
$someForm = $this['some_form'];
|
||||
if ($someForm->isSubmitted()) {
|
||||
}
|
||||
}
|
||||
|
||||
protected function createComponentSomeForm()
|
||||
{
|
||||
return new Form();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user