Automattic / Automattic/VIP-Coding-Standards
Add sniff to delete_option() + add_option
- Lingua principale
- PHP
- Stelle
- 261
- Fork
- 44
- Merge medio
- 19m
- PR unite (30g)
- 1
Descrizione
## What problem would the enhancement address for VIP?
As explained at https://github.com/woocommerce/woocommerce/pull/27696 there is a race condition when `delete_option('foo')` is followed by `add_option('foo', '...')`.
## Describe the solution you'd like
Having a sniff that looked for a `delete_option()` call followed by an `add_option()` immediately
or at some point within the same scope, for the same option key, could flag this race condition and suggest using `update_option()` instead.
## What code should be reported as a violation?
```php
function reset_settings() {
$defaults = get_default_settings();
delete_option( 'my_settings' );
add_option( 'my_settings', $defaults );
}
```
Likely to need some consideration of an option key that is using a variable.
## What code should *not* be reported as a violation?
- `add_option()` in a different scope.
- different option key (including different variable).
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia tracciando come gli sniffs esistenti di PHP_CodeSniffer rappresentano le chiamate a delete_option() e add_option(), incluso il relativo scope e la gestione delle option-key. Il lavoro è completato quando vengono segnalate le chiamate corrispondenti nello stesso scope, escludendo scope o key differenti, e viene suggerito update_option(); l'issue non indica alcun file target né alcun test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- php, wordpress
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100