|
8 | 8 | use Composer\Pcre\Preg; |
9 | 9 | use Doctrine\Common\Collections\ArrayCollection; |
10 | 10 | use Doctrine\Common\Collections\Collection; |
| 11 | +use Doctrine\Common\Collections\Criteria; |
| 12 | +use Doctrine\Common\Collections\Order; |
| 13 | +use Doctrine\Common\Collections\Selectable; |
11 | 14 | use Doctrine\DBAL\Types\Types; |
12 | 15 | use Doctrine\ORM\Mapping as ORM; |
13 | 16 |
|
@@ -98,49 +101,43 @@ class Metadata extends TrackedEntity implements \Stringable |
98 | 101 | private Package $package; |
99 | 102 |
|
100 | 103 | /** |
101 | | - * @var Collection<int, MetadataRequireLink> |
| 104 | + * @var Collection<int, MetadataRequireLink>&Selectable |
102 | 105 | */ |
103 | 106 | #[ORM\OneToMany(targetEntity: MetadataRequireLink::class, mappedBy: 'metadata', cascade: ['persist', 'detach'])] |
104 | | - #[ORM\OrderBy(['index' => 'ASC'])] |
105 | 107 | private Collection $requireLinks; |
106 | 108 |
|
107 | 109 | /** |
108 | | - * @var Collection<int, MetadataDevRequireLink> |
| 110 | + * @var Collection<int, MetadataDevRequireLink>&Selectable |
109 | 111 | */ |
110 | 112 | #[ORM\OneToMany(targetEntity: MetadataDevRequireLink::class, mappedBy: 'metadata', cascade: ['persist', 'detach'])] |
111 | | - #[ORM\OrderBy(['index' => 'ASC'])] |
112 | 113 | private Collection $devRequireLinks; |
113 | 114 |
|
114 | 115 | /** |
115 | | - * @var Collection<int, MetadataConflictLink> |
| 116 | + * @var Collection<int, MetadataConflictLink>&Selectable |
116 | 117 | */ |
117 | 118 | #[ORM\OneToMany(targetEntity: MetadataConflictLink::class, mappedBy: 'metadata', cascade: ['persist', 'detach'])] |
118 | | - #[ORM\OrderBy(['index' => 'ASC'])] |
119 | 119 | private Collection $conflictLinks; |
120 | 120 |
|
121 | 121 | /** |
122 | | - * @var Collection<int, MetadataProvideLink> |
| 122 | + * @var Collection<int, MetadataProvideLink>&Selectable |
123 | 123 | */ |
124 | 124 | #[ORM\OneToMany(targetEntity: MetadataProvideLink::class, mappedBy: 'metadata', cascade: ['persist', 'detach'])] |
125 | | - #[ORM\OrderBy(['index' => 'ASC'])] |
126 | 125 | private Collection $provideLinks; |
127 | 126 |
|
128 | 127 | /** |
129 | | - * @var Collection<int, MetadataReplaceLink> |
| 128 | + * @var Collection<int, MetadataReplaceLink>&Selectable |
130 | 129 | */ |
131 | 130 | #[ORM\OneToMany(targetEntity: MetadataReplaceLink::class, mappedBy: 'metadata', cascade: ['persist', 'detach'])] |
132 | | - #[ORM\OrderBy(['index' => 'ASC'])] |
133 | 131 | private Collection $replaceLinks; |
134 | 132 |
|
135 | 133 | /** |
136 | | - * @var Collection<int, MetadataSuggestLink> |
| 134 | + * @var Collection<int, MetadataSuggestLink>&Selectable |
137 | 135 | */ |
138 | 136 | #[ORM\OneToMany(targetEntity: MetadataSuggestLink::class, mappedBy: 'metadata', cascade: ['persist', 'detach'])] |
139 | | - #[ORM\OrderBy(['index' => 'ASC'])] |
140 | 137 | private Collection $suggestLinks; |
141 | 138 |
|
142 | 139 | /** |
143 | | - * @var Collection<int, MetadataKeyword> |
| 140 | + * @var Collection<int, MetadataKeyword>&Selectable |
144 | 141 | */ |
145 | 142 | #[ORM\OneToMany(mappedBy: 'metadata', targetEntity: MetadataKeyword::class, cascade: ['persist', 'detach'])] |
146 | 143 | private Collection $keywords; |
@@ -418,55 +415,55 @@ public function getPackage(): Package |
418 | 415 | */ |
419 | 416 | public function getRequireLinks(): Collection |
420 | 417 | { |
421 | | - return $this->requireLinks; |
| 418 | + return self::getOrderedCollection($this->requireLinks); |
422 | 419 | } |
423 | 420 |
|
424 | 421 | /** |
425 | 422 | * @return Collection<int, MetadataDevRequireLink> |
426 | 423 | */ |
427 | 424 | public function getDevRequireLinks(): Collection |
428 | 425 | { |
429 | | - return $this->devRequireLinks; |
| 426 | + return self::getOrderedCollection($this->devRequireLinks); |
430 | 427 | } |
431 | 428 |
|
432 | 429 | /** |
433 | 430 | * @return Collection<int, MetadataConflictLink> |
434 | 431 | */ |
435 | 432 | public function getConflictLinks(): Collection |
436 | 433 | { |
437 | | - return $this->conflictLinks; |
| 434 | + return self::getOrderedCollection($this->conflictLinks); |
438 | 435 | } |
439 | 436 |
|
440 | 437 | /** |
441 | 438 | * @return Collection<int, MetadataProvideLink> |
442 | 439 | */ |
443 | 440 | public function getProvideLinks(): Collection |
444 | 441 | { |
445 | | - return $this->provideLinks; |
| 442 | + return self::getOrderedCollection($this->provideLinks); |
446 | 443 | } |
447 | 444 |
|
448 | 445 | /** |
449 | 446 | * @return Collection<int, MetadataReplaceLink> |
450 | 447 | */ |
451 | 448 | public function getReplaceLinks(): Collection |
452 | 449 | { |
453 | | - return $this->replaceLinks; |
| 450 | + return self::getOrderedCollection($this->replaceLinks); |
454 | 451 | } |
455 | 452 |
|
456 | 453 | /** |
457 | 454 | * @return Collection<int, MetadataSuggestLink> |
458 | 455 | */ |
459 | 456 | public function getSuggestLinks(): Collection |
460 | 457 | { |
461 | | - return $this->suggestLinks; |
| 458 | + return self::getOrderedCollection($this->suggestLinks); |
462 | 459 | } |
463 | 460 |
|
464 | 461 | /** |
465 | 462 | * @return Collection<int, MetadataKeyword> |
466 | 463 | */ |
467 | 464 | public function getKeywords(): Collection |
468 | 465 | { |
469 | | - return $this->keywords; |
| 466 | + return self::getOrderedCollection($this->keywords); |
470 | 467 | } |
471 | 468 |
|
472 | 469 | public function hasSource(): bool |
@@ -675,4 +672,15 @@ public function toComposerArray(): array |
675 | 672 |
|
676 | 673 | return $data; |
677 | 674 | } |
| 675 | + |
| 676 | + private static function getOrderedCollection(Collection&Selectable $collection): Collection |
| 677 | + { |
| 678 | + static $criteria = Criteria::create() |
| 679 | + ->orderBy(['index' => Order::Ascending]); |
| 680 | + |
| 681 | + /** @var Collection $collection */ |
| 682 | + $collection = $collection->matching($criteria); |
| 683 | + |
| 684 | + return $collection; |
| 685 | + } |
678 | 686 | } |
0 commit comments