for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\Php7to5\NodeVisitors;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
class GroupUseReplacer extends NodeVisitorAbstract
{
public function leaveNode(Node $node)
if (!$node instanceof Node\Stmt\GroupUse) {
return;
}
$nodePrefixParts = $node->prefix->parts;
$seperateUseStatements = array_map(function ($useNode) use ($nodePrefixParts) {
return $this->createUseNode($nodePrefixParts, $useNode);
}, $node->uses);
return $seperateUseStatements;
protected function createUseNode(array $nodePrefixParts, Node $useNode)
$fullClassName = array_merge($nodePrefixParts, [$useNode->name]);
name
PhpParser\Node
instanceof
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Adding an additional type check:
interface SomeInterface { } class SomeClass implements SomeInterface { public $a; } function someFunction(SomeInterface $object) { if ($object instanceof SomeClass) { $a = $object->a; } }
Changing the type hint:
interface SomeInterface { } class SomeClass implements SomeInterface { public $a; } function someFunction(SomeClass $object) { $a = $object->a; }
$nameNode = new Node\Name($fullClassName);
$alias = ($useNode->alias == $useNode->name) ? null : $useNode->alias;
alias
$useNode = new Node\Stmt\Use_([new Node\Stmt\UseUse($nameNode, $alias)], $useNode->type);
type
return $useNode;
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: