auto-fix "Call to function in_array() requires parameter #3 to be set/true."

Offen
#347 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@staabm arbeitet bereits daran.

Seit 04.11.2026.

  • #349 von @staabm — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
php
Bereich
testing, tooling

Rechercherichtung

Read the linked pull request #349 first; it already has this issue in progress. The issue describes the fixer behavior for in_array(), array_search() and eligible array_keys() calls, including named arguments, splat calls, and types inferred from PHPDoc. Done means only calls whose strict equivalence can be proven are changed, while base64_decode() and array_keys() calls without a search value remain unaffected.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

if we know native haystack and needle types for a in_array, array_keys or array_search call, it would be great we could fix add a true as 3rd parameter in case its missing or can always be true. we should only fix when haystacks' iterable type is a super type of needle (strict comparison). the fixer must not change calls where equivalence cannot be proven.

Example: in_array($needle, X::VALS) into its strict counterpart in_array($needle, X::VALS, true).
https://phpstan.org/r/e288cf2a-08e5-4c06-9255-1a98eefc99fe

named arguments should be supported and calls using the splat operator should be skipped.

we should not fix calls which get their iterable-value type from a phpdoc, e.g.:

/** @return int[] */ 
function getArray(): array {}

function doFoo(int $i):bool {
  return in_array($i, getArray());
}

For array_keys(), only consider calls with at least two arguments, since the strictness flag matters only when a search value is supplied. Calls without a search value should remain unchanged.

The rule also reports calls to other functions, such as base64_decode(). Those calls should not be made fixable by this change.

Vorherrschende Sprache
PHP
Sterne
714
Forks
63
Ø Merge
1 T. 11 Std.
Gemergte PRs (30 T.)
8

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus phpstan/phpstan-strict-rules

Alle Issues in phpstan/phpstan-strict-rules

Ähnliche Issues

Weitere Issues zu PHP

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.