Browse Source

Une passe de phpcs --standard=SPIP41

dev/lister_versions
bricebou 7 months ago
parent
commit
ee42e3d020
  1. 54
      src/Command/CoreListerVersions.php

54
src/Command/CoreListerVersions.php

@ -11,8 +11,8 @@ use Symfony\Component\Console\Output\OutputInterface;
class CoreListerVersions extends Command {
private $spip_git_repo = 'https://git.spip.net/spip/spip.git';
private $versions = [];
private $lastXY = '';
private $prevXY = '';
private $last_xy = '';
private $prev_xy = '';
protected function configure() {
$this
@ -25,9 +25,7 @@ class CoreListerVersions extends Command {
'tags ou branches ?',
'tags' // Par défaut, tout
)
->setAliases(array(
'versions'
))
->setAliases(['versions'])
;
}
@ -45,15 +43,15 @@ class CoreListerVersions extends Command {
$type = $input->getOption('type');
if (!function_exists('passthru')) {
$output->writeln("<error>Votre installation de PHP doit pouvoir exécuter des commandes externes avec la fonction passthru().</error>");
$output->writeln('<error>Votre installation de PHP doit pouvoir exécuter des commandes externes avec la fonction passthru().</error>');
return Command::FAILURE;
}
else{
else {
if (!is_dir('.git')) {
$this->git_init();
$this->gitInit();
}
$this->versions = $this->lister_versions($type);
$this->versions = $this->listerVersions($type);
foreach ($this->versions as $key => $value) {
$output->writeln($value);
}
@ -62,13 +60,13 @@ class CoreListerVersions extends Command {
// 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') {
$versionsXYZ = preg_grep('/^\d+.\d+/', $this->versions);
$this->lastXY = end($versionsXYZ);
$this->prevXY = $this->trouver_version_precedente(end($versionsXYZ));
$versions_xyz = preg_grep('/^\d+.\d+/', $this->versions);
$this->last_xy = end($versions_xyz);
$this->prev_xy = $this->trouverVersionPrecedente(end($versions_xyz));
}
else {
$this->lastXY = preg_replace('/^(\d+.\d+).\d+/', '${1}', end($this->versions));
$this->prevXY = preg_replace('/^(\d+.\d+).\d+/', '${1}',$this->trouver_version_precedente(end($this->versions)));
$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)));
}
}
@ -76,7 +74,7 @@ class CoreListerVersions extends Command {
}
/**
* git_init
* gitInit
*
* Initialisation d'un dépôt GIT vierge auquel on déclare le dépôt distant
* du core de spip afin de pouvoir ensuite appeler `git ls-remote origin`
@ -84,7 +82,7 @@ class CoreListerVersions extends Command {
*
* @return void
*/
public function git_init() {
public function gitInit() {
ob_start();
passthru('git init');
passthru('git remote add origin ' . $this->spip_git_repo);
@ -92,12 +90,12 @@ class CoreListerVersions extends Command {
}
/**
* lister_versions
* listerVersions
*
* @param mixed $type
* @return array $liste
*/
public function lister_versions(string $type) {
public function listerVersions(string $type) {
$liste = [];
if ($type == 'tags') {
ob_start();
@ -127,30 +125,30 @@ class CoreListerVersions extends Command {
}
/**
* trouver_version_precedente
* trouverVersionPrecedente
*
* @param mixed $version
* @return string $prevVersion
* @return string $prev_version
*/
public function trouver_version_precedente($version) {
public function trouverVersionPrecedente($version) {
$versions = $this->versions;
if ($key = array_search($version, $versions)) {
if (preg_match('/^\d+.\d+/', $versions[$key]) && array_key_exists($key - 1, $versions)) {
$key -= 1;
$prevVersion = $versions[$key];
$prev_version = $versions[$key];
preg_match('/\d+.\d+/', $version, $versionXY);
preg_match('/\d+.\d+/', $prevVersion, $prevVersionXY);
preg_match('/\d+.\d+/', $version, $version_xy);
preg_match('/\d+.\d+/', $prev_version, $prev_version_xy);
while ($versionXY[0] == $prevVersionXY[0]) {
$prevVersion = $versions[$key];
preg_match('/\d+.\d+/', $prevVersion, $prevVersionXY);
while ($version_xy[0] == $prev_version_xy[0]) {
$prev_version = $versions[$key];
preg_match('/\d+.\d+/', $prev_version, $prev_version_xy);
$key -= 1;
}
return $prevVersion;
return $prev_version;
}
}
}

Loading…
Cancel
Save