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

✨ New Modernize.FunctionCalls.Dirname sniff #172

Merged
merged 2 commits into from
Dec 2, 2022

Commits on Dec 2, 2022

  1. Introduce new Modernize standard

    Includes updating CI and other dev related files to take the new standard into account.
    jrfnl committed Dec 2, 2022
    Configuration menu
    Copy the full SHA
    5e0cdc6 View commit details
    Browse the repository at this point in the history
  2. ✨ New Modernize.FunctionCalls.Dirname sniff

    This new sniff will detect and, when possible, auto-fix two typical code modernizations which can be made related to the `dirname()` function:
    1. Since PHP 5.3, calls to `dirname(__FILE__)` can be replaced by `__DIR__`.
        Errorcode: `Modernize.FunctionCalls.Dirname.FileConstant`.
    2. Since PHP 7.0, nested function calls to `dirname()` can be changed to use the new `$levels` parameter.
        Errorcode: `Modernize.FunctionCalls.Dirname.Nested`.
    
    Depending on supported PHP versions of an application, the complete sniff can be enabled and/or just one of the error codes could be enabled.
    
    **Regarding the fixers:**
    
    The sniff - and more importantly, the fixer - take fully qualified function calls, named parameters, as well as trailing comma's in function calls into account.
    
    * If a comment is found in any of the code which would be removed by the fixer, the issues will still be flagged, but not be marked as fixable.
    * If the value of a pre-existing `$levels` parameter cannot be determined, the issues will still be flagged, but not be marked as fixable.
    
    Also take note that the fixer does not make any presumptions about the code style of the project. It is recommended to run the code style fixers together with or after this fixer, so those can adjust the code style to the style applicable in the project.
    
    Includes fixer.
    Includes unit tests.
    Includes documentation.
    
    Notes/Future scope:
    * The sniff is not yet compatible with PHPCS 4.x.
    * When PHPCSUtils releases its own abstract for sniffing function calls, this sniff should switch to it.
    
    Refs:
    * https://www.php.net/manual/en/function.dirname.php
    * PHP 5.3: https://php-legacy-docs.zend.com/manual/php5/en/migration53.global-constants
    * PHp 7.0: https://www.php.net/manual/en/migration70.changed-functions.php#migration70.changed-functions.core
        Note: the parameter was originally called `$depth`, but has since been renamed to `$levels`.
    jrfnl committed Dec 2, 2022
    Configuration menu
    Copy the full SHA
    1d3943d View commit details
    Browse the repository at this point in the history