[Rector] FormCallbackRector - use type

This commit is contained in:
TomasVotruba 2017-08-21 12:37:43 +02:00
parent 279a233f66
commit ffc94f276e
4 changed files with 28 additions and 1 deletions

View File

@ -30,6 +30,7 @@ parameters:
- PhpCsFixer\Fixer\Operator\NewWithBracesFixer
- PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer
- PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer
- PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer
skip:
Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer:

View File

@ -71,7 +71,7 @@ final class FormCallbackRector extends NodeVisitorAbstract implements Deprecatio
return false;
}
if ($node->var->name !== 'form') {
if ($node->var->getAttribute('type') !== $this->getDesiredClass()) {
return false;
}
@ -83,6 +83,9 @@ final class FormCallbackRector extends NodeVisitorAbstract implements Deprecatio
return true;
}
/**
* [$this, 'something']
*/
private function createShortArray(Node $node): Array_
{
return new Array_([
@ -96,4 +99,9 @@ final class FormCallbackRector extends NodeVisitorAbstract implements Deprecatio
'kind' => Array_::KIND_SHORT,
]);
}
private function getDesiredClass(): string
{
return 'Nette\Application\UI\Form';
}
}

View File

@ -6,6 +6,15 @@ class SomePresenter
{
$form = new Form;
$form->onSuccess[] = $this->someMethod;
return $form;
}
public function createNetteForm()
{
$form = new \Nette\Application\UI\Form;
$form->onSuccess[] = [$this, 'someMethod'];
return $form;

View File

@ -10,4 +10,13 @@ class SomePresenter
return $form;
}
public function createNetteForm()
{
$form = new \Nette\Application\UI\Form;
$form->onSuccess[] = $this->someMethod;
return $form;
}
}