Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant "instanceof \Countable" check (minor) #3996

Merged
merged 1 commit into from
Feb 10, 2024

Conversation

smnandre
Copy link
Contributor

In CoreExtension::lengthFilter, the check L1183 is redundant as "$thing instanceof \Countable" is already checked L1175.

    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());
    }

The check L1183 is redundant as "$thing instanceof \Countable" is already checked L1175.

```php
        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) {
            return mb_strlen((string) $thing, $env->getCharset());
        }
```
@smnandre
Copy link
Contributor Author

The last 2 commits are to please fabbot, but are unrelated to this PR changes... so feel free to remove them if this is not the good place

@fabpot
Copy link
Contributor

fabpot commented Feb 10, 2024

Can you remove the last 2 commits?

@smnandre
Copy link
Contributor Author

I removed them

@fabpot
Copy link
Contributor

fabpot commented Feb 10, 2024

Thank you @smnandre.

@fabpot fabpot merged commit 7f5958c into twigphp:3.x Feb 10, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants