Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Add sniff to delete_option() + add_option

Offen
#637 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@rebeccahum arbeitet bereits daran.

Seit 31.3.2021.

  • #648 von @rebeccahum — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
php, wordpress
Bereich
tooling

Rechercherichtung

Beginne damit nachzuverfolgen, wie bestehende PHP_CodeSniffer-Sniffs Aufrufe von delete_option() und add_option() darstellen, einschließlich ihres Scopes und des Umgangs mit Option-Keys. Als abgeschlossen gilt die Meldung übereinstimmender Aufrufe im selben Scope unter Ausschluss anderer Scopes oder Keys sowie der Vorschlag, update_option() zu verwenden; das Issue nennt keine Zieldatei und keinen Test.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Type: Enhancement

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?

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).
Vorherrschende Sprache
PHP
Sterne
261
Forks
44
Ø Merge
3 T. 9 Std.
Gemergte PRs (30 T.)
10

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus Automattic/VIP-Coding-Standards

Alle Issues in Automattic/VIP-Coding-Standards

Ähnliche Issues

Weitere Issues zu PHP

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.