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 extends AbstractNodeParser |
20
|
|
|
{ |
21
|
|
|
public function __construct( |
22
|
|
|
UseNodeParser $useNodeParser, |
23
|
|
|
InterfaceNodeParser $interfaceNodeParser, |
24
|
|
|
TraitNodeParser $traitNodeParser |
25
|
|
|
) { |
26
|
|
|
$this->nodeParsers[Node\Stmt\Use_::class] = $useNodeParser; |
27
|
|
|
$this->nodeParsers[Node\Stmt\Interface_::class] = $interfaceNodeParser; |
28
|
|
|
$this->nodeParsers[Node\Stmt\Trait_::class] = $traitNodeParser; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function parse(Node $node, NodeInterface $parent): NodeInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Overriding variable types. |
38
|
|
|
* @var Node\Stmt\Namespace_ $node The namespace node to parse. |
39
|
|
|
* @var PhpFileModelInterface $parent The node which contains this namespace. |
40
|
|
|
*/ |
41
|
|
|
if (Validator::instance(Node\Name::class)->validate($node->name)) { |
42
|
|
|
$parent->setNamespace($node->name->parts); |
43
|
|
|
} |
44
|
|
|
$parent = $this->parseSubNodes($node->stmts, $parent); |
45
|
|
|
|
46
|
|
|
return $parent; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|