Commit 9bb8fb33 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(template) Adds a number modifier

This allows to use %n|% to add a number if needed for unicity.
Args are mandatory, start, step.
Default values for these are 0, 1, 1.

issue #5882
Showing with 26 additions and 0 deletions
+26 -0
...@@ -431,6 +431,28 @@ class templateHandling ...@@ -431,6 +431,28 @@ class templateHandling
return array($dateObject->format($args[1])); return array($dateObject->format($args[1]));
} }
private static function modifierNumber(array $args)
{
if (count($args) < 1) {
$args[] = FALSE;
}
if (count($args) < 2) {
$args[] = 1;
}
if (count($args) < 3) {
$args[] = 1;
}
$numberGenerator = function ($mandatory, $start, $step) {
  • :information_source: Remove the unused function parameter "$mandatory". :blue_book:

    By Ghost User on 2018-11-07T16:09:48 (imported from GitLab)

Please register or sign in to reply
$i = $start;
while (TRUE) {
yield $i;
$i += $step;
}
};
return $numberGenerator($args[0], $args[1], $args[2]);
}
/*! \brief Apply a modifier /*! \brief Apply a modifier
* *
* \param string $m the modifier * \param string $m the modifier
...@@ -533,6 +555,10 @@ class templateHandling ...@@ -533,6 +555,10 @@ class templateHandling
// date // date
$result = array(static::modifierDate($args)); $result = array(static::modifierDate($args));
break; break;
case 'n':
// number
$result = static::modifierNumber($args);
break;
default: default:
trigger_error("Unkown modifier '$m'"); trigger_error("Unkown modifier '$m'");
$result = array($str); $result = array($str);
......
  • SonarQube analysis reported 1 issue

    • :information_source: 1 info

    Watch the comments in this conversation to review them.

    By Ghost User on 2018-11-07T16:09:48 (imported from GitLab)

Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment