Skip to content

Refactor OptionalToRequiredFunctionParameterSniff and RequiredToOptionalFunctionParametersSniff#1273

Merged
wimg merged 2 commits intodevelopfrom
feature/608-638-793-1042-decouple-required-to-optional-param-sniffs
May 9, 2021
Merged

Refactor OptionalToRequiredFunctionParameterSniff and RequiredToOptionalFunctionParametersSniff#1273
wimg merged 2 commits intodevelopfrom
feature/608-638-793-1042-decouple-required-to-optional-param-sniffs

Conversation

@jrfnl
Copy link
Copy Markdown
Member

@jrfnl jrfnl commented Apr 3, 2021

OptionalToRequiredFunctionParameter: decouple from RequiredToOptionalFunctionParametersSniff

This is a technical refactor and contains no significant functional changes.

The OptionalToRequiredFunctionParameterSniff class previously extended the RequiredToOptionalFunctionParametersSniff class, which in turn extended the AbstractComplexVersionSniff.

The sniff has now been refactored to directly extend the AbstractFunctionCallParameterSniff class instead.

The purpose of this refactor is three-fold:

  1. Multiple people have reported issues with fatal "class already declared" errors for this sniff extending another sniff.
    While this is primarily an issue with the autoloader in PHPCS, the issue can be avoided by not allowing one sniff to directly extend another.
    Note: the same problem does not exist when extending an abstract sniff, so this solution will be fine.
  2. The (global) function call determination in the AbstractFunctionCallParameterSniff sniff is better than the one which was previously contained in the RequiredToOptionalFunctionParametersSniff, preventing some potential false positives as demonstrated by the additional unit tests.
  3. In the (near) future, PHPCSUtils is expected to contain a version of the AbstractFunctionCallParameterSniff which is better still.
    By decoupling this sniff from the RequiredToOptionalFunctionParametersSniff and by extension from the AbstractComplexVersionSniff sniff, we pave the way for the breaking change of removing the AbstractComplexVersionSniff class.
    The switch over to the PHPCSUtils version of the AbstractFunctionCallParameterSniff in itself is not a breaking change and can therefore safely be done in a future minor release.

Note: Aside from the tests still passing, I have also verified that the sniff error codes are not affected by this change, so from a "custom ruleset"/"ignore annotations" point of view this refactor does not contain any breaking changes.

Fixes #608
Fixes #638
Fixes #793
Fixes #1042

RequiredToOptionalFunctionParameters: decouple from AbstractComplexVersionSniff

This is a technical refactor and contains no significant functional changes.

The RequiredToOptionalFunctionParametersSniff class previously extended the AbstractComplexVersionSniff.

The sniff has now been refactored to extend the AbstractFunctionCallParameterSniff class instead.

The purpose of this refactor is two-fold:

  1. The (global) function call determination in the AbstractFunctionCallParameterSniff sniff is better than the one which was previously contained in the RequiredToOptionalFunctionParametersSniff, preventing some potential false positives as demonstrated by the additional unit tests.
  2. In the (near) future, PHPCSUtils is expected to contain a version of the AbstractFunctionCallParameterSniff which is better still.
    By decoupling this sniff from the RequiredToOptionalFunctionParametersSniff and by extension from the AbstractComplexVersionSniff sniff, we pave the way for the breaking change of removing the AbstractComplexVersionSniff class.
    The switch over to the PHPCSUtils version of the AbstractFunctionCallParameterSniff in itself is not a breaking change and can therefore safely be done in a future minor release.

Note: Aside from the tests still passing, I have also verified that the sniff error codes are not affected by this change, so from a "custom ruleset"/"ignore annotations" point of view this refactor does not contain any breaking changes.

@jrfnl jrfnl added this to the 10.0.0 milestone Apr 3, 2021
@jrfnl jrfnl requested a review from wimg April 3, 2021 21:29
jrfnl added 2 commits April 11, 2021 07:37
…FunctionParametersSniff

This is a technical refactor and contains no significant functional changes.

The `OptionalToRequiredFunctionParameterSniff` class previously extended the `RequiredToOptionalFunctionParametersSniff` class, which in turn extended the `AbstractComplexVersionSniff`.

The sniff has now been refactored to directly extend the `AbstractFunctionCallParameterSniff` class instead.

The purpose of this refactor is three-fold:
1. Multiple people have reported issues with fatal "class already declared" errors for this sniff extending another sniff.
    While this is primarily an issue with the autoloader in PHPCS, the issue can be avoided by not allowing one sniff to directly extend another.
    Note: the same problem does not exist when extending an _abstract_ sniff, so this solution will be fine.
2. The (global) function call determination in the `AbstractFunctionCallParameterSniff` sniff is better than the one which was previously contained in the `RequiredToOptionalFunctionParametersSniff`, preventing some potential false positives as demonstrated by the additional unit tests.
3. In the (near) future, PHPCSUtils is expected to contain a version of the `AbstractFunctionCallParameterSniff` which is better still.
    By decoupling this sniff from the `RequiredToOptionalFunctionParametersSniff` and by extension from the `AbstractComplexVersionSniff` sniff, we pave the way for the breaking change of removing the `AbstractComplexVersionSniff` class.
    The switch over to the PHPCSUtils version of the `AbstractFunctionCallParameterSniff` in itself is not a breaking change and can therefore safely be done in a future minor release.

Note: Aside from the tests still passing, I have also verified that the sniff error codes are not affected by this change, so from a "custom ruleset"/"ignore annotations" point of view this refactor does not contain any breaking changes.

Fixes 608
Fixes 638
Fixes 793
Fixes 1042
…rsionSniff

This is a technical refactor and contains no significant functional changes.

The `RequiredToOptionalFunctionParametersSniff` class previously extended the `AbstractComplexVersionSniff`.

The sniff has now been refactored to extend the `AbstractFunctionCallParameterSniff` class instead.

The purpose of this refactor is two-fold:
1. The (global) function call determination in the `AbstractFunctionCallParameterSniff` sniff is better than the one which was previously contained in the `RequiredToOptionalFunctionParametersSniff`, preventing some potential false positives as demonstrated by the additional unit tests.
2. In the (near) future, PHPCSUtils is expected to contain a version of the `AbstractFunctionCallParameterSniff` which is better still.
    By decoupling this sniff from the `RequiredToOptionalFunctionParametersSniff` and by extension from the `AbstractComplexVersionSniff` sniff, we pave the way for the breaking change of removing the `AbstractComplexVersionSniff` class.
    The switch over to the PHPCSUtils version of the `AbstractFunctionCallParameterSniff` in itself is not a breaking change and can therefore safely be done in a future minor release.

Note: Aside from the tests still passing, I have also verified that the sniff error codes are not affected by this change, so from a "custom ruleset"/"ignore annotations" point of view this refactor does not contain any breaking changes.
@jrfnl jrfnl force-pushed the feature/608-638-793-1042-decouple-required-to-optional-param-sniffs branch from 4034c11 to aede516 Compare April 11, 2021 05:37
@wimg wimg merged commit 883f96b into develop May 9, 2021
@wimg wimg deleted the feature/608-638-793-1042-decouple-required-to-optional-param-sniffs branch May 9, 2021 15:59
@ktomk
Copy link
Copy Markdown

ktomk commented Jun 2, 2021

@jrfnl: I already had it by just referencing the PHPCompat ruleset alone and then looked into auto-loading in PHPCS and I think it can be prevented there. I filed a PR: squizlabs/PHP_CodeSniffer#3369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment