for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace PhpUnitGen\Parser\NodeParserUtil;
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
/**
* Class RootRetrieverHelper.
*
* @author Paul Thébaud <[email protected]>.
* @copyright 2017-2018 Paul Thébaud <[email protected]>.
* @license https://opensource.org/licenses/MIT The MIT license.
* @link https://github.com/paul-thebaud/phpunit-generator
* @since Class available since Release 2.0.0.
*/
class RootRetrieverHelper
{
* Get the root of the node.
* @param NodeInterface $node The node to search on.
* @return PhpFileModelInterface|null The root if it is found, else null.
public static function getRoot(NodeInterface $node): ?PhpFileModelInterface
$parent = $node;
while ($parent !== null) {
if ($parent instanceof PhpFileModelInterface) {
return $parent;
}
$parent = $parent->getParentNode();
return null;