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:
Fabien Potencier
2020-03-17 15:09:39 +01:00
3 changed files with 13 additions and 4 deletions
+9
View File
@@ -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
View File
@@ -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>
*/
+3 -3
View File
@@ -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) {