WordPress / WordPress/WordPress-Coding-Standards

DeprecatedParameterValues: false positives when handling string concatenation and constants

Open
#2,564 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Extra Type: Bug
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

Bug Description

The WordPress.WP.DeprecatedParameterValues sniff does not handle string concatenation and constants correctly, and this can lead to false positives.

In the case of string concatenation, it only checks the value of the first non-empty token passed, disregarding that there can be multiple tokens passed as part of a single parameter. This is problematic if the content of the first token matches one of the deprecated parameter values.

Similarly, if the constant name matches the content of one of the deprecated string parameters, a false positive will happen because the sniff does not differentiate between the different types of a given parameter.

Minimal Code Snippet

The issue happens when running this command:

vendor/bin/phpcs -s --standard=WordPress --sniffs=WordPress.WP.DeprecatedParameterValues test.php

... over a file containing this code:

<?php

get_bloginfo( 'home' . 'url' );
get_bloginfo(home);

Error Code

WordPress.WP.DeprecatedParameterValues.Found

Environment

Question Answer
PHP version 8.3.22
PHP_CodeSniffer version 3.13.2
WordPressCS version develop
PHPCSUtils version 1.1.0
PHPCSExtra version 1.4.0
WordPressCS install type git clone
IDE (if relevant) N/A

Additional Context (optional)

I discussed this issue briefly with @jrfnl and she suggested that "maybe the sniff should be updated to indicate within the arrays with parameter information for what type(s) of tokens it should check ?"

Something to consider when working on this issue.

Tested Against develop Branch?

  • I have verified the issue still exists in the develop branch of WordPressCS.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WordPress.WP.DeprecatedParameterValues sniff and reproduce the report using the supplied phpcs command and test.php snippet. Trace how concatenated arguments and constants are classified; done means get_bloginfo( 'home' . 'url' ) and get_bloginfo(home) no longer produce false positives while deprecated literal parameter values remain detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing, tooling
Issue type
Bug
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.