Automattic / Automattic/VIP-Coding-Standards

Add sniff to delete_option() + add_option

未关闭
#637 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Type: Enhancement
主要语言
PHP
星标
261
派生
44
平均合并
19 分钟
30 天内合并 PR
1

描述

## 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).

贡献指南

打开贡献指南

调研方向

首先跟踪现有的 PHP_CodeSniffer sniffs 如何表示 delete_option() 和 add_option() 调用,包括其 scope 和 option-key 处理方式。完成标准是报告同一 scope 中的匹配调用,排除不同 scope 或 key 的调用,并建议使用 update_option();issue 未指定目标文件或测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
php, wordpress
领域
tooling
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。