Automattic / Automattic/VIP-Coding-Standards

Add sniff to delete_option() + add_option

Đang mở
#637 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
Type: Enhancement
Ngôn ngữ chính
PHP
Star
261
Fork
44
Merge trung bình
19 phút
Pull request đã merge (30 ngày)
1

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách theo dõi cách các sniffs hiện có của PHP_CodeSniffer biểu diễn các lệnh gọi delete_option() và add_option(), bao gồm scope của chúng và cách xử lý option-key. Được xem là hoàn thành khi báo cáo các lệnh gọi khớp trong cùng scope, loại trừ các scope hoặc key khác nhau, và đề xuất update_option(); issue không nêu tên file đích hoặc test.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
php, wordpress
Lĩnh vực
tooling
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.