non-optimal if statement

Answered

I am using PhpStorm and it says that this if statement is non optimal. Unfortunately it does not say why. Can anyone tell me it is non-optimal?

if ($this->tokens[$next_token_ptr]['code'] === T_ARRAY) {
                        $next_token_ptr = $this->tokens[$this->tokens[$next_token_ptr]['parenthesis_opener']]['parenthesis_closer'];
                    } else if ($this->tokens[$next_token_ptr]['code'] === T_OPEN_SHORT_ARRAY) {
                        $next_token_ptr = $this->tokens[$next_token_ptr]['bracket_closer'];
                    } else {
                        // T_CLOSURE.
                        $next_token_ptr = $this->tokens[$next_token_ptr]['scope_closer'];
                    }
5 comments

Hi there,

Need to see the context. This code block on its own does not produce such notice.

 

Same on StackOverflow: https://stackoverflow.com/questions/51282580/why-is-this-php-if-statement-non-optimal-according-to-phpstorm

 

1

Also would be great to see the screenshot of PhpStorm telling this statement is not optimal - I can't recall any default inspections doing that.

0

>I can't recall any default inspections doing that.

Quite likely comes from Php Inspections (EA Extended) plugin -- it has a bunch of them for "non-optimal if".

0

Yes was coming from Php Inspections.

The problem is that this expression is executed twice when it can be done only once

$this->tokens[$next_token_ptr]['code']

Thanks
0

Please contact the plugin author, we don't provide any support for 3rd party plugins:

https://plugins.jetbrains.com/plugin/7622-php-inspections-ea-extended-

0

Please sign in to leave a comment.