Browse Source

feat(filter): getBranchesFromState

merge-requests/13/head
JamesRezo 2 years ago
parent
commit
553c67789c
  1. 13
      CHANGELOG
  2. 1
      README.md
  3. 4
      data/releases.json
  4. 2
      modeles/supportedversions_compatibility.html
  5. 9
      modeles/supportedversions_eol.html
  6. 8
      modeles/supportedversions_stable.html
  7. 101
      supportedversions_fonctions.php
  8. 93
      tests/SupportedVersionsTest.php

13
CHANGELOG

@ -8,6 +8,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- `|SupportedVersions::getBranchesFromState` filter
### Changed
- `<supportedversions|eol>` model (one date column, no footnotes)
### Removed
- `|SupportedVersions::phpMatrixWithEol` filter
- `|SupportedVersions::eoledBranches` filter
## [0.4.1] - 2021-05-18
### Added

1
README.md

@ -22,6 +22,7 @@ SPIP Plugin backport of [PHP Supported Versions](http://php.net/supported-versio
## Filters
- `|SupportedVersions::getBranchValues` : Array of branch data for a given release string
- `|SupportedVersions::getBranchesFromState` Array of branch data for a given state sttring
## Other usage

4
data/releases.json

@ -142,8 +142,8 @@
"initial_release": "2002-12-14 21:50:42",
"active_support": "2003-05-26 18:52:51",
"eol": "2003-05-26 18:52:51",
"last_version_release": "",
"last_date_release": "",
"last_version_release": "1.5.2",
"last_date_release": "2003-02-01",
"php": [],
"releases": [{
"version": "1.5.2",

2
modeles/supportedversions_compatibility.html

@ -1,7 +1,7 @@
<B_compatibility>
<table class="spip supportedversions">
<thead>
<BOUCLE_compatibility_head(DATA){source table, #NULL|SupportedVersions::phpMatrixWithEol}{0,1}>
<BOUCLE_compatibility_head(DATA){source table, #VAL{true}|SupportedVersions::phpMatrix}{0,1}>
<tr>
<th>&nbsp;</th>
<th style="text-align: center;" colspan="[(#VALEUR|count)]"><:supportedversions:php_compatibility:></th>

9
modeles/supportedversions_eol.html

@ -3,23 +3,18 @@
<thead>
<tr>
<th><:supportedversions:branch:></th>
<th colspan="2"><:date:></th>
<th><:supportedversions:end_of_life:></th>
<th><:supportedversions:last_release:></th>
<th><:info_notes:></th>
</tr>
</thead>
<tbody>
<BOUCLE_eol_branches(DATA){source table, #NULL|SupportedVersions::eoledBranches}{par branch}{inverse}>
<BOUCLE_eol_branches(DATA){source table, #VAL{eol}|SupportedVersions::getBranchesFromState}{par branch}{inverse}>
<tr>
<td>#BRANCH</td>
<td>
[(#EOL|affdate)]
</td>
<td>
[(#EOL|date_relative)]
</td>
<td>#LAST_VERSION_RELEASE</td>
<td>&nbsp;</td>
</tr>
</BOUCLE_eol_branches>
</tbody>

8
modeles/supportedversions_stable.html

@ -12,10 +12,10 @@
Rien : <supportedversions|stable>
]
<BOUCLE_stable(DATA){source table, #NULL|SupportedVersions::branchesToShow}>
[(#VALEUR|SupportedVersions::state|=={stable}|et{#ENV{info}|strstr{version}})#LAST_VERSION_RELEASE]
[(#VALEUR|SupportedVersions::state|=={stable}|et{#ENV{info}|strstr{date}})[(#LAST_DATE_RELEASE|affdate)]]
<BOUCLE_url(CONDITION){si #VALEUR|SupportedVersions::state|=={stable}|et{#ENV{info}|strstr{url}}}>
<BOUCLE_stable(DATA){source table, #VAL{stable}|SupportedVersions::getBranchesFromState}{par last_date_release}{inverse}{0,1}>
[(#ENV{info}|strstr{version}|oui)#LAST_VERSION_RELEASE]
[(#ENV{info}|strstr{date}|oui)[(#LAST_DATE_RELEASE|affdate)]]
<BOUCLE_url(CONDITION){si #ENV{info}|strstr{url}}>
<BOUCLE_releases(DATA){source table, #RELEASES}{version=#LAST_VERSION_RELEASE}{0,1}>
<BOUCLE_download(DATA){source table, #DOWNLOAD}>#URL</BOUCLE_download>
</BOUCLE_releases>

101
supportedversions_fonctions.php

@ -212,32 +212,6 @@ class SupportedVersions
);
}
/**
* Filtre sélectionnant les données des branches en fin de vie.
*
* @return array<mixed> les branches en fin de vie à afficher
*/
public static function eoledBranches() {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$now = self::$now->format('Y-m-d');
return array_reduce(
self::$releases,
function ($branches, $release) use ($now) {
if ($release['eol'] != '' && $release['eol'] <= $now) {
$branches[] = $release;
}
return $branches;
},
[]
);
}
/**
* Filtre fournissant un tableau de compatibilité SPIP/PHP.
*
@ -290,15 +264,7 @@ class SupportedVersions
}
/**
* @codeCoverageIgnore
* @return array<mixed>
*/
public static function phpMatrixWithEol() {
return self::phpMatrix(true);
}
/**
* Filtre fournissant les informations de la branche liée à la release passée en parramètre.
* Filtre fournissant les informations de la branche liée à la release passée en paramètre.
*
* - Si le paramètre ne correspond pas à un nommage de branch X.Y
* ou si la branche X.Y n'existe pas :
@ -337,6 +303,71 @@ class SupportedVersions
return $values;
}
/**
* Filtre fournissant les branches correspondant à un état de publication donné.
*
* l'état de publication doit correspondre à l'un des termes suivants:
* future, stable, security, eol.
* @see state()
*
* @param string $state l'état de publication souhaité
* @return array<mixed>
*/
public static function getBranchesFromState(string $state): array {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$notPlannedBranch = [
'branch' => '',
'initial_release' => '',
'active_support' => '',
'eol' => '',
'php' => [],
'releases' => [],
];
$callable = function ($values) {
return false;
};
if ('future' === $state) {
$callable = function ($values) {
$initial = $values['initial_release'] ? new DateTime($values['initial_release']) : null;
return $initial && $initial > self::$now;
};
}
if ('stable' === $state) {
$callable = function ($values) {
$initial = $values['initial_release'] ? new DateTime($values['initial_release']) : null;
$bug = $values['active_support'] ? new DateTime($values['active_support']) : null;
return $initial && $initial <= self::$now && (!$bug || $bug >= self::$now);
};
}
if ('security' === $state) {
$callable = function ($values) {
$bug = $values['active_support'] ? new DateTime($values['active_support']) : null;
$security = $values['eol'] ? new DateTime($values['eol']) : null;
return $bug && $bug <= self::$now && (!$security || $security >= self::$now);
};
}
if ('eol' === $state) {
$callable = function ($values) {
$security = $values['eol'] ? new DateTime($values['eol']) : null;
return $security && $security < self::$now;
};
}
$filteredBranches = array_filter(self::$releases, $callable);
return empty($filteredBranches) ? [$notPlannedBranch] : array_values($filteredBranches);
}
//Calendar Part
/**

93
tests/SupportedVersionsTest.php

@ -180,48 +180,6 @@ class SupportedVersionsTest extends TestCase
));
}
public function dataSupportedVersionsEoledBranches()
{
return [
'date-courante' => [
['0.1', '0.8', '1.0'],
'',
],
'plus-tard' => [
['0.1', '0.8', '1.0', '1.1', '4.1'],
'1972-03-01',
],
];
}
/**
* @group criteres
* @dataProvider dataSupportedVersionsEoledBranches
*
* @param array $expected
* @param string $now
* @return void
*/
public function testSupportedVersionsEoledBranches($expected, $now)
{
//Given
SupportedVersions::setConfig($this->calendarConfig, $now ? $now : $this->now);
//When
$branches = SupportedVersions::eoledBranches();
//Then
$this->assertEquals($expected, array_reduce(
$branches,
function ($branchNames, $branch) {
$branchNames[] = $branch['branch'];
return $branchNames;
},
[]
));
}
public function dataPhpMatrix()
{
return [
@ -328,6 +286,57 @@ class SupportedVersionsTest extends TestCase
$this->assertEquals($expected, $values);
}
public function dataGetBranchesFromState()
{
return [
'randomstring' => [
[''],
'randomstring',
],
'future' => [
['3.0', '4.0', '4.1'],
'future',
],
'stable' => [
['0.1', '0.9', '2.0', '2.1'],
'stable',
],
'security' => [
['1.1'],
'security',
],
'eol' => [
['0.1', '0.8', '1.0'],
'eol',
],
];
}
/**
* @group filtres
* @dataProvider dataGetBranchesFromState
*/
public function testGetBranchesFromState($expected, $state)
{
//Given
SupportedVersions::setConfig(
$this->calendarConfig,
$this->now,
);
//When
$branches = SupportedVersions::getBranchesFromState($state);
$branches = array_reduce($branches, function ($branchNames, $branch) {
$branchNames[] = $branch['branch'];
return $branchNames;
},[]);
//Then
$this->assertEquals($expected, $branches);
}
public function dataSupportedVersionsStateOrGradient()
{
return [

Loading…
Cancel
Save