Completed
Push — develop ( 67e161...8b0772 )
by Paul
05:50
created

UseNodeParser::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParser;
4
5
use PhpParser\Node;
6
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
7
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
8
9
/**
10
 * Class UseNodeParser.
11
 *
12
 * @author     Paul Thébaud <[email protected]>.
13
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
14
 * @license    https://opensource.org/licenses/MIT The MIT license.
15
 * @link       https://github.com/paul-thebaud/phpunit-generator
16
 * @since      Class available since Release 2.0.0.
17
 */
18
class UseNodeParser implements NodeParserInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function parse(Node $nodeToParse, NodeInterface $node): NodeInterface
24
    {
25
        /**
26
         * Overriding variable types.
27
         * @var Node\Stmt\Use_  $nodeToParse The namespace node to parse.
28
         * @var PhpFileModelInterface $node        The node which contains this namespace.
29
         */
30
        foreach ($nodeToParse->uses as $use) {
0 ignored issues
show
Bug introduced by
Accessing uses on the interface PhpParser\Node suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
31
            if ($use->alias !== null) {
32
                $node->addUse($use->alias, $use->name->toString());
33
            } else {
34
                $node->addUse($use->name->getLast(), $use->name->toString());
35
            }
36
        }
37
38
        return $node;
39
    }
40
}