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

[Insight] Boolean should be compared strictly - in Event/FilterLocaleSwitchEvent.php, line 39 #157

Open
lunetics opened this issue May 9, 2015 · 2 comments

Comments

@lunetics
Copy link
Collaborator

lunetics commented May 9, 2015

in Event/FilterLocaleSwitchEvent.php, line 39

With booleans, only strict comparison (with === operator) should be used to lower bug risks and to improve performances.

     *
     * @throws \InvalidArgumentException
     */
    public function __construct(Request $request, $locale)
    {
        if (!is_string($locale) || null == $locale || '' == $locale) {
            throw new \InvalidArgumentException(sprintf('Wrong type, expected \'string\' got \'%s\'', $locale));
        }

        $this->request = $request;
        $this->locale = $locale;

Posted from SensioLabsInsight

@ghost
Copy link

ghost commented May 18, 2015

I think we should only use if(!is_string($locale)) {.
Edit: Or if(!is_string($locale) || !empty($locale)) { if empty strings should be forbidden.

is_string(false) = bool(false)
is_string(true) = bool(false)
is_string(NULL) = bool(false)
is_string('abc') = bool(true)
is_string('23') = bool(true)
is_string(23) = bool(false)
is_string('23.5') = bool(true)
is_string(23.5) = bool(false)
is_string('') = bool(true)
is_string(' ') = bool(true)
is_string('0') = bool(true)
is_string(0) = bool(false)

http://php.net/manual/de/function.is-string.php

@ghost ghost mentioned this issue May 18, 2015
@ghost
Copy link

ghost commented May 18, 2015

As explained here: #161 (comment)
we should do if(!is_string($locale) || '' === $locale) {.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant