Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstantStringSniff: Take into account namespace prefixing #444

Merged
merged 3 commits into from
Oct 2, 2020

Commits on Sep 24, 2020

  1. Configuration menu
    Copy the full SHA
    a3a38b2 View commit details
    Browse the repository at this point in the history
  2. Namespace should be backslash rather than forward slash on unit test

    Co-Authored-By: Juliette <663378+jrfnl@users.noreply.github.com>
    rebeccahum and jrfnl committed Sep 24, 2020
    Configuration menu
    Copy the full SHA
    7c6dc07 View commit details
    Browse the repository at this point in the history

Commits on Sep 25, 2020

  1. Constants/ConstantString: prevent more false positives

    The `define()` and `defined()` functions expect the name of a constant as a text string to be passed as the first parameter.
    This sniff is intended to guard against a coding mistake where the name of the constant would be passed as a_constant_.
    
    While passing the name of the constant as a constant _could_ be perfectly valid when that constant contains the name of another constant as a text string, more often than not, it will be a coding error.
    
    As things were, the sniff did not handle parameters build up using more than one token into account. It also did not handle valid situations, like passing the constant name as a text string via a variable to the functions, correctly.
    
    As outlined in #422 (comment) (Proposal 1), this limits the sniff to _only_ trigger an error when a plain constant has been passed as the "constant name" parameter and ignore all other cases.
    
    Note: The current implementation of this fix, uses the WPCS `get_function_call_parameter()` method to retrieve the stack pointer to the start and end of the parameter. Once PHPCSUtils is in place, this function call should be replaced by using the PHPCSUtils version of that method.
    
    Fixes 422
    Fixes 480
    jrfnl committed Sep 25, 2020
    Configuration menu
    Copy the full SHA
    b01bca1 View commit details
    Browse the repository at this point in the history