✨ New Modernize.FunctionCalls.Dirname sniff #172
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduce new Modernize standard
Includes updating CI and other dev related files to take the new standard into account.
P.S.: By rights, this should be a separate standard in the PHPCompatibility organisation, but that's for later. For now, I just want to make sure this sniff becomes available.
✨ 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:dirname(__FILE__)
can be replaced by__DIR__
.Errorcode:
Modernize.FunctionCalls.Dirname.FileConstant
.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.
$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:
Refs:
Note: the parameter was originally called
$depth
, but has since been renamed to$levels
.