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