Skip to content

Commit

Permalink
PHP 8.2 | Squiz/VariableComment: allow for stand-alone null/true/fals…
Browse files Browse the repository at this point in the history
…e 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.
  • Loading branch information
jrfnl committed Jan 10, 2024
1 parent dc0ac49 commit 7725dec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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--) {
Expand Down
18 changes: 18 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 7725dec

Please sign in to comment.