Automattic / Automattic/VIP-Coding-Standards
Add sniff to delete_option() + add_option
- Lenguaje dominante
- PHP
- Estrellas
- 261
- Forks
- 44
- Merge medio
- 19 min
- PR fusionados (30 d)
- 1
Descripción
## 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).
Guía de contribución
Línea de trabajo
Comienza rastreando cómo los sniffs existentes de PHP_CodeSniffer representan las llamadas a delete_option() y add_option(), incluido su scope y el manejo de las option-keys. Se considera terminado informar de las llamadas coincidentes en el mismo scope, excluyendo scopes o keys diferentes, y sugerir update_option(); el issue no indica ningún archivo objetivo ni ninguna prueba.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- php, wordpress
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100