|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpUnitGen\Parser\NodeParser; |
|
4
|
|
|
|
|
5
|
|
|
use PhpParser\Node; |
|
6
|
|
|
use PhpUnitGen\Exception\Exception; |
|
7
|
|
|
use PhpUnitGen\Model\PropertyInterface\NodeInterface; |
|
8
|
|
|
use PhpUnitGen\Parser\NodeParserUtil\UsePreParseTrait; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class PhpFileNodeParser. |
|
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 PhpFileNodeParser extends AbstractNodeParser |
|
20
|
|
|
{ |
|
21
|
|
|
use UsePreParseTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* PhpFileNodeParser constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param NamespaceNodeParser $namespaceNodeParser The namespace node parser to use. |
|
27
|
|
|
* @param UseNodeParser $useNodeParser The use node parser to use. |
|
28
|
|
|
* @param GroupUseNodeParser $groupUseNodeParser The group use node parser to use. |
|
29
|
|
|
* @param FunctionNodeParser $functionNodeParser The function node parser to use. |
|
30
|
|
|
* @param ClassNodeParser $classNodeParser The class node parser to use. |
|
31
|
|
|
* @param TraitNodeParser $traitNodeParser The trait node parser to use. |
|
32
|
|
|
* @param InterfaceNodeParser $interfaceNodeParser The interface node parser to use. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct( |
|
35
|
|
|
NamespaceNodeParser $namespaceNodeParser, |
|
36
|
|
|
UseNodeParser $useNodeParser, |
|
37
|
|
|
GroupUseNodeParser $groupUseNodeParser, |
|
38
|
|
|
FunctionNodeParser $functionNodeParser, |
|
39
|
|
|
ClassNodeParser $classNodeParser, |
|
40
|
|
|
TraitNodeParser $traitNodeParser, |
|
41
|
|
|
InterfaceNodeParser $interfaceNodeParser |
|
42
|
|
|
) { |
|
43
|
|
|
$this->nodeParsers[Node\Stmt\Namespace_::class] = $namespaceNodeParser; |
|
44
|
|
|
$this->nodeParsers[Node\Stmt\Function_::class] = $functionNodeParser; |
|
45
|
|
|
$this->nodeParsers[Node\Stmt\Class_::class] = $classNodeParser; |
|
46
|
|
|
$this->nodeParsers[Node\Stmt\Trait_::class] = $traitNodeParser; |
|
47
|
|
|
$this->nodeParsers[Node\Stmt\Interface_::class] = $interfaceNodeParser; |
|
48
|
|
|
|
|
49
|
|
|
$this->useNodeParser = $useNodeParser; |
|
50
|
|
|
$this->groupUseNodeParser = $groupUseNodeParser; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function invoke($node, NodeInterface $parent): void |
|
57
|
|
|
{ |
|
58
|
|
|
throw new Exception('A PhpFile is the root of parsing, so only sub-statements can be parsed.'); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|