Completed
Push — develop ( cec1b5...82146f )
by Paul
02:04
created

FunctionNodeParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 2
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParser;
4
5
use PhpParser\Node;
6
use PhpUnitGen\Model\FunctionModel;
7
use PhpUnitGen\Model\PropertyInterface\ClassLikeInterface;
8
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
9
use PhpUnitGen\Parser\NodeParserTrait\DocumentationTrait;
10
use PhpUnitGen\Parser\NodeParserTrait\ParamTrait;
11
use PhpUnitGen\Parser\NodeParserTrait\VisibilityTrait;
12
13
/**
14
 * Class FunctionNodeParser.
15
 *
16
 * @author     Paul Thébaud <[email protected]>.
17
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
18
 * @license    https://opensource.org/licenses/MIT The MIT license.
19
 * @link       https://github.com/paul-thebaud/phpunit-generator
20
 * @since      Class available since Release 2.0.0.
21
 */
22
class FunctionNodeParser extends AbstractNodeParser
23
{
24
    use VisibilityTrait;
25
    use DocumentationTrait;
26
    use ParamTrait;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function parse(Node $node, NodeInterface $parent): NodeInterface
32
    {
33
        /**
34
         * Overriding variable types.
35
         * @var Node\Stmt\ClassMethod $node   The function node to parse.
36
         * @var ClassLikeInterface    $parent The node which contains this namespace.
37
         */
38
        $function = new FunctionModel();
39
        $function->setName($node->name);
40
        $function->setDocumentation($this->parseDocumentation($node));
41
        $function->setIsFinal($node->isFinal());
42
        $function->setIsStatic($node->isStatic());
43
        $function->setIsAbstract($node->isAbstract());
44
        $function->setVisibility($this->parseVisibility($node));
45
46
        foreach ($node->getParams() as $param) {
47
            $function->addParameter($this->parseParam($param));
48
        }
49
50
        $parent->addFunction($function);
51
52
        return $parent;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $parent returns the type PhpUnitGen\Model\Propert...face\ClassLikeInterface which is incompatible with the type-hinted return PhpUnitGen\Model\PropertyInterface\NodeInterface.
Loading history...
53
    }
54
}
55