Phpinspectionsea: Resolved operands types are not complimentary - Verify complimentary operands types - allow matching overlap

Created on 12 Apr 2019  路  2Comments  路  Source: kalessil/phpinspectionsea


| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Plugin | Php Inspections (EA Extended) - v3.0.13 |
| Language level | PHP 7.3.1 |

Current behaviour

Code like this:

$foo = $_COOKIE['bar'] ?? '';
$foo = substr($bar, 3) ?? '';

Produces the warnings:

Resolved operands types are not complimentary, while they should be ([string, array] vs [string]).
Resolved operands types are not complimentary, while they should be ([bool, string] vs [string]).

These are from Code Style > Proper null-coalescing operator usage.

That inspection has an option "Verify complimentary operands types" which would let me turn the checking off completely, but really I'd like an additional option for 'Match if types overlap'. So that if there is an intersection between the 2 arrays in the warning messages it would mark it as a pass.

E.g.
OK: [string, array] vs [string]
OK: [string, array] vs [bool, string]
Not OK: [string] vs [int]
Not OK: [string, array] vs [bool, int]

enhancement fixed

Most helpful comment

Implemented!

All 2 comments

Implemented!

I'm sorry, I just got this warning. What problem will it cause, and how should I fix it?

$foo = $_COOKIE['bar'] ?? '';
Was this page helpful?
0 / 5 - 0 ratings