Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit 5a074ba

Browse files
committed
Sort output files data
1 parent 50cb6dc commit 5a074ba

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"ext-ctype": "*",
77
"ext-iconv": "*",
88
"ext-pdo": "*",
9+
"bentools/iterable-functions": "^2.1",
910
"illuminate/collections": "^9.13",
1011
"symfony/console": "6.2.*",
1112
"symfony/css-selector": "6.2.*",

composer.lock

Lines changed: 48 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PhpVersionFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function eol(): iterable
7676

7777
$version = $cols->eq(0)->text();
7878
$endOfLife = $this->extractDate($cols->eq(1)->text());
79-
$lastRelease = $cols->eq(3)->text();
79+
$lastRelease = $cols->eq(2)->text();
8080

8181
$initialVersion = "3.0" !== $version ? "$version.0" : "$version.x";
8282

src/Storage/FilesystemStorage.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
namespace App\Storage;
66

77
use App\Clock;
8+
use App\Model\PhpRelease;
89
use App\Model\PhpVersion;
910
use App\Storage;
1011
use Illuminate\Support\Collection;
1112
use RuntimeException;
1213
use Symfony\Component\Serializer\SerializerInterface;
14+
use function BenTools\IterableFunctions\iterable_to_array;
1315

1416
final class FilesystemStorage implements Storage
1517
{
@@ -49,43 +51,56 @@ public function write(iterable $versions, iterable $releases): void
4951
HTML);
5052
}
5153

54+
/**
55+
* @param iterable<PhpVersion> $versions
56+
*/
5257
private function writeAllVersionsFile(iterable $versions): void
5358
{
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);
5564
}
5665

5766
/**
5867
* @param iterable<PhpVersion> $versions
5968
*/
6069
private function writeMaintenedVersions(iterable $versions): void
6170
{
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();
6575

6676
$this->writeJson('maintened.json', $data);
6777
}
6878

6979
private function writeUnmaintenedVersions(iterable $versions): void
7080
{
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();
7485

7586
$this->writeJson('unmaintened.json', $data);
7687
}
7788

7889
private function writeReleaseVersions(iterable $releases): void
7990
{
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);
8196
}
8297

8398
private function writeJson(string $file, iterable $data): void
8499
{
85-
$this->writeContent($file, ['items' => $this->serializer->serialize($data, 'json')]);
100+
$this->writeContent($file, $this->serializer->serialize(['items' => $data], 'json'));
86101
}
87102

88-
private function writeContent(string $file, iterable|string $data): void
103+
private function writeContent(string $file, string $data): void
89104
{
90105
$fullpath = rtrim($this->outputFolder, DIRECTORY_SEPARATOR).'/'.ltrim($file, DIRECTORY_SEPARATOR);
91106

0 commit comments

Comments
 (0)