mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-20 23:41:57 +02:00
make isType() cccept fnmatch with * as well
This commit is contained in:
parent
f29aae36e9
commit
3d80a53210
4
ecs.yml
4
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'
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user