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

AttributeNodeParser::retrieveVisibility()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParser;
4
5
use PhpParser\Node;
6
use PhpUnitGen\Model\AttributeModel;
7
use PhpUnitGen\Model\ModelInterface\TraitModelInterface;
8
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
9
use PhpUnitGen\Parser\NodeParserTrait\VisibilityTrait;
10
use Respect\Validation\Validator;
11
12
/**
13
 * Class AttributeNodeParser.
14
 *
15
 * @author     Paul Thébaud <[email protected]>.
16
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
17
 * @license    https://opensource.org/licenses/MIT The MIT license.
18
 * @link       https://github.com/paul-thebaud/phpunit-generator
19
 * @since      Class available since Release 2.0.0.
20
 */
21
class AttributeNodeParser extends AbstractNodeParser
22
{
23
    use VisibilityTrait;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function parse(Node $node, NodeInterface $parent): NodeInterface
29
    {
30
        /**
31
         * Overriding variable types.
32
         * @var Node\Stmt\Property  $node   The property node to parse.
33
         * @var TraitModelInterface $parent The node which contains this namespace.
34
         */
35
        if (! Validator::instance(Node\Stmt\Property::class)->validate($node)) {
36
            return $parent;
37
        }
38
39
        $isStatic = $node->isStatic();
40
        $visibility = $this->parseVisibility($node);
41
42
        foreach ($node->props as $property) {
43
            $attribute = new AttributeModel();
44
            $attribute->setName($property->name);
45
            $attribute->setIsStatic($isStatic);
46
            $attribute->setVisibility($visibility);
47
48
            /** @todo */
49
            $attribute->setValue(null);
50
51
            $parent->addAttribute($attribute);
52
        }
53
54
        return $parent;
55
    }
56
}
57