MethodCallAnalyzer - added isMethodCallTypeAndMethod + misc

This commit is contained in:
TomasVotruba 2017-10-14 21:00:26 +02:00
parent 2c71f647f7
commit 7aa73fbdc0
4 changed files with 22 additions and 6 deletions

View File

@ -8,6 +8,7 @@
],
"require": {
"php": "^7.1",
"beberlei/assert": "^2.7",
"nette/utils": "^2.4",
"nikic/php-parser": "4.0.x-dev#ed8a744c as 3.1.1",
"rector/better-reflection": "^3.0",

View File

@ -47,7 +47,6 @@ final class RectorGuessFilter
$maxSimilarity = strlen($rectorGuess->getMessage()) * self::MAX_RELATIVE_SIMIARITY;
foreach ($allMessages as $message) {
// experimental
$levenshtein = levenshtein($rectorGuess->getMessage(), $message);
if ($levenshtein !== 0 && $levenshtein < $maxSimilarity) {
continue 2;

View File

@ -54,9 +54,11 @@ final class RectorsExtension extends Extension
foreach ($rectors as $rectorClass => $arguments) {
$rectorDefinition = $containerBuilder->autowire($rectorClass);
if (count($arguments)) {
$rectorDefinition->setArguments([$arguments]);
if (! count($arguments)) {
continue;
}
$rectorDefinition->setArguments([$arguments]);
}
}
}

View File

@ -15,15 +15,29 @@ final class MethodCallAnalyzer
/**
* Checks "$this->classOfSpecificType->specificMethodName()"
*
* @param string[] $methodsNames
* @param string[] $methods
*/
public function isMethodCallTypeAndMethods(Node $node, string $type, array $methodsNames): bool
public function isMethodCallTypeAndMethods(Node $node, string $type, array $methods): bool
{
if (! $this->isMethodCallType($node, $type)) {
return false;
}
return in_array((string) $node->name, $methodsNames, true);
/** @var MethodCall $node */
return in_array((string) $node->name, $methods, true);
}
/**
* Checks "$this->classOfSpecificType->specificMethodName()"
*/
public function isMethodCallTypeAndMethod(Node $node, string $type, string $method): bool
{
if (! $this->isMethodCallType($node, $type)) {
return false;
}
/** @var MethodCall $node */
return $node->name === $method;
}
/**