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

ClassNodeParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
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\ClassModel;
7
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
8
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
9
10
/**
11
 * Class ClassNodeParser.
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 ClassNodeParser extends AbstractNodeParser
20
{
21
    /**
22
     * InterfaceNodeParser constructor.
23
     *
24
     * @param FunctionNodeParser  $functionNodeParser  The function node parser.
25
     * @param AttributeNodeParser $attributeNodeParser The attribute node parser.
26
     */
27
    public function __construct(FunctionNodeParser $functionNodeParser, AttributeNodeParser $attributeNodeParser)
28
    {
29
        $this->nodeParsers[Node\Stmt\ClassMethod::class] = $functionNodeParser;
30
        $this->nodeParsers[Node\Stmt\Property::class]    = $attributeNodeParser;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function parse(Node $node, NodeInterface $parent): NodeInterface
37
    {
38
        /**
39
         * Overriding variable types.
40
         * @var Node\Stmt\Class_      $node   The class node to parse.
41
         * @var PhpFileModelInterface $parent The node which contains this namespace.
42
         */
43
        $class = new ClassModel();
44
        $class->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

44
        $class->setName(/** @scrutinizer ignore-type */ $node->name);
Loading history...
45
        $class->setIsAbstract($node->isAbstract());
46
        $class->setIsFinal($node->isFinal());
47
48
        $class = $this->parseSubNodes($node->stmts, $class);
49
50
        $parent->addClass($class);
51
52
        return $parent;
53
    }
54
}
55