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\ClassDependencies;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Enum_;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Trait_;
use PhpParser\NodeVisitorAbstract;
final class ParseClassFqnNodeVisitor extends NodeVisitorAbstract
{
private ?string $namespace = null;
private ?string $className = null;
public function __construct(
private readonly ClassDependencies $classDependencies,
) {
}
public function enterNode(Node $node): int|Node|null
if ($node instanceof Namespace_) {
$this->namespace = (string) $node->name;
if ($node instanceof Class_ || $node instanceof Trait_ || $node instanceof Interface_ || $node instanceof Enum_) {
$this->className = (string) $node->name;
if ($this->namespace !== null && $this->className !== null) {
$this->classDependencies->setFqn(new Fqn(sprintf('%s\%s', $this->namespace, $this->className)));
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.
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.