mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
504a41770d
f8e04774ad
Fixing scoped build (#1143)
40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Naming\NamingConvention;
|
|
|
|
use RectorPrefix20211104\Nette\Utils\Strings;
|
|
use PhpParser\Node\Expr\FuncCall;
|
|
use PhpParser\Node\Expr\MethodCall;
|
|
use PhpParser\Node\Expr\StaticCall;
|
|
use Rector\NodeNameResolver\NodeNameResolver;
|
|
final class NamingConventionAnalyzer
|
|
{
|
|
/**
|
|
* @var \Rector\NodeNameResolver\NodeNameResolver
|
|
*/
|
|
private $nodeNameResolver;
|
|
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver)
|
|
{
|
|
$this->nodeNameResolver = $nodeNameResolver;
|
|
}
|
|
/**
|
|
* Matches cases:
|
|
*
|
|
* $someNameSuffix = $this->getSomeName();
|
|
* $prefixSomeName = $this->getSomeName();
|
|
* $someName = $this->getSomeName();
|
|
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $expr
|
|
*/
|
|
public function isCallMatchingVariableName($expr, string $currentName, string $expectedName) : bool
|
|
{
|
|
// skip "$call = $method->call();" based conventions
|
|
$callName = $this->nodeNameResolver->getName($expr->name);
|
|
if ($currentName === $callName) {
|
|
return \true;
|
|
}
|
|
// starts with or ends with
|
|
return (bool) \RectorPrefix20211104\Nette\Utils\Strings::match($currentName, '#^(' . $expectedName . '|' . $expectedName . '$)#i');
|
|
}
|
|
}
|