mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-04 14:36:52 +00:00
Merge branch '2.x' into 3.x
* 2.x: Tweaking phpdoc above Environment Identity Equals - Best practices Update default.rst
This commit is contained in:
@@ -21,6 +21,15 @@ undefined:
|
||||
.. code-block:: twig
|
||||
|
||||
{{ var.method(foo|default('foo'))|default('foo') }}
|
||||
|
||||
Using the ``default`` filter on a boolean variable might trigger unexpected behaviour, as
|
||||
``false`` is treated as an empty value. Consider using ``??`` instead:
|
||||
|
||||
.. code-block:: twig
|
||||
|
||||
{% set foo = false %}
|
||||
{{ foo|default(true) }} {# true #}
|
||||
{{ foo ?? true }} {# false #}
|
||||
|
||||
.. note::
|
||||
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ use Twig\RuntimeLoader\RuntimeLoaderInterface;
|
||||
use Twig\TokenParser\TokenParserInterface;
|
||||
|
||||
/**
|
||||
* Stores the Twig configuration.
|
||||
* Stores the Twig configuration and renders templates.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
|
||||
@@ -525,11 +525,11 @@ function twig_replace_filter($str, $from)
|
||||
*/
|
||||
function twig_round($value, $precision = 0, $method = 'common')
|
||||
{
|
||||
if ('common' == $method) {
|
||||
if ('common' === $method) {
|
||||
return round($value, $precision);
|
||||
}
|
||||
|
||||
if ('ceil' != $method && 'floor' != $method) {
|
||||
if ('ceil' !== $method && 'floor' !== $method) {
|
||||
throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.');
|
||||
}
|
||||
|
||||
@@ -1184,7 +1184,7 @@ function twig_to_array($seq, $preserveKeys = true)
|
||||
function twig_test_empty($value)
|
||||
{
|
||||
if ($value instanceof \Countable) {
|
||||
return 0 == \count($value);
|
||||
return 0 === \count($value);
|
||||
}
|
||||
|
||||
if ($value instanceof \Traversable) {
|
||||
|
||||
Reference in New Issue
Block a user