UseNodeParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 17
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 9 5
1
<?php
2
3
/**
4
 * This file is part of PhpUnitGen.
5
 *
6
 * (c) 2017-2018 Paul Thébaud <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpUnitGen\Parser\NodeParser;
13
14
use PhpParser\Node;
15
use PhpUnitGen\Exception\Exception;
16
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
17
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
18
19
/**
20
 * Class UseNodeParser.
21
 *
22
 * @author     Paul Thébaud <[email protected]>.
23
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
24
 * @license    https://opensource.org/licenses/MIT The MIT license.
25
 * @link       https://github.com/paul-thebaud/phpunit-generator
26
 * @since      Class available since Release 2.0.0.
27
 */
28
class UseNodeParser extends AbstractNodeParser
29
{
30
    /**
31
     * Parse a node to update the parent node model.
32
     *
33
     * @param mixed         $node   The node to parse.
34
     * @param NodeInterface $parent The parent node.
35
     */
36
    public function invoke($node, NodeInterface $parent): void
37
    {
38
        if (! $node instanceof Node\Stmt\Use_ || ! $parent instanceof PhpFileModelInterface) {
39
            throw new Exception('UseNodeParser is made to parse a use node');
40
        }
41
42
        if ($node->type === Node\Stmt\Use_::TYPE_NORMAL) {
43
            foreach ($node->uses as $use) {
44
                $parent->addUse($use->getAlias()->name, $use->name->toString());
45
            }
46
        }
47
    }
48
}
49