PropertyParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parse() 0 18 3
1
<?php
2
3
namespace Padawan\Parser;
4
5
use Padawan\Domain\Project\Node\ClassProperty;
6
use PhpParser\Node\Stmt\PropertyProperty as Property;
7
8
class PropertyParser {
9
10
    public function __construct(CommentParser $commentParser) {
11
        $this->commentParser = $commentParser;
12
    }
13
14
    /**
15
     * Parses Property node to ClassProperty
16
     *
17
     * @param $node Property
18
     *
19
     * @return ClassProperty
20
     */
21
    public function parse(Property $node, $modifier = 0, $comments = null)
22
    {
23
        $prop = new ClassProperty;
24
        $prop->name = $node->name;
25
        $prop->setModifier($modifier);
26
        if (empty($comments)) {
27
            $comments = $node->getAttribute("comments");
28
        }
29
        $comment = $this->commentParser->parse(
30
            $comments
31
        );
32
        $var = $comment->getProperty($prop->name);
33
        if (!empty($var)) {
34
            $prop->doc = $comment->getDoc();
35
            $prop->type = $var->getType();
36
        }
37
        return $prop;
38
    }
39
40
    /**
41
     * @var CommentParser
42
     */
43
    private $commentParser;
44
}
45