From ba6e62303d567863275fb086941f50a06dc7d08f Mon Sep 17 00:00:00 2001
From: Klaus Purer <klaus.purer@protonmail.ch>
Date: Sun, 15 Oct 2023 11:55:50 +0200
Subject: [PATCH] fix(VariableComment): Allow intersection types in @var
 comment (#3392423)

---
 .../Sniffs/Commenting/VariableCommentSniff.php       |  1 +
 tests/Drupal/Commenting/VariableCommentUnitTest.inc  | 12 ++++++++++++
 .../Commenting/VariableCommentUnitTest.inc.fixed     | 12 ++++++++++++
 3 files changed, 25 insertions(+)

diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php
index 8b5a04dc..1b6a3fcf 100644
--- a/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php
+++ b/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php
@@ -50,6 +50,7 @@ class VariableCommentSniff extends AbstractVariableSniff
             T_NULLABLE,
             T_READONLY,
             T_TYPE_UNION,
+            T_TYPE_INTERSECTION,
             T_FALSE,
             T_NULL,
         ];
diff --git a/tests/Drupal/Commenting/VariableCommentUnitTest.inc b/tests/Drupal/Commenting/VariableCommentUnitTest.inc
index 5e6358f6..bfb78f30 100644
--- a/tests/Drupal/Commenting/VariableCommentUnitTest.inc
+++ b/tests/Drupal/Commenting/VariableCommentUnitTest.inc
@@ -84,4 +84,16 @@ class Test {
    */
   protected string $constant;
 
+  /**
+   * Intersection type support, it is allowed to repeat it in the var type.
+   *
+   * @var \Drupal\user\UserStorageInterface&\PHPUnit\Framework\MockObject\MockObject
+   */
+  protected UserStorageInterface&MockObject $userStorageMock;
+
+  /**
+   * It is also allowed to leave the var comment out since there is a type.
+   */
+  protected UserStorageInterface&MockObject $userStorageMock2;
+
 }
diff --git a/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed b/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed
index a8876df1..25ed52c5 100644
--- a/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed
+++ b/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed
@@ -88,4 +88,16 @@ class Test {
    */
   protected string $constant;
 
+  /**
+   * Intersection type support, it is allowed to repeat it in the var type.
+   *
+   * @var \Drupal\user\UserStorageInterface&\PHPUnit\Framework\MockObject\MockObject
+   */
+  protected UserStorageInterface&MockObject $userStorageMock;
+
+  /**
+   * It is also allowed to leave the var comment out since there is a type.
+   */
+  protected UserStorageInterface&MockObject $userStorageMock2;
+
 }
-- 
GitLab