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

Aperta
#347 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@staabm ci sta già lavorando.

Dal 4/11/2026.

  • #349 di @staabm — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
php
Ambito
testing, tooling

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
PHP
Stelle
714
Fork
63
Merge medio
1g 11h
PR unite (30g)
8

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di phpstan/phpstan-strict-rules

Tutte le issue di phpstan/phpstan-strict-rules

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.