Skip to content

Commit 7725dec

Browse files
committed
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.
1 parent dc0ac49 commit 7725dec

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
4242
T_NULLABLE => T_NULLABLE,
4343
T_TYPE_UNION => T_TYPE_UNION,
4444
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
45+
T_NULL => T_NULL,
46+
T_TRUE => T_TRUE,
47+
T_FALSE => T_FALSE,
4548
];
4649

4750
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {

src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,21 @@ class IntersectionTypes
418418
*/
419419
private \Iterator&\Countable $variableName;
420420
}
421+
422+
class StandaloneNullTrueFalseTypes
423+
{
424+
/**
425+
* @var null
426+
*/
427+
public null $variableName = null;
428+
429+
/**
430+
* @var true
431+
*/
432+
protected true $variableName = true;
433+
434+
/**
435+
* @var false
436+
*/
437+
private false $variableName = false;
438+
}

src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,21 @@ class IntersectionTypes
418418
*/
419419
private \Iterator&\Countable $variableName;
420420
}
421+
422+
class StandaloneNullTrueFalseTypes
423+
{
424+
/**
425+
* @var null
426+
*/
427+
public null $variableName = null;
428+
429+
/**
430+
* @var true
431+
*/
432+
protected true $variableName = true;
433+
434+
/**
435+
* @var false
436+
*/
437+
private false $variableName = false;
438+
}

0 commit comments

Comments
 (0)