make isType() cccept fnmatch with * as well

This commit is contained in:
Tomas Votruba 2019-02-02 17:12:12 +01:00
parent f29aae36e9
commit 3d80a53210
4 changed files with 44 additions and 2 deletions

View File

@ -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'

View File

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

View File

@ -0,0 +1,25 @@
<?php
namespace Rector\Tests\Rector\MethodCall\MethodNameReplacerRector\Fixture;
class SomePresenter
{
public function run()
{
}
}
?>
-----
<?php
namespace Rector\Tests\Rector\MethodCall\MethodNameReplacerRector\Fixture;
class SomePresenter
{
public function __invoke()
{
}
}
?>

View File

@ -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',
],
];
}
}