TraitNamesBuilder::buildTraits()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Parser\Code\Builders\Names;
7
8
use PhpParser\Node;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use PhpParser\Node\Stmt\TraitUse;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\Stmt\TraitUse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use PhUml\Code\Name as TraitName;
11
12
trait TraitNamesBuilder
13
{
14
    /**
15
     * @param Node[] $nodes
16
     * @return TraitName[]
17
     */
18 35
    private function buildTraits(array $nodes): array
19
    {
20 35
        $useStatements = array_filter($nodes, static fn (Node $node): bool => $node instanceof TraitUse);
21
22 35
        $traits = [];
23
        /** @var TraitUse $use */
24 35
        foreach ($useStatements as $use) {
25 23
            $traits = $this->traitNames($use, $traits);
26
        }
27
28 35
        return $traits;
29
    }
30
31
    /**
32
     * @param TraitName[] $traits
33
     * @return TraitName[]
34
     */
35 23
    private function traitNames(TraitUse $use, array $traits): array
36
    {
37 23
        foreach ($use->traits as $name) {
38 23
            $traits[] = new TraitName((string) $name);
39
        }
40 23
        return $traits;
41
    }
42
}
43