1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpUnitGen\Parser\NodeParser; |
4
|
|
|
|
5
|
|
|
use PhpParser\Node; |
6
|
|
|
use PhpUnitGen\Model\InterfaceModel; |
7
|
|
|
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface; |
8
|
|
|
use PhpUnitGen\Parser\NodeParser\NodeParserInterface\InterfaceNodeParserInterface; |
9
|
|
|
use PhpUnitGen\Parser\NodeParser\NodeParserInterface\MethodNodeParserInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class InterfaceNodeParser. |
13
|
|
|
* |
14
|
|
|
* @author Paul Thébaud <[email protected]>. |
15
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
16
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
17
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
18
|
|
|
* @since Class available since Release 2.0.0. |
19
|
|
|
*/ |
20
|
|
|
class InterfaceNodeParser extends AbstractNodeParser implements InterfaceNodeParserInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* InterfaceNodeParser constructor. |
24
|
|
|
* |
25
|
|
|
* @param MethodNodeParserInterface $methodNodeParser The method node parser to use. |
26
|
|
|
*/ |
27
|
|
|
public function __construct( |
28
|
|
|
MethodNodeParserInterface $methodNodeParser |
29
|
|
|
) { |
30
|
|
|
$this->nodeParsers[Node\Stmt\ClassMethod::class] = $methodNodeParser; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Parse a node to update the parent node model. |
35
|
|
|
* |
36
|
|
|
* @param Node\Stmt\Interface_ $node The node to parse. |
37
|
|
|
* @param PhpFileModelInterface $parent The parent node. |
38
|
|
|
* |
39
|
|
|
* @return PhpFileModelInterface The updated parent. |
40
|
|
|
*/ |
41
|
|
|
public function invoke(Node\Stmt\Interface_ $node, PhpFileModelInterface $parent): PhpFileModelInterface |
42
|
|
|
{ |
43
|
|
|
$interface = new InterfaceModel(); |
44
|
|
|
$interface->setParentNode($parent); |
45
|
|
|
$interface->setName($node->name); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$interface = $this->parseSubNodes($node->stmts, $interface); |
48
|
|
|
|
49
|
|
|
$parent->addInterface($interface); |
50
|
|
|
|
51
|
|
|
return $parent; |
52
|
|
|
} |
53
|
|
|
} |