mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-22 16:32:27 +02:00
commit
3f805d93c3
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Fixture;
|
||||
|
||||
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Source\ClassMethodToBeSkipped;
|
||||
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Source\SomeTranslator;
|
||||
|
||||
class UnderScoreOnly
|
||||
{
|
||||
/**
|
||||
* @var SomeTranslator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
private function createHtml()
|
||||
{
|
||||
$this->translator->__('...');
|
||||
$this->translator->getLocale();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Fixture;
|
||||
|
||||
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Source\ClassMethodToBeSkipped;
|
||||
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Source\SomeTranslator;
|
||||
|
||||
class UnderScoreOnly
|
||||
{
|
||||
/**
|
||||
* @var SomeTranslator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
private function createHtml()
|
||||
{
|
||||
$this->translator->trans('...');
|
||||
$this->translator->getLocale();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -8,6 +8,7 @@ use Iterator;
|
||||
use Nette\Utils\Html;
|
||||
use Rector\Renaming\Rector\MethodCall\RenameMethodCallRector;
|
||||
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Source\ClassMethodToBeSkipped;
|
||||
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Source\SomeTranslator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
final class RenameMethodCallRectorTest extends AbstractRectorTestCase
|
||||
@ -43,6 +44,10 @@ final class RenameMethodCallRectorTest extends AbstractRectorTestCase
|
||||
ClassMethodToBeSkipped::class => [
|
||||
'createHtml' => 'testHtml',
|
||||
],
|
||||
SomeTranslator::class => [
|
||||
'__' => 'trans',
|
||||
'__t' => 'trans',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Renaming\Tests\Rector\MethodCall\RenameMethodCallRector\Source;
|
||||
|
||||
final class SomeTranslator
|
||||
{
|
||||
|
||||
}
|
@ -59,7 +59,7 @@ final class NameResolver
|
||||
}
|
||||
|
||||
// is probably regex pattern
|
||||
if (($name[0] === $name[strlen($name) - 1]) && ! ctype_alpha($name[0])) {
|
||||
if ($this->isRegexPattern($name)) {
|
||||
return (bool) Strings::match($resolvedName, $name);
|
||||
}
|
||||
|
||||
@ -224,4 +224,22 @@ final class NameResolver
|
||||
|
||||
return (string) $functionName;
|
||||
}
|
||||
|
||||
private function isRegexPattern(string $name): bool
|
||||
{
|
||||
if (Strings::length($name) <= 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$firstChar = $name[0];
|
||||
$lastChar = $name[strlen($name) - 1];
|
||||
if ($firstChar !== $lastChar) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// this prevents miss matching like "aMethoda"
|
||||
$possibleDelimiters = ['#', '~', '/'];
|
||||
|
||||
return in_array($firstChar, $possibleDelimiters, true);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user