Automattic / Automattic/VIP-Coding-Standards

Add sniff to delete_option() + add_option

オープン
#637 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る
Type: Enhancement
主要言語
PHP
スター
261
フォーク
44
平均マージ
19分
マージ済み PR(30日)
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 を短くまとめたダイジェスト。