add skip assign expr

This commit is contained in:
TomasVotruba 2020-07-26 22:37:47 +02:00
parent 66a3ecd8d9
commit 0c64e0a3ab
3 changed files with 40 additions and 1 deletions

View File

@ -66,7 +66,9 @@ class SomeEventSubscriber implements EventSubscriberInterface
PHP
,
[
'EventSubscriberInterface' => ['getSubscribedEvents'],
'$methodsByType' => [
'EventSubscriberInterface' => ['getSubscribedEvents'],
],
]
),
]);

View File

@ -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;
}
}

View File

@ -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();
}
}