|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Koriym\AppStateDiagram; |
|
6
|
|
|
|
|
7
|
|
|
use Koriym\AppStateDiagram\Exception\InvalidDescriptorMissingIdOrHrefException; |
|
8
|
|
|
use stdClass; |
|
9
|
|
|
|
|
10
|
|
|
use function array_key_exists; |
|
11
|
|
|
use function assert; |
|
12
|
|
|
use function explode; |
|
13
|
|
|
use function in_array; |
|
14
|
|
|
use function is_string; |
|
15
|
|
|
use function json_encode; |
|
16
|
|
|
use function substr; |
|
17
|
|
|
|
|
18
|
|
|
final class TaggedProfile extends AbstractProfile |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var array<string, AbstractDescriptor> */ |
|
21
|
|
|
private $tranceDescriptor; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param list<string> $orTags |
|
|
|
|
|
|
25
|
|
|
* @param list<string> $andTags |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(AbstractProfile $alpsFile, array $orTags, array $andTags) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->title = $alpsFile->title; |
|
30
|
|
|
$this->doc = $alpsFile->doc; |
|
31
|
|
|
$this->scanLinks($alpsFile, $andTags, $orTags); |
|
32
|
|
|
$this->scanDescriptors($alpsFile); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param list<string> $andTags |
|
37
|
|
|
* @param list<string> $orTags |
|
38
|
|
|
*/ |
|
39
|
|
|
private function scanLinks(AbstractProfile $alpsFile, array $andTags, array $orTags): void |
|
40
|
|
|
{ |
|
41
|
|
|
$links = new Links(); |
|
42
|
|
|
$transDescriptors = new Descriptors(); |
|
43
|
|
|
foreach ($alpsFile->links as $link) { |
|
44
|
|
|
if ( |
|
45
|
|
|
$this->isFilteredAnd($link->transDescriptor, $andTags) |
|
46
|
|
|
|| $this->isFilteredOr($link->transDescriptor, $orTags) |
|
47
|
|
|
) { |
|
48
|
|
|
$links->add($link); |
|
49
|
|
|
$transDescriptors->add($link->transDescriptor); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$this->links = $links->links; |
|
54
|
|
|
$this->tranceDescriptor = $transDescriptors->descriptors; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function scanDescriptors(AbstractProfile $alpsFile): void |
|
58
|
|
|
{ |
|
59
|
|
|
$descriptors = new Descriptors(); |
|
60
|
|
|
foreach ($this->links as $link) { |
|
61
|
|
|
$descriptors->add($link->transDescriptor); |
|
62
|
|
|
$from = $this->filteredDescriptor( |
|
63
|
|
|
$alpsFile->descriptors[$link->from], |
|
64
|
|
|
$alpsFile->descriptors |
|
65
|
|
|
); |
|
66
|
|
|
foreach ($from->descriptors as $descriptor) { |
|
67
|
|
|
$descriptors->add($descriptor); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$to = $this->filteredDescriptor( |
|
71
|
|
|
$alpsFile->descriptors[$link->to], |
|
72
|
|
|
$alpsFile->descriptors |
|
73
|
|
|
); |
|
74
|
|
|
foreach ($to->descriptors as $descriptor) { |
|
75
|
|
|
$descriptors->add($descriptor); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$this->descriptors = $descriptors->descriptors; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** @param list<string> $andTags */ |
|
83
|
|
|
private function isFilteredAnd(AbstractDescriptor $descriptor, array $andTags): bool |
|
84
|
|
|
{ |
|
85
|
|
|
if ($andTags === []) { |
|
86
|
|
|
return false; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
foreach ($andTags as $tag) { |
|
90
|
|
|
if (! in_array($tag, $descriptor->tags, true)) { |
|
|
|
|
|
|
91
|
|
|
return false; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return true; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** @param list<string> $orTags */ |
|
99
|
|
|
private function isFilteredOr(AbstractDescriptor $descriptor, array $orTags): bool |
|
100
|
|
|
{ |
|
101
|
|
|
if ($orTags === []) { |
|
102
|
|
|
return false; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
foreach ($orTags as $tag) { |
|
106
|
|
|
if (in_array($tag, $descriptor->tags, true)) { |
|
|
|
|
|
|
107
|
|
|
return true; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return false; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
private function getDescriptorId(stdClass $child): string |
|
115
|
|
|
{ |
|
116
|
|
|
if (isset($child->id) && is_string($child->id)) { |
|
117
|
|
|
return $child->id; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$href = $child->href; |
|
121
|
|
|
if (! isset($href)) { |
|
122
|
|
|
throw new InvalidDescriptorMissingIdOrHrefException((string) json_encode($child)); // @codeCoverageIgnore |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
assert(is_string($href)); |
|
126
|
|
|
|
|
127
|
|
|
$isInternal = $href[0] === '#'; |
|
128
|
|
|
|
|
129
|
|
|
if ($isInternal) { |
|
130
|
|
|
return substr($href, 1); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return explode('#', $href)[1]; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** @param array<AbstractDescriptor> $allDescriptors */ |
|
137
|
|
|
private function filteredDescriptor(AbstractDescriptor $edge, array $allDescriptors): Descriptors |
|
138
|
|
|
{ |
|
139
|
|
|
$descriptors = new Descriptors(); |
|
140
|
|
|
$filteredChildren = []; |
|
141
|
|
|
|
|
142
|
|
|
foreach ($edge->descriptor as $child) { |
|
143
|
|
|
$descriptor = $allDescriptors[$this->getDescriptorId($child)]; |
|
144
|
|
|
if ($this->validDescriptor($descriptor)) { |
|
145
|
|
|
$filteredChildren[] = $child; |
|
146
|
|
|
$descriptors->add($descriptor); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
$edge->descriptor = $filteredChildren; |
|
|
|
|
|
|
151
|
|
|
$descriptors->add($edge); |
|
152
|
|
|
|
|
153
|
|
|
return $descriptors; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
private function validDescriptor(AbstractDescriptor $descriptor): bool |
|
157
|
|
|
{ |
|
158
|
|
|
if ($descriptor instanceof SemanticDescriptor) { |
|
159
|
|
|
return true; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return $descriptor instanceof TransDescriptor && array_key_exists($descriptor->id, $this->tranceDescriptor); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
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