for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\Classifier;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
/**
* @internal Visitor for Classifier
*/
final class ClassifierVisitor extends NodeVisitorAbstract
{
* @var array<class-string>
array<class-string>
2
private array $classNames = [];
* @param \Closure(class-string): bool $shouldSkipClass
public function __construct(private \Closure $shouldSkipClass)
}
public function enterNode(Node $node)
if ($node instanceof Node\Stmt\Class_) {
* @psalm-var class-string|null $className
$className = $node->namespacedName?->toString();
if ($className !== null && !($this->shouldSkipClass)($className)) {
$this->classNames[] = $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 array<class-string>
public function getClassNames(): array
return $this->classNames;