for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of PhpUnitGen.
*
* (c) 2017-2018 Paul Thébaud <[email protected]>
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace PhpUnitGen\Parser\NodeParser;
use PhpParser\Node;
use PhpUnitGen\Exception\Exception;
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
* Class UseNodeParser.
* @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 UseNodeParser extends AbstractNodeParser
{
* Parse a node to update the parent node model.
* @param mixed $node The node to parse.
* @param NodeInterface $parent The parent node.
public function invoke($node, NodeInterface $parent): void
if (! $node instanceof Node\Stmt\Use_ || ! $parent instanceof PhpFileModelInterface) {
throw new Exception('UseNodeParser is made to parse a use node');
}
if ($node->type === Node\Stmt\Use_::TYPE_NORMAL) {
foreach ($node->uses as $use) {
$parent->addUse($use->getAlias()->name, $use->name->toString());