Phpinspectionsea: Invalid fix for interesting null coalesce pattern

Created on 16 Nov 2018  路  4Comments  路  Source: kalessil/phpinspectionsea

First, thank you for reporting a bug or making a request. That takes time and we appreciate that!

Let's start with common details:

| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Issue type | Bug |
| Plugin | Php Inspections (EA Extended), 3.0.8.1 |
| Language level | PHP 7.0 |

The null coalesce operator "fixed" this

            $r = $a = $w = false;
            if (isset($this->params['readonly'])) {
                $r = $this->params['readonly'];
            }
            if (isset($this->params['align_columns'])) {
                $a = $this->params['align_columns'];
            }
            if (isset($this->params['wrap_columns'])) {
                $w = $this->params['wrap_columns'];
            }

to

            $r = $this->params['readonly'] ?? $a = $w = false;
            if (isset($this->params['align_columns'])) {
                $a = $this->params['align_columns'];
            }
            if (isset($this->params['wrap_columns'])) {
                $w = $this->params['wrap_columns'];
            }

rather than

$r = $this->params['readonly'] ?? false;
$a = $this->params['align_columns'] ?? false;
$w = $this->params['wrap_columns'] ?? false;

PhpStorm 2018.3 EAP
Build #PS-183.4284.100, built on November 14, 2018
PhpStorm EAP User
Expiration date: December 14, 2018
JRE: 1.8.0_152-release-1343-b15 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.1

bug / false-positive fixed

All 4 comments

OT: Could we maybe have an inspection that reports multiple assignments in the same line? Doesn't feel like a best practice for me really...

@andreasschroth: why not. Please create a new issue, so the idea is not lost =)

@kalessil Yeah, right, I agree. Added a new issue for that.

Fixed!

Was this page helpful?
0 / 5 - 0 ratings