for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Benoth\StaticReflection\Parser;
use PhpParser\Node as NodeInterface;
use PhpParser\NodeVisitorAbstract;
/**
* @codeCoverageIgnore
*/
class DebugNodeVisitor extends NodeVisitorAbstract
{
protected $level = 0;
public function enterNode(NodeInterface $node)
$this->debug(str_repeat(' ', ++$this->level).$node->getType().(property_exists($node, 'name') ? ' '.(method_exists($node->name, 'toString') ? $node->name->toString() : $node->name) : '').(method_exists($node, 'getLine') ? ' L:'.$node->getLine() : '').PHP_EOL);
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; }
}
public function leaveNode(NodeInterface $node)
--$this->level;
public function beforeTraverse(array $nodes)
$this->level = 0;
$this->debug('BeforeTraverse'.PHP_EOL);
public function afterTraverse(array $nodes)
$this->debug('AfterTraverse'.PHP_EOL);
* @param string $text
protected function debug($text)
echo $text;
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: