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

Review the WordPressVIPMinimum.Classes.DeclarationCompatibility sniff #507

Open
51 tasks
jrfnl opened this issue Jul 22, 2020 · 2 comments
Open
51 tasks

Review the WordPressVIPMinimum.Classes.DeclarationCompatibility sniff #507

jrfnl opened this issue Jul 22, 2020 · 2 comments
Assignees
Labels
PHPCSUtils The addition and utilisation of PHPCSUtils package
Milestone

Comments

@jrfnl
Copy link
Collaborator

jrfnl commented Jul 22, 2020

Review the WordPressVIPMinimum.Classes.DeclarationCompatibility sniff for the following in as far as relevant to that sniff:

  • Code style independent sniffing / Correct handling of quirky code
    Typical things to add tests for and verify correct handling of:
    • Nested function/closure declarations
    • Nested class declarations
    • Comments in unexpected places
    • Variables being assigned to via list statements
    • Multiline text strings
    • Text strings provided via heredoc/nowdoc
    • Use of short open tags
    • Using PHP close tag as end of statement
    • Inline control structures (without braces)
  • Code simplifications which can be made using PHPCSUtils
  • Sniff stability improvements which can be made using PHPCSUtils
  • Correct handling of modern PHP code
    Typical things to add tests for and verify correct handling of (where applicable):
    • PHP 5.0 Try/catch/finally (PHP 5.5) and exceptions
    • PHP 5.3 Namespaced code vs code in the global namespace
    • PHP 5.3 Use import statements, incl aliasing
    • PHP 5.3 Short ternaries
    • PHP 5.3 Closures, incl closure use
    • PHP 5.4 Short arrays
    • PHP 5.5 Class name resolution using ::class
    • PHP 5.5 List in foreach
    • PHP 5.5/7.0 Generators using yield and yield from
    • PHP 5.6 Constant scalar expressions
    • PHP 5.6 Importing via use function/const
    • PHP 7.0 Null coalesce
    • PHP 7.0 Anonymous classes
    • PHP 7.0 Scalar and return type declarations
    • PHP 7.0 Group use statements
    • PHP 7.1 Short lists
    • PHP 7.1 Keyed lists
    • PHP 7.1 Multi-catch
    • PHP 7.1 Nullable types
    • PHP 7.3 List reference assignments
    • PHP 7.4 arrow functions
    • PHP 7.4 numeric literals with underscores
    • PHP 7.4 null coalesce equals
    • PHP 7.4 Typed properties
    • Various versions: trailing comma's in function calls, group use, function declarations, closure use etc

Other:

  • Review violation error vs warning
  • Review violation severity
  • Review violation message, consider adding a link
  • Check open issues related to the sniff
  • Review PHPDoc comments

Sniff basics, but changes need to be lined up for next major release:

Once PHPCS/PHPCSUtils supports this:

  • PHP 8.0 Constructor property promotion
  • PHP 8.0 Union types
  • PHP 8.0 match expressions
  • PHP 8.0 Nullsafe operator
  • PHP 8.0 Named arguments
  • PHP 8.0 Single token namespaced names
@jrfnl jrfnl added this to the 3.x milestone Sep 13, 2020
@jrfnl jrfnl added the PHPCSUtils The addition and utilisation of PHPCSUtils package label Sep 13, 2020
@jrfnl
Copy link
Collaborator Author

jrfnl commented Sep 19, 2023

Noticed the following three things while looking at this sniff for something unrelated:

No parameter name check

Looks like the parameter name as declared in a child class is not checked against the parameter name in the parent class, while in the context of PHP 8.0 named parameters and these methods potentially being called via call_user_func_array(), it is actually important that the parameter names match as well.

Signature checks are incomplete

Also looks like the signature checks are incomplete.

For example: it only checks if a parameter is declared to be passed by reference when the parameter in the parent class is declared to be passed by reference, while, when the parameter in the parent is not passed by reference, we should also make sure that the parameter in the overloaded method in the child class is also not passed by reference (currently it could well be, which is wrong and will not be flagged as-is).

if (
(
array_key_exists( 'default', $param ) === true &&
array_key_exists( 'default', $signatureParams[ $i ] ) === false
) || (
array_key_exists( 'pass_by_reference', $param ) === true &&
$param['pass_by_reference'] !== $signatureParams[ $i ]['pass_by_reference']
) || (
array_key_exists( 'variable_length', $param ) === true &&
$param['variable_length'] !== $signatureParams[ $i ]['variable_length']
)
) {

Check for type declarations

IIRC, none of the parameters in the parent classes have type declarations.

We should make sure that the methods in child classes also don't have type declarations as that would violate the contravariance rules and potentially cause a fatal error.

Return type declarations are fine as those are covariant.

@jrfnl
Copy link
Collaborator Author

jrfnl commented Sep 19, 2023

Also note that this class definitely needs a lot more tests.

jrfnl added a commit that referenced this issue Sep 19, 2023
While looking at this sniff for something unrelated, I started wondering if the signature definitions were still in line with WP Core.

Turned out they were not.

Refs:
* https://developer.wordpress.org/reference/classes/wp_widget/wp_widget/
* https://developer.wordpress.org/reference/classes/walker/start_el/
* https://developer.wordpress.org/reference/classes/walker/end_el/
* https://developer.wordpress.org/reference/classes/walker/unset_children/

Also see the [additional notes I've added to the review ticket](#507 (comment)).
jrfnl added a commit that referenced this issue Sep 19, 2023
While looking at this sniff for something unrelated, I started wondering if the signature definitions were still in line with WP Core.

Turned out they were not, though with the current checks being done in the sniff, this wasn't necessarily problematic (though it should have been, but that's for another PR).

Also see the [additional notes I've added to the review ticket](#507 (comment)).

Refs:
* https://developer.wordpress.org/reference/classes/wp_widget/wp_widget/
* https://developer.wordpress.org/reference/classes/walker/start_el/
* https://developer.wordpress.org/reference/classes/walker/end_el/
* https://developer.wordpress.org/reference/classes/walker/unset_children/
rebeccahum pushed a commit that referenced this issue May 2, 2024
While looking at this sniff for something unrelated, I started wondering if the signature definitions were still in line with WP Core.

Turned out they were not, though with the current checks being done in the sniff, this wasn't necessarily problematic (though it should have been, but that's for another PR).

Also see the [additional notes I've added to the review ticket](#507 (comment)).

Refs:
* https://developer.wordpress.org/reference/classes/wp_widget/wp_widget/
* https://developer.wordpress.org/reference/classes/walker/start_el/
* https://developer.wordpress.org/reference/classes/walker/end_el/
* https://developer.wordpress.org/reference/classes/walker/unset_children/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PHPCSUtils The addition and utilisation of PHPCSUtils package
Projects
None yet
Development

No branches or pull requests

1 participant