fix cyclox

This commit is contained in:
TomasVotruba 2017-10-18 13:50:56 +02:00
parent f6d01ebfec
commit 7203e18c7f

View File

@ -35,19 +35,17 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
private $nodeFactory; private $nodeFactory;
/** /**
* @var mixed * @var mixed[]
*/ */
private $activeTransformation; private $activeTransformation = [];
/** /**
* Type to method call() * Type to method call()
* *
* @param string[] $typeToMethodCalls * @param string[] $typeToMethodCalls
*/ */
public function __construct( public function __construct(array $typeToMethodCalls, NodeFactory $nodeFactory)
array $typeToMethodCalls, {
NodeFactory $nodeFactory
) {
$this->typeToMethodCalls = $typeToMethodCalls; $this->typeToMethodCalls = $typeToMethodCalls;
$this->nodeFactory = $nodeFactory; $this->nodeFactory = $nodeFactory;
} }
@ -64,17 +62,13 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
return false; return false;
} }
/** @var ArrayDimFetch $var */
foreach ($node->vars as $var) { foreach ($node->vars as $var) {
$variableNode = $var->var; if (! $var instanceof ArrayDimFetch) {
$variableNodeType = $variableNode->getAttribute(Attribute::TYPE); continue;
}
foreach ($this->typeToMethodCalls as $type => $transformation) { if ($this->matchArrayDimFetch($var)) {
if ($variableNodeType === $type) { return true;
$this->activeTransformation = $transformation;
return true;
}
} }
} }
@ -123,4 +117,19 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
return null; return null;
} }
private function matchArrayDimFetch(ArrayDimFetch $arrayDimFetchNode): bool
{
$variableNodeType = $arrayDimFetchNode->var->getAttribute(Attribute::TYPE);
foreach ($this->typeToMethodCalls as $type => $transformation) {
if ($variableNodeType === $type) {
$this->activeTransformation = $transformation;
return true;
}
}
return false;
}
} }