Passed
Push — develop ( fb709e...b69568 )
by Paul
03:14
created

InterfaceNodeParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParser;
4
5
use PhpParser\Node;
6
use PhpUnitGen\Model\InterfaceModel;
7
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
8
use PhpUnitGen\Parser\NodeParser\NodeParserInterface\InterfaceNodeParserInterface;
9
use PhpUnitGen\Parser\NodeParser\NodeParserInterface\MethodNodeParserInterface;
10
11
/**
12
 * Class InterfaceNodeParser.
13
 *
14
 * @author     Paul Thébaud <[email protected]>.
15
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
16
 * @license    https://opensource.org/licenses/MIT The MIT license.
17
 * @link       https://github.com/paul-thebaud/phpunit-generator
18
 * @since      Class available since Release 2.0.0.
19
 */
20
class InterfaceNodeParser extends AbstractNodeParser implements InterfaceNodeParserInterface
21
{
22
    /**
23
     * InterfaceNodeParser constructor.
24
     *
25
     * @param MethodNodeParserInterface $methodNodeParser The method node parser to use.
26
     */
27
    public function __construct(
28
        MethodNodeParserInterface $methodNodeParser
29
    ) {
30
        $this->nodeParsers[Node\Stmt\ClassMethod::class] = $methodNodeParser;
31
    }
32
33
    /**
34
     * Parse a node to update the parent node model.
35
     *
36
     * @param Node\Stmt\Interface_  $node   The node to parse.
37
     * @param PhpFileModelInterface $parent The parent node.
38
     *
39
     * @return PhpFileModelInterface The updated parent.
40
     */
41
    public function invoke(Node\Stmt\Interface_ $node, PhpFileModelInterface $parent): PhpFileModelInterface
42
    {
43
        $interface = new InterfaceModel();
44
        $interface->setParentNode($parent);
45
        $interface->setName($node->name);
0 ignored issues
show
Bug introduced by
It seems like $node->name can also be of type null; however, parameter $name of PhpUnitGen\Model\InterfaceModel::setName() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        $interface->setName(/** @scrutinizer ignore-type */ $node->name);
Loading history...
46
47
        $interface = $this->parseSubNodes($node->stmts, $interface);
48
49
        $parent->addInterface($interface);
50
51
        return $parent;
52
    }
53
}