Skip to content

4.0 | Add parameter types to all (non-test) methods#1237

Merged
jrfnl merged 15 commits into
4.xfrom
phpcs-4.x/feature/390-add-param-types
Sep 11, 2025
Merged

4.0 | Add parameter types to all (non-test) methods#1237
jrfnl merged 15 commits into
4.xfrom
phpcs-4.x/feature/390-add-param-types

Conversation

@jrfnl

@jrfnl jrfnl commented Sep 11, 2025

Copy link
Copy Markdown
Member

Description

4.0 | PHPCS Framework classes: add parameter types

4.0 | Files: add parameter types

This commit explicitly does not include adding a parameter type to the File::getTokensAsString() $start and $length parameters as the pre-existing inline parameter validation is more comprehensive and more reliable.

4.0 | Filters: add parameter types

4.0 | Generators: add parameter types

Includes changing the expected parameter type for a couple of methods from DomNode to DomElement.
The previous was incorrect, but changing the method signature by making a type more specific, is a breaking change, so had to wait until now.

4.0 | Reports: add parameter types

4.0 | Tokenizers: add parameter types

4.0 | Util classes: add parameter types

This commit explicitly does not include adding a parameter type to the MessageCollector::add() $message and $type parameters and the Common::getSniffCode() $sniffsClass parameter, as the pre-existing inline parameter validation is more comprehensive and more reliable.

Includes removing a type check from an "internal-only" class which is no longer necessary (and updating the associated test).

4.0 | (Abstract) Sniff classes: add parameter types

4.0 | Standards/Generic: add parameter types to sniffs

4.0 | Standards/PEAR: add parameter types to sniffs

4.0 | Standards/PSR: add parameter types to sniffs

4.0 | Standards/Squiz: add parameter types to sniffs

4.0 | Standards/Zend: add parameter types to sniffs

4.0 | Tests: add parameter types to sniffs used as test fixtures

4.0 | AbstractSniffTestCase: add parameter types

Includes updating the sniff test classes overloading these methods.

Suggested changelog entry

  • Wherever possible based on the PHP 7.2 minimum version, parameter types have been added to all methods.

Related issues/external references

Fixes #390

This commit explicitly does **not** include adding a parameter type to the `File::getTokensAsString()` `$start` and `$length` parameters as the pre-existing inline parameter validation is more comprehensive and more reliable.
Includes changing the expected parameter type for a couple of methods from `DomNode` to `DomElement`.
The previous was incorrect, but changing the method signature by making a type more specific, is a breaking change, so had to wait until now.
This commit explicitly does **not** include adding a parameter type to the `MessageCollector::add()` `$message` and `$type` parameters and the `Common::getSniffCode()` `$sniffsClass` parameter, as the pre-existing inline parameter validation is more comprehensive and more reliable.

Includes removing a type check from an "internal-only" class which is no longer necessary (and updating the associated test).
Includes updating the sniff test classes overloading these methods.
@jrfnl

jrfnl commented Sep 11, 2025

Copy link
Copy Markdown
Member Author

Associated update PR for the PHPCS 4.0 dev upgrade guide: PHPCSStandards/PHP_CodeSniffer-documentation#55

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant