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

NamespaceNodeParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 12 2
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
use Respect\Validation\Validator;
9
10
/**
11
 * Class NamespaceNodeParser.
12
 *
13
 * @author     Paul Thébaud <[email protected]>.
14
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
15
 * @license    https://opensource.org/licenses/MIT The MIT license.
16
 * @link       https://github.com/paul-thebaud/phpunit-generator
17
 * @since      Class available since Release 2.0.0.
18
 */
19
class NamespaceNodeParser implements NodeParserInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function parse(Node $nodeToParse, NodeInterface $node): NodeInterface
25
    {
26
        /**
27
         * Overriding variable types.
28
         * @var Node\Stmt\Namespace_  $nodeToParse The namespace node to parse.
29
         * @var PhpFileModelInterface $node        The node which contains this namespace.
30
         */
31
        if (Validator::instance(Node\Name::class)->validate($nodeToParse->name)) {
32
            $node->setNamespace($nodeToParse->name->parts);
33
        }
34
35
        return $node;
36
    }
37
}