Skip to content

Commit

Permalink
minor twigphp#3996 Remove redundant "instanceof \Countable" check (mi…
Browse files Browse the repository at this point in the history
…nor) (smnandre)

This PR was merged into the 3.x branch.

Discussion
----------

Remove redundant "instanceof \Countable" check (minor)

In [CoreExtension::lengthFilter](https://github.com/twigphp/Twig/compare/3.x...smnandre:fix/remove-check-countable?expand=1#diff-29e85e483c6ec4a9c2fd144820b6722c86df60d54175b355d85e806253313c1a), the check L1183 is redundant as "`$thing instanceof \Countable`" is already checked L1175.

```diff
    if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) {
        return \count($thing);
    }

    if ($thing instanceof \Traversable) {
        return iterator_count($thing);
    }

-    if (method_exists($thing, '__toString') && !$thing instanceof \Countable) {
+    if (method_exists($thing, '__toString')) {
        return mb_strlen((string) $thing, $env->getCharset());
    }
```

Commits
-------

2836af3 Remove redundant "$thing instanceof \Countable" check
  • Loading branch information
fabpot committed Feb 10, 2024
2 parents 17bf9a0 + 2836af3 commit 7f5958c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ public static function lengthFilter(Environment $env, $thing)
return iterator_count($thing);
}

if (method_exists($thing, '__toString') && !$thing instanceof \Countable) {
if (method_exists($thing, '__toString')) {
return mb_strlen((string) $thing, $env->getCharset());
}

Expand Down

0 comments on commit 7f5958c

Please sign in to comment.