Skip to content

DeprecatedParameterValues: false positives when handling string concatenation and constants #2564

@rodrigoprimo

Description

@rodrigoprimo

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions