Skip to content

Report only the ternary's own negated condition as redundant - #14417

Merged
danog merged 2 commits into
vimeo:masterfrom
danog:ternary-negated-active
Nov 21, 2026
Merged

danog merged 2 commits into
vimeo:masterfrom
danog:ternary-negated-active

Conversation

@danog

@danog danog commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Psalm reports a false RedundantCondition for ?? in an elseif whose if checked count().

Before

<?php
/** @param list<?int> $list */
function first(array $list): ?int {
    if (count($list) > 2) {
        return null;
    } elseif (($list[0] ?? null) !== null) { // RedundantCondition: Type list{0?: int|null, 1?: int|null} for $list is never has-at-least-3
        return 0;
    }

    return null;
}

After

    } elseif (($list[0] ?? null) !== null) { // no issue

The negated types of a ternary include the clauses that held before it, which
the context already applied: an elseif after count($a) > 2 reported
$a[0] ?? null as never has-at-least-3.
@danog danog added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: decreased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 768 98.1 $\color{gray}{\textsf{+1.5\%}}$ 25 925 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-1}}$ 53 509 $\color{green}{\textsf{-4}}$ 682
✅ symfony 3 606 163.8 $\color{gray}{\textsf{-1.5\%}}$ 50 606 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-1}}$ 98 398 $\color{green}{\textsf{-4}}$ 1 528
✅ doctrine-orm 393 21.3 $\color{gray}{\textsf{+0.6\%}}$ 3 466 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-14}}$ 6 105 $\color{green}{\textsf{-56}}$ 0
✅ psl 632 27.4 $\color{gray}{\textsf{+0.4\%}}$ 1 299 5 455 1
✅ phpunit 471 12.4 $\color{gray}{\textsf{-0.3\%}}$ 1 744 3 459 18
✅ php-parser 236 8.4 $\color{gray}{\textsf{+1.1\%}}$ 17 133 21 035 0
✅ tempest 905 23.1 $\color{gray}{\textsf{+4.5\%}}$ 5 043 10 505 252
✅ amphp-amp 61 2.0 29 49 0
✅ webmozarts-assert 288 4.9 $\color{gray}{\textsf{+0.4\%}}$ 577 2 720 0
✅ guzzle-promises 56 2.1 $\color{gray}{\textsf{+0.5\%}}$ 154 427 2
✅ monolog 153 6.0 $\color{gray}{\textsf{+0.5\%}}$ 903 2 403 10
✅ drupal 4 851 182.1 $\color{gray}{\textsf{-0.5\%}}$ 97 525 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-1}}$ 169 110 $\color{green}{\textsf{-2}}$ 583
Total 13 420 551.5 $\color{gray}{\textsf{-0.1\%}}$ 204 404 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-17}}$ 373 175 $\color{green}{\textsf{-66}}$ 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.
✅ laravel: issues +0 −1

Memory 1 768 → 1 768 MB (<0.1 %) · Wall 96.6 → 98.1 s (+1.5 %)

Weighted 53 513 → 53 509 (−4, −0.01 %): L4 −1

Issue type added removed
RedundantCondition 0 1

Removed (1)

  • src/Illuminate/Database/Query/Builder.php:4299 RedundantCondition (error): Type non-empty-array<array-key, non-empty-string>|non-empty-string|null for $uniqueBy is always non-empty-countable
✅ symfony: issues +0 −1

Memory 3 606 → 3 606 MB (<0.1 %) · Wall 166.2 → 163.8 s (−1.5 %)

Weighted 98 402 → 98 398 (−4, <0.01 %): L4 −1

Issue type added removed
RedundantCondition 0 1

Removed (1)

  • src/Symfony/Component/EventDispatcher/EventDispatcher.php:52 RedundantCondition (error): Type array<array-key, mixed> for $this->optimized is always isset
✅ doctrine-orm: issues +0 −14

Memory 393 → 393 MB (<0.1 %) · Wall 21.1 → 21.3 s (+0.6 %)

Weighted 6 161 → 6 105 (−56, −0.91 %): L4 −14

Issue type added removed
RedundantCondition 0 14

Removed (14)

  • src/Mapping/Driver/XmlDriver.php:170 RedundantCondition (error): Type SimpleXMLElement for $xmlRoot->indexes is always isset
  • src/Mapping/Driver/XmlDriver.php:213 RedundantCondition (error): Type SimpleXMLElement for $xmlRoot->unique-constraints is always isset
  • src/Mapping/Driver/XmlDriver.php:307 RedundantCondition (error): Type SimpleXMLElement for $idElement->generator is always isset
  • src/Mapping/Driver/XmlDriver.php:364 RedundantCondition (error): Type SimpleXMLElement for $oneToOneElement->join-columns is always isset
  • src/Mapping/Driver/XmlDriver.php:415 RedundantCondition (error): Type SimpleXMLElement for $oneToManyElement->order-by is always isset
  • src/Mapping/Driver/XmlDriver.php:466 RedundantCondition (error): Type SimpleXMLElement for $manyToOneElement->join-columns is always isset
  • src/Mapping/Driver/XmlDriver.php:550 RedundantCondition (error): Type SimpleXMLElement for $manyToManyElement->order-by is always isset
  • src/Mapping/Driver/XmlDriver.php:576 RedundantCondition (error): Type SimpleXMLElement for $xmlRoot->attribute-overrides is always isset
  • src/Mapping/Driver/XmlDriver.php:588 RedundantCondition (error): Type SimpleXMLElement for $xmlRoot->association-overrides is always isset
  • src/Mapping/Driver/XmlDriver.php:595 RedundantCondition (error): Type SimpleXMLElement for $overrideElement->join-columns is always isset
  • … and 4 more
✅ drupal: issues +0 −1

Memory 4 851 → 4 851 MB (<0.1 %) · Wall 183.1 → 182.1 s (−0.5 %)

Weighted 169 112 → 169 110 (−2, <0.01 %): L2 −1

Issue type added removed
RedundantConditionGivenDocblockType 0 1

Removed (1)

  • core/lib/Drupal/Core/TypedData/Plugin/DataType/BinaryData.php:44 RedundantConditionGivenDocblockType (error): Docblock-defined type string for $this->uri is always isset

head e299c77 · base 1552477 (merge-base) · workflow run

@danog
danog merged commit 908f6e1 into vimeo:master Nov 21, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant