Skip to content

Commit

Permalink
YoastCS rules: disallow the "mixed" type in annotations
Browse files Browse the repository at this point in the history
An exception is made for the tests, as a data provider for input validation within a function could well be passing every single different type, in which case, `mixed` is perfectly valid.

Related to 303

Fixes 196

Impact on Yoast packages:

| Plugin/Tool       | Errors/Warnings |
|-------------------|-----------------|
| PHPUnit Polyfills | 49 (this is valid though as these are assertion declarations)
| WP Test Utils     | --
| YoastCS           | 2
| WHIP              | --
| Yoast Test Helper | 4
| Duplicate Post    | 12
| Yst ACF           | 1
| Yst WooCommerce   | 2
| Yst News          | 1
| Yst Local         | 42
| Yst Video         | 12
| Yst Premium       | 17
| Yst Free          | 151
  • Loading branch information
jrfnl committed Dec 14, 2023
1 parent e5eb7c0 commit 5b93977
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions Yoast/Reports/Threshold.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @since 2.2.0
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Flags unused params which are required via the interface. Invalid.
* @phpcs:disable SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint -- Type is too complex to document properly.
*/
final class Threshold implements Report {

Expand Down
6 changes: 6 additions & 0 deletions Yoast/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation"/>
</rule>

<!-- Disallows usage of "mixed" type hint. -->
<rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint">
<!-- Make an exception for the tests as "mixed" is a valid type for testing type validation in code. -->
<exclude-pattern>*/tests/*\.php$</exclude-pattern>
</rule>

<!-- CS: don't allow "// end class" comments and the likes. -->
<rule ref="PSR12.Classes.ClosingBrace"/>

Expand Down

0 comments on commit 5b93977

Please sign in to comment.