for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Jerowork\FileClassReflector\NikicParser;
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 FqcnNodeVisitor extends NodeVisitorAbstract
{
private ?string $namespace = null;
private ?string $className = null;
/**
* @var null|class-string
null|class-string
2
*/
private ?string $fqcn = null;
public function enterNode(Node $node) : null|array|int|Node
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;
/** @var class-string $fqcn */
$fqcn = $this->className;
$this->fqcn = $fqcn;
if ($this->namespace !== null && $this->className !== null) {
$fqcn = 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.
* @return null|class-string
public function getFqcn() : ?string
return $this->fqcn;