Automattic / Automattic/VIP-Coding-Standards

File inclusion - check for constant defined in the current file

Open
#456 1 comment 0 reactions 0 assignees View on GitHub
Standard: VIP-Go Type: Enhancement
Dominant language
PHP
Stars
261
Forks
44
Avg merge
19m
Merged PRs (30d)
1

Description

## What problem would the enhancement address for VIP?

The frequency with which "Warning: File inclusion using custom constant (`PREFIX_PATH`). Probably needs manual inspection (WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant)." shows up just below a line that matches the pattern is high.

Perhaps we can reduce this noise.

## Describe the solution you'd like

See if we can improve the sniff, to see if the constant has been defined in the current file, and if so, skip the violation.

## What code should be reported as a violation?

```php
require PREFIX_PATH_UNDEFINED_IN_THIS_FILE . '/...';
```

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

```php
define( 'PREFIX_PATH_DEFINED_IN_THIS_FILE', '...' );
...other code...
require PREFIX_PATH_DEFINED_IN_THIS_FILE . '/...';
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the sniff that emits WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant and inspect how it detects constants in file-inclusion expressions. Add coverage for the undefined constant example and the constant defined earlier in the same file; done means only the undefined case is reported.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.