Automattic / Automattic/VIP-Coding-Standards

Sniff idea: Detect when constant is being used in constant()

Offen
#717 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
PHP
Sterne
261
Forks
44
Ø Merge
19 Min.
Gemergte PRs (30 T.)
1

Beschreibung

## Describe the solution you'd like

Not sure if VIPCS is the best way forward, but I think this would be a worthy sniff.

When using `constant()`, we should throw a warning if a string is not being inputted. Of course it is valid PHP to do something like:

```
constant( FOO_BAR );
```

But I think most likely, what the user wants to do is:

```
constant( 'FOO_BAR' );
```

## What code should be reported as a violation?

```
constant( FOO_BAR );
```

## What code should *not* be reported as a violation?

```
constant( 'FOO_BAR' );
constant( "FOO_BAR" );
constant( $foo_bar );
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, die bestehenden VIPCS-PHP_CodeSniffer-Sniff-Konventionen und die Darstellung von Aufrufen von constant() zu prüfen. Bestätige, dass constant(FOO_BAR) gemeldet wird, während Zeichenketten in Anführungszeichen und Variablen nicht gemeldet werden, und überprüfe das Verhalten mit der relevanten Sniff-Testsuite.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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