1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpUnitGen\Parser\NodeParser; |
4
|
|
|
|
5
|
|
|
use PhpParser\Comment\Doc; |
6
|
|
|
use PhpUnitGen\Annotation\AbstractAnnotation; |
7
|
|
|
use PhpUnitGen\Annotation\AnnotationFactory; |
8
|
|
|
use PhpUnitGen\Annotation\AnnotationParser; |
9
|
|
|
use PhpUnitGen\Annotation\AnnotationRegister; |
10
|
|
|
use PhpUnitGen\Annotation\AnnotationLexer; |
11
|
|
|
use PhpUnitGen\Exception\AnnotationParseException; |
12
|
|
|
use PhpUnitGen\Exception\Exception; |
13
|
|
|
use PhpUnitGen\Model\PropertyInterface\DocumentationInterface; |
14
|
|
|
use PhpUnitGen\Model\PropertyInterface\NodeInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class DocumentationNodeParser. |
18
|
|
|
* |
19
|
|
|
* @author Paul Thébaud <[email protected]>. |
20
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
21
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
22
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
23
|
|
|
* @since Class available since Release 2.0.0. |
24
|
|
|
*/ |
25
|
|
|
class DocumentationNodeParser |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var AnnotationParser $annotationParser The annotation parser to use. |
29
|
|
|
*/ |
30
|
|
|
private $annotationParser; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* DocumentationNodeParser constructor. |
34
|
|
|
* |
35
|
|
|
* @param AnnotationParser $annotationParser The annotation parser to use. |
36
|
|
|
*/ |
37
|
|
|
public function __construct(AnnotationParser $annotationParser) |
38
|
|
|
{ |
39
|
|
|
$this->annotationParser = $annotationParser; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Parse a node to update the parent node model. |
44
|
|
|
* |
45
|
|
|
* @param mixed $node The node to parse. |
46
|
|
|
* @param NodeInterface $parent The parent node. |
47
|
|
|
*/ |
48
|
|
|
public function invoke($node, NodeInterface $parent): void |
49
|
|
|
{ |
50
|
|
|
if (! $node instanceof Doc || ! $parent instanceof DocumentationInterface) { |
51
|
|
|
throw new Exception('DocumentationNodeParser is made to parse a documentation node'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$documentation = $node->getText(); |
55
|
|
|
$parent->setDocumentation($documentation); |
56
|
|
|
|
57
|
|
|
$this->annotationParser->invoke($parent, $documentation); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|