DocumentationNodeParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 8
c 3
b 0
f 0
dl 0
loc 33
rs 10
wmc 4

2 Methods

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