Repository: PHPCSStandards/PHP_CodeSniffer (php)

Issue:
Squiz/VariableComment: incorrectly flags missing docblock for properties with union/intersection type
## Describe the bug

When scanning a class containing properties with PHP native union or intersection types, these will always be flagged as not having a docblock even when a docblock is present.

### Code sample
```php
class Foo
{
    /**
     * This is fine.
     *
     * @var string|integer
     */
    public $correct_not_missing_docblock_union;

    /**
     * This snippet gets flagged with "Missing member variable doc comment (Squiz.Commenting.VariableComment.Missing)"
     *
     * @var string|integer
     */
    public string|int $BUG_missing_docblock_with_union_type;

    /**
     * This is fine
     *
     * @var InterfaceA&InterfacB
     */
    public $correct_not_missing_docblock_intersection;

    /**
     * This snippet gets flagged with "Missing member variable doc comment (Squiz.Commenting.VariableComment.Missing)"
     *
     * @var InterfaceA&InterfacB
     */
    public InterfaceA&InterfacB $BUG_missing_docblock_intersection;
}
```


### To reproduce
Steps to reproduce the behavior:
1. Create a file called `test.php` with the code sample above...
2. Run `phpcs test.php --standard=squiz --sniffs=squiz.commenting.variablecomment`
3. See error message displayed
```
---------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
---------------------------------------------------------------------------------------------
 17 | ERROR | Missing member variable doc comment (Squiz.Commenting.VariableComment.Missing)
 31 | ERROR | Missing member variable doc comment (Squiz.Commenting.VariableComment.Missing)
---------------------------------------------------------------------------------------------
```

## Expected behavior
That the docblocks would be recognized correctly and no "missing docblock" errors would be thrown.

## Versions (please complete the following information)

| | |
|-|-|
| Operating System | _not relevant_
| PHP version | _not relevant_
| PHP_CodeSniffer version | `master`
| Standard | Squiz
| Install type | git clone

## Additional context
PR squizlabs/PHP_CodeSniffer#3757 may contain a partial fix for this.

## Please confirm:

- [x] I have searched the issue list and am not opening a duplicate issue.
- [x] I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- [x] I have verified the issue still exists in the `master` branch of PHP_CodeSniffer.


Pull request description:
Squiz/VariableComment: allow union and intersection types to be detected
If one uses a union type for an object property, the doc-type-hint could not be related to the variable type.

Fixed now.

Includes unit test.

This is a continuation of [#3757](https://github.com/squizlabs/PHP_CodeSniffer/pull/3757)

Closes #178
Closes squizlabs/PHP_CodeSniffer#3757


Patch:
diff --git a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php
index d2d53e2c3..f7599c779 100644
--- a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php
+++ b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php
@@ -30,16 +30,18 @@ class VariableCommentSniff extends AbstractVariableSniff
     {
         $tokens = $phpcsFile->getTokens();
         $ignore = [
-            T_PUBLIC       => T_PUBLIC,
-            T_PRIVATE      => T_PRIVATE,
-            T_PROTECTED    => T_PROTECTED,
-            T_VAR          => T_VAR,
-            T_STATIC       => T_STATIC,
-            T_READONLY     => T_READONLY,
-            T_WHITESPACE   => T_WHITESPACE,
-            T_STRING       => T_STRING,
-            T_NS_SEPARATOR => T_NS_SEPARATOR,
-            T_NULLABLE     => T_NULLABLE,
+            T_PUBLIC            => T_PUBLIC,
+            T_PRIVATE           => T_PRIVATE,
+            T_PROTECTED         => T_PROTECTED,
+            T_VAR               => T_VAR,
+            T_STATIC            => T_STATIC,
+            T_READONLY          => T_READONLY,
+            T_WHITESPACE        => T_WHITESPACE,
+            T_STRING            => T_STRING,
+            T_NS_SEPARATOR      => T_NS_SEPARATOR,
+            T_NULLABLE          => T_NULLABLE,
+            T_TYPE_UNION        => T_TYPE_UNION,
+            T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
         ];
 
         for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {


Test patch:
diff --git a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
index 36efc443b..928022498 100644
--- a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
+++ b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
@@ -402,3 +402,19 @@ class ReadOnlyProps
 
      private readonly string $variable;
 }
+
+class UnionTypes
+{
+    /**
+     * @var array|boolean
+     */
+    private array|bool $variableName = array();
+}
+
+class IntersectionTypes
+{
+    /**
+     * @var \Iterator|\Countable
+     */
+    private \Iterator&\Countable $variableName;
+}
diff --git a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed
index 5c652f540..2666c7c55 100644
--- a/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed
+++ b/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed
@@ -402,3 +402,19 @@ class ReadOnlyProps
 
      private readonly string $variable;
 }
+
+class UnionTypes
+{
+    /**
+     * @var array|boolean
+     */
+    private array|bool $variableName = array();
+}
+
+class IntersectionTypes
+{
+    /**
+     * @var \Iterator|\Countable
+     */
+    private \Iterator&\Countable $variableName;
+}