Completed
Push — develop ( e382f7...b48d9b )
by Paul
02:10
created

MethodNodeParser   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 15 1
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParser;
4
5
use PhpParser\Node;
6
use PhpUnitGen\Model\FunctionModel;
7
use PhpUnitGen\Model\ModelInterface\InterfaceModelInterface;
8
use PhpUnitGen\Parser\NodeParserUtil\MethodVisibilityTrait;
9
10
/**
11
 * Class MethodNodeParser.
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 MethodNodeParser extends AbstractFunctionNodeParser
20
{
21
    use MethodVisibilityTrait;
22
23
    /**
24
     * Parse a node to update the parent node model.
25
     *
26
     * @param Node\Stmt\ClassMethod   $node   The node to parse.
27
     * @param InterfaceModelInterface $parent The parent node.
28
     *
29
     * @return InterfaceModelInterface The updated parent.
30
     */
31
    public function invoke(Node\Stmt\ClassMethod $node, InterfaceModelInterface $parent): InterfaceModelInterface
32
    {
33
        $function = new FunctionModel();
34
        $function->setParentNode($parent);
35
        $function->setName($node->name);
36
        $function->setIsFinal($node->isFinal());
37
        $function->setIsStatic($node->isStatic());
38
        $function->setIsAbstract($node->isAbstract());
39
        $function->setVisibility($this->getMethodVisibility($node));
40
41
        $function = $this->parseFunction($node, $function);
42
43
        $parent->addFunction($function);
44
45
        return $parent;
46
    }
47
}
48