From 3d80a5321077972e5a4bd9ee1044d4fd991558bb Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 2 Feb 2019 17:12:12 +0100 Subject: [PATCH] make isType() cccept fnmatch with * as well --- ecs.yml | 4 +-- src/Rector/TypeAnalyzerTrait.php | 13 ++++++++++ .../nette_to_symfony_presenter.php.inc | 25 +++++++++++++++++++ .../MethodNameReplacerRectorTest.php | 4 +++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/Rector/MethodCall/MethodNameReplacerRector/Fixture/nette_to_symfony_presenter.php.inc diff --git a/ecs.yml b/ecs.yml index a02cc6ee566..c663d5aacea 100644 --- a/ecs.yml +++ b/ecs.yml @@ -58,8 +58,8 @@ parameters: skip: # run manually from time to time, not to bother user with it - # Symplify\CodingStandard\Fixer\Order\PropertyOrderByComplexityFixer: ~ - # Symplify\CodingStandard\Fixer\Order\PrivateMethodOrderByUseFixer: ~ + Symplify\CodingStandard\Fixer\Order\PropertyOrderByComplexityFixer: ~ + Symplify\CodingStandard\Fixer\Order\PrivateMethodOrderByUseFixer: ~ PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer: - 'packages/Php/src/Rector/Double/RealToFloatTypeCastRector.php' diff --git a/src/Rector/TypeAnalyzerTrait.php b/src/Rector/TypeAnalyzerTrait.php index 01a17067d90..8f6a004b95e 100644 --- a/src/Rector/TypeAnalyzerTrait.php +++ b/src/Rector/TypeAnalyzerTrait.php @@ -2,6 +2,7 @@ namespace Rector\Rector; +use Nette\Utils\Strings; use PhpParser\Node; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\MethodCall; @@ -40,6 +41,18 @@ trait TypeAnalyzerTrait protected function isType(Node $node, string $type): bool { $nodeTypes = $this->getTypes($node); + + // fnmatch support + if (Strings::contains($type, '*')) { + foreach ($nodeTypes as $nodeType) { + if (fnmatch($type, $nodeType)) { + return true; + } + } + + return false; + } + return in_array($type, $nodeTypes, true); } diff --git a/tests/Rector/MethodCall/MethodNameReplacerRector/Fixture/nette_to_symfony_presenter.php.inc b/tests/Rector/MethodCall/MethodNameReplacerRector/Fixture/nette_to_symfony_presenter.php.inc new file mode 100644 index 00000000000..44503f39014 --- /dev/null +++ b/tests/Rector/MethodCall/MethodNameReplacerRector/Fixture/nette_to_symfony_presenter.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/tests/Rector/MethodCall/MethodNameReplacerRector/MethodNameReplacerRectorTest.php b/tests/Rector/MethodCall/MethodNameReplacerRector/MethodNameReplacerRectorTest.php index bb671837c73..beff3981a2c 100644 --- a/tests/Rector/MethodCall/MethodNameReplacerRector/MethodNameReplacerRectorTest.php +++ b/tests/Rector/MethodCall/MethodNameReplacerRector/MethodNameReplacerRectorTest.php @@ -20,6 +20,7 @@ final class MethodNameReplacerRectorTest extends AbstractRectorTestCase __DIR__ . '/Fixture/fixture5.php.inc', __DIR__ . '/Fixture/fixture6.php.inc', __DIR__ . '/Fixture/SomeClass.php', + __DIR__ . '/Fixture/nette_to_symfony_presenter.php.inc', ]); } @@ -47,6 +48,9 @@ final class MethodNameReplacerRectorTest extends AbstractRectorTestCase FormMacros::class => [ 'renderFormBegin' => ['Nette\Bridges\FormsLatte\Runtime', 'renderFormBegin'], ], + '*Presenter' => [ + 'run' => '__invoke', + ], ]; } }