From 7725dec0a4cf6c269384d9034face0f894e5c5a6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Dec 2023 17:17:32 +0100 Subject: [PATCH 1/2] PHP 8.2 | Squiz/VariableComment: allow for stand-alone null/true/false types Since PHP 8.2, stand-alone use of `true`, `false` and `null` is allowed. However, if these were used as the type for a property, the docblock would not be found. Fixed now. Includes unit tests. --- .../Sniffs/Commenting/VariableCommentSniff.php | 3 +++ .../Commenting/VariableCommentUnitTest.inc | 18 ++++++++++++++++++ .../VariableCommentUnitTest.inc.fixed | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php index f7599c779b..370e720875 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php @@ -42,6 +42,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr) T_NULLABLE => T_NULLABLE, T_TYPE_UNION => T_TYPE_UNION, T_TYPE_INTERSECTION => T_TYPE_INTERSECTION, + T_NULL => T_NULL, + T_TRUE => T_TRUE, + T_FALSE => T_FALSE, ]; for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) { diff --git a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc index 928022498a..60d83525cb 100644 --- a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc +++ b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc @@ -418,3 +418,21 @@ class IntersectionTypes */ private \Iterator&\Countable $variableName; } + +class StandaloneNullTrueFalseTypes +{ + /** + * @var null + */ + public null $variableName = null; + + /** + * @var true + */ + protected true $variableName = true; + + /** + * @var false + */ + private false $variableName = false; +} diff --git a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed index 2666c7c553..8bea190fd5 100644 --- a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed @@ -418,3 +418,21 @@ class IntersectionTypes */ private \Iterator&\Countable $variableName; } + +class StandaloneNullTrueFalseTypes +{ + /** + * @var null + */ + public null $variableName = null; + + /** + * @var true + */ + protected true $variableName = true; + + /** + * @var false + */ + private false $variableName = false; +} From b04f0a690ed6812e6eb4524248e2a7a8c4ea04a6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Dec 2023 17:19:55 +0100 Subject: [PATCH 2/2] Squiz/VariableComment: allow for various other missing types There were some more allowed types missing from the list of tokens to skip over to find a docblock. Fixed now. Includes unit tests. --- .../Sniffs/Commenting/VariableCommentSniff.php | 3 +++ .../Commenting/VariableCommentUnitTest.inc | 18 ++++++++++++++++++ .../VariableCommentUnitTest.inc.fixed | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php index 370e720875..76fbc6dca6 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php @@ -39,12 +39,15 @@ public function processMemberVar(File $phpcsFile, $stackPtr) T_WHITESPACE => T_WHITESPACE, T_STRING => T_STRING, T_NS_SEPARATOR => T_NS_SEPARATOR, + T_NAMESPACE => T_NAMESPACE, T_NULLABLE => T_NULLABLE, T_TYPE_UNION => T_TYPE_UNION, T_TYPE_INTERSECTION => T_TYPE_INTERSECTION, T_NULL => T_NULL, T_TRUE => T_TRUE, T_FALSE => T_FALSE, + T_SELF => T_SELF, + T_PARENT => T_PARENT, ]; for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) { diff --git a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc index 60d83525cb..54ef5d2d3b 100644 --- a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc +++ b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc @@ -436,3 +436,21 @@ class StandaloneNullTrueFalseTypes */ private false $variableName = false; } + +class MoreMissingButSupportedTypes +{ + /** + * @var parent + */ + public parent $variableName; + + /** + * @var self + */ + protected self $variableName; + + /** + * @var SomeClass + */ + private namespace\SomeClass $variableName; +} diff --git a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed index 8bea190fd5..a292b6de15 100644 --- a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed @@ -436,3 +436,21 @@ class StandaloneNullTrueFalseTypes */ private false $variableName = false; } + +class MoreMissingButSupportedTypes +{ + /** + * @var parent + */ + public parent $variableName; + + /** + * @var self + */ + protected self $variableName; + + /** + * @var SomeClass + */ + private namespace\SomeClass $variableName; +}