Skip to content

Commit 570ce73

Browse files
authored
Merge pull request #1039 from PHPCSStandards/phpcs-4.0/feature/squiz-variablecomment-make-tagnotallowed-modular
Squiz/VariableComment: make errorcode for "TagNotAllowed" warning modular
2 parents 3d5bf47 + 20994a2 commit 570ce73

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

phpcs.xml.dist

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
<rule ref="Squiz.Commenting.PostStatementComment">
4848
<exclude name="Squiz.Commenting.PostStatementComment.AnnotationFound"/>
4949
</rule>
50-
<rule ref="Squiz.Commenting.VariableComment"/>
50+
<rule ref="Squiz.Commenting.VariableComment">
51+
<exclude name="Squiz.Commenting.VariableComment.DeprecatedTagNotAllowed"/>
52+
<exclude name="Squiz.Commenting.VariableComment.LinkTagNotAllowed"/>
53+
</rule>
5154
<rule ref="Squiz.Formatting.OperatorBracket"/>
5255
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing"/>
5356
<rule ref="Squiz.Operators.ComparisonOperatorUsage"/>
@@ -154,9 +157,4 @@
154157
<exclude-pattern>src/Standards/Generic/Sniffs/Commenting/TodoSniff\.php</exclude-pattern>
155158
<exclude-pattern>src/Standards/Generic/Tests/Commenting/TodoUnitTest\.php</exclude-pattern>
156159
</rule>
157-
158-
<!-- @see https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/122#discussion_r1414167897 -->
159-
<rule ref="Squiz.Commenting.VariableComment">
160-
<exclude-pattern>src/Util/Tokens\.php</exclude-pattern>
161-
</rule>
162160
</ruleset>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
111111
} else {
112112
$error = '%s tag is not allowed in member variable comment';
113113
$data = [$tokens[$tag]['content']];
114-
$phpcsFile->addWarning($error, $tag, 'TagNotAllowed', $data);
114+
$code = ucwords(ltrim($tokens[$tag]['content'], '@')).'TagNotAllowed';
115+
$phpcsFile->addWarning($error, $tag, $code, $data);
115116
}//end if
116117
}//end foreach
117118

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,26 @@ class PHP84FinalProperties {
476476
*/
477477
final int $hasDocblock;
478478
}
479+
480+
// phpcs:disable Squiz.Commenting.VariableComment.SinceTagNotAllowed
481+
// phpcs:disable Squiz.Commenting.VariableComment.DeprecatedTagNotAllowed
482+
class AllowMoreForSelectivelyIgnoringDisallowedTags {
483+
/**
484+
* @var string
485+
*
486+
* @since 3.1
487+
* @deprecated 10.5
488+
*/
489+
public string $propertyWithExtraTags;
490+
491+
/**
492+
* @var string
493+
*
494+
* @link https://example.org/some-link
495+
* @api
496+
* @param string This tag is not allowed.
497+
*/
498+
public $theAboveExtraTagsAreStillNotAllowed;
499+
}
500+
501+
// phpcs:enable Squiz.Commenting.VariableComment

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,26 @@ class PHP84FinalProperties {
476476
*/
477477
final int $hasDocblock;
478478
}
479+
480+
// phpcs:disable Squiz.Commenting.VariableComment.SinceTagNotAllowed
481+
// phpcs:disable Squiz.Commenting.VariableComment.DeprecatedTagNotAllowed
482+
class AllowMoreForSelectivelyIgnoringDisallowedTags {
483+
/**
484+
* @var string
485+
*
486+
* @since 3.1
487+
* @deprecated 10.5
488+
*/
489+
public string $propertyWithExtraTags;
490+
491+
/**
492+
* @var string
493+
*
494+
* @link https://example.org/some-link
495+
* @api
496+
* @param string This tag is not allowed.
497+
*/
498+
public $theAboveExtraTagsAreStillNotAllowed;
499+
}
500+
501+
// phpcs:enable Squiz.Commenting.VariableComment

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ public function getErrorList()
8181
*/
8282
public function getWarningList()
8383
{
84-
return [93 => 1];
84+
return [
85+
93 => 1,
86+
494 => 1,
87+
495 => 1,
88+
496 => 1,
89+
];
8590

8691
}//end getWarningList()
8792

0 commit comments

Comments
 (0)