From f2fde71ef785161daf52fc82853db03aecbe5172 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Fri, 10 Feb 2023 17:35:18 +0100 Subject: [PATCH] disable the Squiz\VariableCommentSniff "missing" code, to fix union types --- .../Sniffs/Commenting/VariableCommentSniff.php | 11 ++++++++++- tests/DigiComp/Sniffs/Commenting/data/comments.php | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/DigiComp/Sniffs/Commenting/VariableCommentSniff.php b/src/DigiComp/Sniffs/Commenting/VariableCommentSniff.php index 6f2e0ed..d89c602 100644 --- a/src/DigiComp/Sniffs/Commenting/VariableCommentSniff.php +++ b/src/DigiComp/Sniffs/Commenting/VariableCommentSniff.php @@ -16,6 +16,7 @@ class VariableCommentSniff extends \PHP_CodeSniffer\Standards\Squiz\Sniffs\Comme \T_PROTECTED => \T_PROTECTED, \T_VAR => \T_VAR, \T_STATIC => \T_STATIC, + \T_TYPE_UNION => \T_TYPE_UNION, \T_WHITESPACE => \T_WHITESPACE, \T_STRING => \T_STRING, \T_NS_SEPARATOR => \T_NS_SEPARATOR, @@ -50,7 +51,15 @@ class VariableCommentSniff extends \PHP_CodeSniffer\Standards\Squiz\Sniffs\Comme $phpcsFile->addWarning($error, $commentEnd, 'MissingVarOrInheritDoc'); return; } - + // remove the error reporting from base class, as it does not accept union types + // https://github.com/squizlabs/PHP_CodeSniffer/pull/3757 + $oldSeverity = $phpcsFile->ruleset->ruleset['DigiComp.Commenting.VariableComment.Missing']['severity'] ?? null; + $phpcsFile->ruleset->ruleset['DigiComp.Commenting.VariableComment.Missing']['severity'] = 0; parent::processMemberVar($phpcsFile, $stackPtr); + if ($oldSeverity) { + $phpcsFile->ruleset->ruleset['DigiComp.Commenting.VariableComment.Missing']['severity'] = $oldSeverity; + } else { + unset($phpcsFile->ruleset->ruleset['DigiComp.Commenting.VariableComment.Missing']['severity']); + } } } diff --git a/tests/DigiComp/Sniffs/Commenting/data/comments.php b/tests/DigiComp/Sniffs/Commenting/data/comments.php index 3011138..64a42e4 100644 --- a/tests/DigiComp/Sniffs/Commenting/data/comments.php +++ b/tests/DigiComp/Sniffs/Commenting/data/comments.php @@ -37,3 +37,10 @@ class E extends A { #[\OwnAttribute] protected $myVar; } + +class F extends A { + /** + * @var A|E + */ + protected A|E $myVar; +}