This commit is contained in:
TomasVotruba 2018-02-13 20:25:40 +01:00
parent a270d174c9
commit 3bfad4e873
2 changed files with 27 additions and 10 deletions

View File

@ -124,7 +124,7 @@ final class ArgumentReplacerRector extends AbstractRector
$argumentReplacerItemRecipes = [];
foreach ($this->argumentReplacerRecipes as $argumentReplacerRecipe) {
if ($this->isTypeAndMethod($node, $argumentReplacerRecipe->getClass(), $argumentReplacerRecipe->getMethod())) {
if ($this->isRecipeMatch($node, $argumentReplacerRecipe)) {
$argumentReplacerItemRecipes[] = $argumentReplacerRecipe;
}
}
@ -161,8 +161,11 @@ final class ArgumentReplacerRector extends AbstractRector
}
}
private function isTypeAndMethod(Node $node, string $type, string $method): bool
private function isRecipeMatch(Node $node, ArgumentReplacerRecipe $argumentReplacerRecipe): bool
{
$type = $argumentReplacerRecipe->getClass();
$method = $argumentReplacerRecipe->getMethod();
if ($this->methodCallAnalyzer->isTypeAndMethods($node, $type, [$method])) {
return true;
}
@ -174,6 +177,9 @@ final class ArgumentReplacerRector extends AbstractRector
return $this->classMethodAnalyzer->isTypeAndMethods($node, $type, [$method]);
}
/**
* @param mixed[] $configurationArrays
*/
private function loadArgumentReplacerItemRecipes(array $configurationArrays): void
{
foreach ($configurationArrays as $configurationArray) {

View File

@ -25,14 +25,17 @@ final class ArgumentReplacerRecipe
* @var string
*/
private $class;
/**
* @var string
*/
private $method;
/**
* @var int
*/
private $position;
/**
* @var string
*/
@ -74,14 +77,7 @@ final class ArgumentReplacerRecipe
public static function createFromArray(array $data): self
{
// @todo: make exceptions clear for end user
Assert::keyExists($data, 'class');
Assert::keyExists($data, 'method');
Assert::keyExists($data, 'position');
Assert::keyExists($data, 'type');
if ($data['type'] === 'replace_default_value') {
Assert::keyExists($data, 'replace_map');
}
self::validateArrayData($data);
return new self(
$data['class'],
@ -93,6 +89,21 @@ final class ArgumentReplacerRecipe
);
}
/**
* @param mixed[] $data
*/
private static function validateArrayData(array $data): void
{
Assert::keyExists($data, 'class');
Assert::keyExists($data, 'method');
Assert::keyExists($data, 'position');
Assert::keyExists($data, 'type');
if ($data['type'] === 'replace_default_value') {
Assert::keyExists($data, 'replace_map');
}
}
public function getClass(): string
{
return $this->class;