for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Jerowork\ClassDependenciesParser\PhpParser\NodeVisitor;
use Jerowork\ClassDependenciesParser\Fqn;
use Jerowork\ClassDependenciesParser\ImportedFqn;
use Jerowork\ClassDependenciesParser\ClassDependencies;
use PhpParser\Node;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Use_;
use PhpParser\NodeVisitorAbstract;
final class ParseImportedFqnNodeVisitor extends NodeVisitorAbstract
{
public function __construct(
private readonly ClassDependencies $classDependencies,
) {
}
public function enterNode(Node $node): int|Node|null
if (!$node instanceof Use_ && !$node instanceof GroupUse) {
return parent::enterNode($node);
parent::enterNode($node)
PhpParser\NodeVisitorAbstract::enterNode()
This check looks for function or method calls that always return null and whose return value is used.
class A { function getObject() { return null; } } $a = new A(); if ($a->getObject()) {
The method getObject() can return nothing but null, so it makes no sense to use the return value.
getObject()
The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
$prefix = $node instanceof GroupUse ? sprintf('%s\\', $node->prefix) : '';
foreach ($node->uses as $use) {
$this->classDependencies->addImportedFqn(new ImportedFqn(
new Fqn($prefix . $use->name),
true,
$use->alias !== null ? (string) $use->alias : null,
));
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.