1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Koriym\AppStateDiagram; |
||
6 | |||
7 | use stdClass; |
||
8 | |||
9 | use function implode; |
||
10 | use function is_array; |
||
11 | use function strtoupper; |
||
12 | use function usort; |
||
13 | |||
14 | use const PHP_EOL; |
||
15 | |||
16 | final class LinkRelations |
||
17 | { |
||
18 | /** @var list<LinkRelation> */ |
||
19 | private $links; |
||
20 | |||
21 | /** @param list<stdClass>|stdClass|null $link */ |
||
22 | public function __construct($link = null) |
||
23 | { |
||
24 | if ($link === null) { |
||
25 | $this->links = []; |
||
0 ignored issues
–
show
|
|||
26 | |||
27 | return; |
||
28 | } |
||
29 | |||
30 | if (is_array($link)) { |
||
31 | $this->links = $this->createLinkRelations($link); |
||
32 | |||
33 | return; |
||
34 | } |
||
35 | |||
36 | $this->links = [new LinkRelation($link)]; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param list<stdClass> $links |
||
41 | * |
||
42 | * @return list<LinkRelation> |
||
43 | */ |
||
44 | private function createLinkRelations(array $links): array |
||
45 | { |
||
46 | $linkRelations = []; |
||
47 | foreach ($links as $link) { |
||
48 | $linkRelations[] = new LinkRelation($link); |
||
49 | } |
||
50 | |||
51 | usort($linkRelations, static function (LinkRelation $a, LinkRelation $b): int { |
||
52 | return strtoupper($a->rel) <=> strtoupper($b->rel); |
||
53 | }); |
||
54 | |||
55 | return $linkRelations; |
||
56 | } |
||
57 | |||
58 | public function __toString(): string |
||
59 | { |
||
60 | return implode(PHP_EOL, $this->links); |
||
61 | } |
||
62 | } |
||
63 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..