Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

AlwaysReturnInFilter: isInsideIfConditonal() guards the conditions array after reading it

Chiusa Adatta ai principianti
#903 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Una pull request collegata è già stata integrata.

  • #905 di @tomjn — integrata

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
tooling

Direzione di ricerca

Inizia da AlwaysReturnInFilterSniff::isInsideIfConditonal() e analizza come viene letto l'array conditions del token. Semplifica la logica di guard e reset come descritto, quindi verifica che lo sniff segnali ancora gli stessi casi; il lavoro è terminato quando la pulizia preserva il comportamento delle segnalazioni.

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

Descrizione

This is a tidy-up. It does not change what the sniff reports.

AlwaysReturnInFilterSniff::isInsideIfConditonal() decides whether a return in a filter callback sits inside an if. It has a guard for a token that has no conditions array, but the guard comes after two end() calls that have already read that array, so it protects nothing. PHP_CodeSniffer sets conditions on every token, so the guard is not needed in the first place.

The reset() call between the two has no effect on the result either. It only undoes the array pointer move that end() made on the shared token array.

The method can read the array once, return false when the innermost condition is a function or closure, and otherwise return in_array( T_IF, $conditions, true ).

@GaryJones spotted this while reviewing #901. It was left out of that PR because that one only adds return types.

Lingua principale
PHP
Stelle
261
Fork
44
Merge medio
3g 17h
PR unite (30g)
9

Preparare l'ambiente

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 Automattic/VIP-Coding-Standards

Tutte le issue di Automattic/VIP-Coding-Standards

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.