FunctionNodeParser::invoke()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 3
nop 2
dl 0
loc 18
rs 9.9332
c 0
b 0
f 0
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\Node;
15
use PhpUnitGen\Exception\Exception;
16
use PhpUnitGen\Model\FunctionModel;
17
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
18
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
19
20
/**
21
 * Class FunctionNodeParser.
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 FunctionNodeParser extends AbstractFunctionNodeParser
30
{
31
    /**
32
     * Parse a node to update the parent node model.
33
     *
34
     * @param mixed         $node   The node to parse.
35
     * @param NodeInterface $parent The parent node.
36
     */
37
    public function invoke($node, NodeInterface $parent): void
38
    {
39
        if (! $node instanceof Node\Stmt\Function_ || ! $parent instanceof PhpFileModelInterface) {
40
            throw new Exception('FunctionNodeParser is made to parse a function node');
41
        }
42
43
        $function = new FunctionModel();
44
        $function->setParentNode($parent);
45
        $function->setName($node->name);
46
        $function->setIsGlobal(true);
47
48
        $this->parseFunction($node, $function);
49
50
        if (($documentation = $node->getDocComment()) !== null) {
51
            $this->documentationNodeParser->invoke($documentation, $function);
52
        }
53
54
        $parent->addFunction($function);
55
    }
56
}
57