False positives when using the null-safe operator `?->` in an if-condition
| Subject | Details |
|---|---|
| Plugin | Php Inspections (EA Extended) 5.0.0.0 |
| Language level | e.g. PHP 8.2 (check project settings or composer.json) |
Current behaviour
The following code is reported with the following two issues:
Line 5: [EA] Null pointer exception may occur here. (on $shippingMethodConfig)
Line 6: [EA] The if-else workflow is driven by inverted conditions, consider avoiding invertions. (on `else)
/** @var ShippingMethodConfigEntity|null $shippingMethodConfig */
$shippingMethodConfig;
if ($shippingMethodConfig?->getAddressConfiguration()->useDefaultAddress() === false) {
$senderAddress = $shippingMethodConfig->getAddressConfiguration()->getAddress();
} else {
$senderAddress = $commonConfig->getSenderAddress();
}
Expected behaviour
No errors are reported. Neither is the if driven by an inverted condition (because we are comparing against bool?) nor can shippingMethodConfig be null here.
Environment details
Thank you for reporting @windaishi!
We have multiple reports for this case and will include a fix into next release.
We are pushing fix for Line 6: [EA] The if-else workflow is driven by inverted conditions, consider avoiding invertions. (on else)` false-positive, which greatly improves accuracy if the inspection. Thank you for reporting it @windaishi!
We are unsure how to proceed with Line 5: [EA] Null pointer exception may occur here. (on $shippingMethodConfig), @kalessil could you please share your thoughts about the false-positive.
@ea-inspections-team: agree with @windaishi, it's a false-positive.
From a types-resolving perspective, the code is correct (assignment in if-body will not inject null into the result type). I'm in support of fixing this false positive.
@kalessil: thank you. Fixing this is not a trivial task and we have to plan the fix for 2024.3 (not 2024.2).
Php Inspections (EA Extended) 5.3.0
PhpStorm 2025.2 Build #PS-252.23892.419, built on August 1, 2025 Source revision: 42cc6c7831493
Yup, still occurs. If someone wants to disable this specific inspection: Php Inspections (EA Extended) → Probable bugs → Null reference
probably only makes sense though if something else also checks this, e.g. PhpStan.