Automattic / Automattic/VIP-Coding-Standards
Add sniff to delete_option() + add_option
- Langage dominant
- PHP
- Étoiles
- 261
- Forks
- 44
- Merge moyen
- 19 min
- PR mergées (30 j)
- 1
Description
## 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).
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par retracer la manière dont les sniffs PHP_CodeSniffer existants représentent les appels à delete_option() et add_option(), y compris leur scope et la gestion des option-keys. Le travail est considéré comme terminé lorsque les appels correspondants dans le même scope sont signalés, en excluant les scopes ou les keys différents, et que update_option() est suggéré ; l’issue ne nomme aucun fichier cible ni aucun test.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- php, wordpress
- Domaine
- tooling
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100