Skip to content

Commit

Permalink
Replace calls to twig_test_iterable to is_iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Oct 8, 2023
1 parent dafc3af commit 9e0ca37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function getTests(): array
new TwigTest('divisible by', null, ['node_class' => DivisiblebyTest::class, 'one_mandatory_argument' => true]),
new TwigTest('constant', null, ['node_class' => ConstantTest::class]),
new TwigTest('empty', 'twig_test_empty'),
new TwigTest('iterable', 'twig_test_iterable'),
new TwigTest('iterable', 'is_iterable'),
];
}

Expand Down Expand Up @@ -392,7 +392,7 @@ function twig_random(Environment $env, $values = null, $max = null)
}
}

if (!twig_test_iterable($values)) {
if (!is_iterable($values)) {
return $values;
}

Expand Down Expand Up @@ -529,7 +529,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null)
*/
function twig_replace_filter($str, $from)
{
if (!twig_test_iterable($from)) {
if (!is_iterable($from)) {
throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
}

Expand Down Expand Up @@ -626,7 +626,7 @@ function twig_array_merge(...$arrays)
$result = [];

foreach ($arrays as $argNumber => $array) {
if (!twig_test_iterable($array)) {
if (!is_iterable($array)) {
throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" for argument %d.', \gettype($array), $argNumber + 1));
}

Expand Down Expand Up @@ -722,7 +722,7 @@ function twig_last(Environment $env, $item)
*/
function twig_join_filter($value, $glue = '', $and = null)
{
if (!twig_test_iterable($value)) {
if (!is_iterable($value)) {
$value = (array) $value;
}

Expand Down Expand Up @@ -1428,7 +1428,7 @@ function twig_constant_is_defined($constant, $object = null)
*/
function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
{
if (!twig_test_iterable($items)) {
if (!is_iterable($items)) {
throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
}

Expand Down Expand Up @@ -1672,7 +1672,7 @@ function twig_array_column($array, $name, $index = null): array

function twig_array_filter(Environment $env, $array, $arrow)
{
if (!twig_test_iterable($array)) {
if (!is_iterable($array)) {
throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Node/WithNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function compile(Compiler $compiler): void
->write(sprintf('$%s = ', $varsName))
->subcompile($node)
->raw(";\n")
->write(sprintf("if (!twig_test_iterable(\$%s)) {\n", $varsName))
->write(sprintf("if (!is_iterable(\$%s)) {\n", $varsName))
->indent()
->write("throw new RuntimeError('Variables passed to the \"with\" tag must be a hash.', ")
->repr($node->getTemplateLine())
Expand Down

0 comments on commit 9e0ca37

Please sign in to comment.