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; |
7
|
|
|
|
8
|
|
|
use PhpParser\Node\Name as ParsedName; |
|
|
|
|
9
|
|
|
use PhpParser\Node\Stmt\Class_; |
|
|
|
|
10
|
|
|
use PhpParser\Node\Stmt\Enum_; |
|
|
|
|
11
|
|
|
use PhpParser\Node\Stmt\GroupUse; |
|
|
|
|
12
|
|
|
use PhpParser\Node\Stmt\Interface_; |
|
|
|
|
13
|
|
|
use PhpParser\Node\Stmt\Trait_; |
|
|
|
|
14
|
|
|
use PhpParser\Node\Stmt\Use_; |
|
|
|
|
15
|
|
|
use PhpParser\Node\Stmt\UseUse; |
|
|
|
|
16
|
|
|
use PhUml\Code\Name; |
17
|
|
|
use PhUml\Code\UseStatement; |
18
|
|
|
use PhUml\Code\UseStatements; |
19
|
|
|
|
20
|
|
|
final class UseStatementsBuilder |
21
|
|
|
{ |
22
|
43 |
|
public function build(Class_|Interface_|Trait_|Enum_ $definition): UseStatements |
23
|
|
|
{ |
24
|
43 |
|
$uses = []; |
25
|
|
|
|
26
|
43 |
|
$previous = $definition->getAttribute('previous'); |
27
|
43 |
|
while ($previous instanceof Use_ || $previous instanceof GroupUse) { |
28
|
24 |
|
if ($previous instanceof Use_) { |
29
|
24 |
|
$uses[] = array_map(fn (UseUse $use): UseStatement => $this->fromUseStatement($use), $previous->uses); |
30
|
|
|
} else { |
31
|
3 |
|
$prefix = (string) $previous->prefix; |
32
|
3 |
|
$uses[] = array_map( |
33
|
3 |
|
fn (UseUse $use): UseStatement => $this->fromGroupedUse($use, $prefix), |
34
|
3 |
|
$previous->uses |
35
|
|
|
); |
36
|
|
|
} |
37
|
24 |
|
$previous = $previous->getAttribute('previous'); |
38
|
|
|
} |
39
|
|
|
|
40
|
43 |
|
return new UseStatements(array_merge(...$uses)); |
41
|
|
|
} |
42
|
|
|
|
43
|
24 |
|
private function fromUseStatement(UseUse $use): UseStatement |
44
|
|
|
{ |
45
|
24 |
|
$alias = null; |
46
|
24 |
|
if ($use->alias !== null) { |
47
|
2 |
|
$alias = new Name((string) $use->alias); |
48
|
|
|
} |
49
|
24 |
|
return new UseStatement(new Name((string) $use->name), $alias); |
50
|
|
|
} |
51
|
|
|
|
52
|
3 |
|
private function fromGroupedUse(UseUse $use, string $prefix): UseStatement |
53
|
|
|
{ |
54
|
3 |
|
$alias = null; |
55
|
3 |
|
if ($use->alias !== null) { |
56
|
1 |
|
$alias = new Name((string) $use->alias); |
57
|
|
|
} |
58
|
3 |
|
return new UseStatement(new Name((string) ParsedName::concat($prefix, $use->name)), $alias); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths