diff --git a/src/Command/CoreListerVersions.php b/src/Command/CoreListerVersions.php index d3954bf..b3ba021 100644 --- a/src/Command/CoreListerVersions.php +++ b/src/Command/CoreListerVersions.php @@ -3,16 +3,12 @@ namespace Spip\Cli\Command; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class CoreListerVersions extends Command { public const _SPIP_GIT_REPO = 'https://git.spip.net/spip/spip.git'; - private $versions = []; - private $last_xy = ''; - private $prev_xy = ''; protected function configure() { $this @@ -22,8 +18,8 @@ class CoreListerVersions extends Command { 'type', 't', InputOption::VALUE_OPTIONAL, - 'tags ou branches ?', - 'tags' // Par défaut, les tags + 'branches ou tags ?', + 'branches' // Par défaut, les tags ) ->setAliases(['versions']) ; @@ -47,23 +43,10 @@ class CoreListerVersions extends Command { return Command::FAILURE; } else { - $this->versions = $this->listerVersions($type); - foreach ($this->versions as $key => $value) { + $versions = $this->listerVersions($type); + foreach ($versions as $key => $value) { $output->writeln($value); } - - // On fait en sorte de renvoyer au même format X.Y les dernière - // et avant-dernière versions que ce soit des branches ou des tags - // Utilisable tel quel ensuite pour gérer la compat des plugins - if ($type == 'branches') { - $versions_xyz = preg_grep('/^\d+.\d+/', $this->versions); - $this->last_xy = end($versions_xyz); - $this->prev_xy = $this->trouverVersionPrecedente(end($versions_xyz)); - } - else { - $this->last_xy = preg_replace('/^(\d+.\d+).\d+/', '${1}', end($this->versions)); - $this->prev_xy = preg_replace('/^(\d+.\d+).\d+/', '${1}', $this->trouverVersionPrecedente(end($this->versions))); - } } return Command::SUCCESS; @@ -75,8 +58,10 @@ class CoreListerVersions extends Command { * @param mixed $type * @return array $liste */ - public function listerVersions(string $type) { - $liste = []; + + public static function listerVersions(string $type = 'branches') { + $liste = []; + if ($type == 'tags') { ob_start(); passthru('git ls-remote --tags ' . self::_SPIP_GIT_REPO); @@ -91,7 +76,7 @@ class CoreListerVersions extends Command { if ($type == 'branches') { ob_start(); - passthru('git ls-remote --heads origin'); + passthru('git ls-remote --heads ' . self::_SPIP_GIT_REPO); $branches = ob_get_contents(); ob_end_clean(); @@ -107,19 +92,18 @@ class CoreListerVersions extends Command { /** * trouverVersionPrecedente * - * @param mixed $version - * @return string $prev_version + * @param array $versions + * @param string $version_installee + * @return string $prev_version */ - public function trouverVersionPrecedente($version) { - - $versions = $this->versions; + public static function trouverVersionPrecedente(array $versions, string $version_installee) { - if ($key = array_search($version, $versions)) { + if ($key = array_search($version_installee, $versions)) { if (preg_match('/^\d+.\d+/', $versions[$key]) && array_key_exists($key - 1, $versions)) { $key -= 1; $prev_version = $versions[$key]; - preg_match('/\d+.\d+/', $version, $version_xy); + preg_match('/\d+.\d+/', $version_installee, $version_xy); preg_match('/\d+.\d+/', $prev_version, $prev_version_xy); while ($version_xy[0] == $prev_version_xy[0]) {