|
5 | 5 | namespace App\Storage; |
6 | 6 |
|
7 | 7 | use App\Clock; |
| 8 | +use App\Model\PhpRelease; |
8 | 9 | use App\Model\PhpVersion; |
9 | 10 | use App\Storage; |
10 | 11 | use Illuminate\Support\Collection; |
11 | 12 | use RuntimeException; |
12 | 13 | use Symfony\Component\Serializer\SerializerInterface; |
| 14 | +use function BenTools\IterableFunctions\iterable_to_array; |
13 | 15 |
|
14 | 16 | final class FilesystemStorage implements Storage |
15 | 17 | { |
@@ -49,43 +51,56 @@ public function write(iterable $versions, iterable $releases): void |
49 | 51 | HTML); |
50 | 52 | } |
51 | 53 |
|
| 54 | + /** |
| 55 | + * @param iterable<PhpVersion> $versions |
| 56 | + */ |
52 | 57 | private function writeAllVersionsFile(iterable $versions): void |
53 | 58 | { |
54 | | - $this->writeJson('all.json', $versions); |
| 59 | + $data = (new Collection($versions)) |
| 60 | + ->sort(static fn (PhpVersion $item1, PhpVersion $item2): int => -1 * version_compare($item1->getVersion(), $item2->getVersion())) |
| 61 | + ->values(); |
| 62 | + |
| 63 | + $this->writeJson('all.json', $data); |
55 | 64 | } |
56 | 65 |
|
57 | 66 | /** |
58 | 67 | * @param iterable<PhpVersion> $versions |
59 | 68 | */ |
60 | 69 | private function writeMaintenedVersions(iterable $versions): void |
61 | 70 | { |
62 | | - $data = (new Collection($versions))->filter( |
63 | | - fn (PhpVersion $version): bool => $version->getEndOfLife() > $this->clock->now(), |
64 | | - ); |
| 71 | + $data = (new Collection($versions)) |
| 72 | + ->filter(fn (PhpVersion $version): bool => $version->getEndOfLife() > $this->clock->now()) |
| 73 | + ->sort(static fn (PhpVersion $item1, PhpVersion $item2): int => -1 * version_compare($item1->getVersion(), $item2->getVersion())) |
| 74 | + ->values(); |
65 | 75 |
|
66 | 76 | $this->writeJson('maintened.json', $data); |
67 | 77 | } |
68 | 78 |
|
69 | 79 | private function writeUnmaintenedVersions(iterable $versions): void |
70 | 80 | { |
71 | | - $data = (new Collection($versions))->filter( |
72 | | - fn (PhpVersion $version): bool => $version->getEndOfLife() <= $this->clock->now(), |
73 | | - ); |
| 81 | + $data = (new Collection($versions)) |
| 82 | + ->filter(fn (PhpVersion $version): bool => $version->getEndOfLife() <= $this->clock->now()) |
| 83 | + ->sort(static fn (PhpVersion $a, PhpVersion $b): int => -1 * version_compare($a->getVersion(), $b->getVersion())) |
| 84 | + ->values(); |
74 | 85 |
|
75 | 86 | $this->writeJson('unmaintened.json', $data); |
76 | 87 | } |
77 | 88 |
|
78 | 89 | private function writeReleaseVersions(iterable $releases): void |
79 | 90 | { |
80 | | - $this->writeJson('releases.json', $releases); |
| 91 | + $data = (new Collection($releases)) |
| 92 | + ->sort(static fn (PhpRelease $a, PhpRelease $b): int => -1 * ($a->getReleaseDate() <=> $b->getReleaseDate())) |
| 93 | + ->values(); |
| 94 | + |
| 95 | + $this->writeJson('releases.json', $data); |
81 | 96 | } |
82 | 97 |
|
83 | 98 | private function writeJson(string $file, iterable $data): void |
84 | 99 | { |
85 | | - $this->writeContent($file, ['items' => $this->serializer->serialize($data, 'json')]); |
| 100 | + $this->writeContent($file, $this->serializer->serialize(['items' => $data], 'json')); |
86 | 101 | } |
87 | 102 |
|
88 | | - private function writeContent(string $file, iterable|string $data): void |
| 103 | + private function writeContent(string $file, string $data): void |
89 | 104 | { |
90 | 105 | $fullpath = rtrim($this->outputFolder, DIRECTORY_SEPARATOR).'/'.ltrim($file, DIRECTORY_SEPARATOR); |
91 | 106 |
|
|
0 commit comments