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

Move sanitization methods to SanitizationHelperTrait + minor improvements #2356

Merged
merged 8 commits into from
Aug 18, 2023

Commits on Aug 18, 2023

  1. Rename SanitizingFunctionsTrait to SanitizationHelperTrait

    The `Sniff:;is_*sanitized()` utility methods are about to be moved to this trait, but once they have been, the trait name is no longer correct as all other `*Functions[Helper|Trait]` classes/traits _only_ deal with function lists and checking whether something is in those lists, while this trait will now do more than that.
    
    With that in mind, I propose to rename the trait to `SanitizationHelperTrait`.
    jrfnl committed Aug 18, 2023
    Configuration menu
    Copy the full SHA
    21d8cae View commit details
    Browse the repository at this point in the history
  2. Move sanitization methods to SanitizationHelperTrait

    This moves the last utility functions from the `Sniff` class to a dedicated trait.
    
    I am also explicitly marking the trait as internal API to allow us to iterate on this (not so very clean) solution in future 3.x releases without being forced to wait for a 4.0 release.
    
    The methods have been made stand-alone, as in, the presumption that the WPCS `Sniff` class is being extended has been removed by adding the `$phpcsFile` parameter.
    
    Closes 1465
    jrfnl committed Aug 18, 2023
    Configuration menu
    Copy the full SHA
    50e1fe9 View commit details
    Browse the repository at this point in the history
  3. SanitizationHelperTrait::is_sanitized(): add some defensive coding

    As this method is now stand-alone, we'd better make sure the token being examined exists.
    
    Note: no need to do the same for the `is_only_sanitized()` method as the first thing that method calls is this method and if this method returns `false`, the `is_only_sanitized()` method will too.
    jrfnl committed Aug 18, 2023
    Configuration menu
    Copy the full SHA
    e72ca2c View commit details
    Browse the repository at this point in the history
  4. SanitizationHelperTrait::is_sanitized(): implement PHPCSUtils

    Note: The `$functionPtr` variable is overwritten a few lines later and the other variables being set are effectively unused (other than in these lines), so this code can be safely removed/replaced.
    jrfnl committed Aug 18, 2023
    Configuration menu
    Copy the full SHA
    b217ebc View commit details
    Browse the repository at this point in the history
  5. SanitizationHelperTrait::is_sanitized(): efficiency tweak - move unse…

    …t check up
    
    A variable which is being unset, doesn't need to be unslashed or sanitized, so bow out early.
    jrfnl committed Aug 18, 2023
    Configuration menu
    Copy the full SHA
    0834f59 View commit details
    Browse the repository at this point in the history
  6. SanitizationHelperTrait::is_sanitized(): efficiency fix/improve perfo…

    …rmance
    
    Remove the need for a call to the performance negative `array_diff_key()` function by setting up the original arrays in a better way.
    jrfnl committed Aug 18, 2023
    Configuration menu
    Copy the full SHA
    1bf115b View commit details
    Browse the repository at this point in the history
  7. SanitizationHelperTrait::is_sanitized(): minor code tweaks

    * Get rid of an unnecessary `else`.
    * Improve readability of long condition.
    * Get rid of unnecessary true/false condition code.
    jrfnl committed Aug 18, 2023
    Configuration menu
    Copy the full SHA
    6440bed View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    2d019df View commit details
    Browse the repository at this point in the history