From 692a0fe3d3d62d06bb609712744bc7d46a44d2e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Mon, 7 Jul 2025 12:59:03 +0200 Subject: [PATCH] feat: read supported versions from composer.json --- bin/devkit.php | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/devkit.php b/bin/devkit.php index 8201017e..ea466fae 100755 --- a/bin/devkit.php +++ b/bin/devkit.php @@ -69,21 +69,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int $jsonPath = $input->getOption('tools'); $readmePath = $input->getOption('readme'); $tools = $this->loadTools($jsonPath); + + $composerJson = \Safe\json_decode(file_get_contents(__DIR__ . '/../composer.json'), true); + if (!isset($composerJson['require']['php']) || preg_match_all('/~(\d+\.\d+)\.0/', $composerJson['require']['php'], $matches) === 0) { + $output->writeln('Invalid or missing PHP version in composer.json'); + return 1; + } + $versions = $matches[1]; - $toolsList = '| Name | Description | PHP 8.2 | PHP 8.3 | PHP 8.4 |' . PHP_EOL; - $toolsList .= '| :--- | :---------- | :------ | :------ | :------ |' . PHP_EOL; + $toolsList = '| Name | Description | '. implode(' ', array_map(fn($v) => sprintf('PHP %s |', $v), $versions)) . PHP_EOL; + $toolsList .= '| :--- | :---------- | '. implode(' ', array_fill(0, count($versions), ':------ |')) . PHP_EOL; $toolsList .= $tools->sort(function (Tool $left, Tool $right) { return strcasecmp($left->name(), $right->name()); - })->reduce('', function ($acc, Tool $tool) { - - return $acc . sprintf('| %s | [%s](%s) | %s | %s | %s |', - $tool->name(), - $tool->summary(), - $tool->website(), - in_array('exclude-php:8.2', $tool->tags(), true) ? '❌' : '✅', - in_array('exclude-php:8.3', $tool->tags(), true) ? '❌' : '✅', - in_array('exclude-php:8.4', $tool->tags(), true) ? '❌' : '✅', - ) . PHP_EOL; + })->reduce('', function ($acc, Tool $tool) use ($versions) { + + $args = [ + $tool->name(), + $tool->summary(), + $tool->website(), + ]; + foreach ($versions as $version) { + $args[] = in_array(sprintf('exclude-php:%s', $version), $tool->tags(), true) ? '❌' : '✅'; + } + + return $acc . vsprintf('| %s | [%s](%s) | '. implode(' ', array_fill(0, count($versions), '%s |')), $args) . PHP_EOL; }); $readme = file_get_contents($readmePath);