Completed
Push — develop ( 763ea8...df26dc )
by Paul
01:58
created

TraitNodeParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 15 1
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParser;
4
5
use PhpParser\Node;
6
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
7
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
8
use PhpUnitGen\Model\TraitModel;
9
10
/**
11
 * Class TraitNodeParser.
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 TraitNodeParser extends AbstractNodeParser
20
{
21
    /**
22
     * InterfaceNodeParser constructor.
23
     *
24
     * @param MethodNodeParser    $methodNodeParser    The method node parser.
25
     * @param AttributeNodeParser $attributeNodeParser The attribute node parser.
26
     */
27
    public function __construct(MethodNodeParser $methodNodeParser, AttributeNodeParser $attributeNodeParser)
28
    {
29
        $this->nodeParsers[Node\Stmt\ClassMethod::class] = $methodNodeParser;
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\Trait_      $node   The namespace node to parse.
41
         * @var PhpFileModelInterface $parent The node which contains this namespace.
42
         */
43
        $trait = new TraitModel();
44
        $trait->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
        $trait->setName(/** @scrutinizer ignore-type */ $node->name);
Loading history...
45
46
        $trait = $this->parseSubNodes($node->stmts, $trait);
47
48
        $parent->addTrait($trait);
49
50
        return $parent;
51
    }
52
}
53