Automattic / Automattic/VIP-Coding-Standards

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

Open
#717 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
261
Forks
44
Avg merge
19m
Merged PRs (30d)
1

Description

## 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 );
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing VIPCS PHP_CodeSniffer sniff conventions and how constant() calls are represented. Confirm that constant(FOO_BAR) is reported while quoted strings and variables are not, and verify the behavior with the relevant sniff test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.