Passed
Push — 1.6 ( c2a002 )
by Luis
05:37
created

TraitNamesBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildTraits() 0 17 3
A traitNames() 0 6 2
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Parser\Code\Builders\Names;
9
10
use PhpParser\Node;
11
use PhpParser\Node\Name;
12
use PhpParser\Node\Stmt\TraitUse;
13
use PhUml\Code\Name as TraitName;
14
15
trait TraitNamesBuilder
16
{
17
    /** @param Node[] $nodes */
18
    protected function buildTraits(array $nodes): array
19
    {
20 120
        $useStatements = array_filter($nodes, function (Node $node) {
21 108
            return $node instanceof TraitUse;
22 120
        });
23
24 120
        if (empty($useStatements)) {
25 111
            return [];
26
        }
27
28 45
        $traits = [];
29
        /** @var TraitUse  $use */
30 45
        foreach ($useStatements as $use) {
31 45
            $traits = $this->traitNames($use, $traits);
32
        }
33
34 45
        return $traits;
35
    }
36
37
    /**
38
     * @param Name[] $traits
39
     * @return TraitName[]
40
     */
41 45
    private function traitNames(TraitUse $use, array $traits): array
42
    {
43 45
        foreach ($use->traits as $name) {
44 45
            $traits[] = TraitName::from($name->getLast());
45
        }
46 45
        return $traits;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $traits returns an array which contains values of type PhpParser\Node\Name which are incompatible with the documented value type PhUml\Code\Name.
Loading history...
47
    }
48
}
49