1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpUnitGen\Parser\NodeParser; |
4
|
|
|
|
5
|
|
|
use PhpParser\Node; |
6
|
|
|
use PhpUnitGen\Model\ClassModel; |
7
|
|
|
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface; |
8
|
|
|
use PhpUnitGen\Model\PropertyInterface\NodeInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ClassNodeParser. |
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 ClassNodeParser extends AbstractNodeParser |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* InterfaceNodeParser constructor. |
23
|
|
|
* |
24
|
|
|
* @param FunctionNodeParser $functionNodeParser The function node parser. |
25
|
|
|
* @param AttributeNodeParser $attributeNodeParser The attribute node parser. |
26
|
|
|
*/ |
27
|
|
|
public function __construct(FunctionNodeParser $functionNodeParser, AttributeNodeParser $attributeNodeParser) |
28
|
|
|
{ |
29
|
|
|
$this->nodeParsers[Node\Stmt\ClassMethod::class] = $functionNodeParser; |
30
|
|
|
$this->nodeParsers[Node\Stmt\Property::class] = $attributeNodeParser; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function parse(Node $node, NodeInterface $parent): NodeInterface |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Overriding variable types. |
40
|
|
|
* @var Node\Stmt\Class_ $node The class node to parse. |
41
|
|
|
* @var PhpFileModelInterface $parent The node which contains this namespace. |
42
|
|
|
*/ |
43
|
|
|
$class = new ClassModel(); |
44
|
|
|
$class->setName($node->name); |
|
|
|
|
45
|
|
|
$class->setIsAbstract($node->isAbstract()); |
46
|
|
|
$class->setIsFinal($node->isFinal()); |
47
|
|
|
|
48
|
|
|
$class = $this->parseSubNodes($node->stmts, $class); |
49
|
|
|
|
50
|
|
|
$parent->addClass($class); |
51
|
|
|
|
52
|
|
|
return $parent; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|