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