Skip to content

Commit

Permalink
Merge branch '2.x' into 3.x
Browse files Browse the repository at this point in the history
* 2.x:
  Rename variables used in map method
  The deprecated null value for the method round has been changed to zero.
  • Loading branch information
fabpot committed Jan 14, 2022
2 parents 93d26f9 + 9984a6e commit 5981815
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/filters/map.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The arrow function also receives the key as a second argument:
"Alice": "Dupond",
} %}
{{ people|map((last, first) => "#{first} #{last}")|join(', ') }}
{{ people|map((value, key) => "#{value} #{key}")|join(', ') }}
{# outputs Bob Smith, Alice Dupond #}
Note that the arrow function has access to the current context.
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ function twig_replace_filter($str, $from)
*/
function twig_round($value, $precision = 0, $method = 'common')
{
$value = (float) $value;

if ('common' === $method) {
return round($value, $precision);
}
Expand All @@ -551,8 +553,6 @@ function twig_round($value, $precision = 0, $method = 'common')
throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.');
}

$value = (float) $value;

return $method($value * 10 ** $precision) / 10 ** $precision;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Fixtures/filters/round.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

{{ ''|round(-1, 'floor')}}
{{ null|round(-1, 'floor')}}
{{ null|round }}
{{ null|round(2, 'ceil') }}
--DATA--
return []
--EXPECT--
Expand All @@ -28,3 +30,5 @@ return []

0
0
0
0

0 comments on commit 5981815

Please sign in to comment.