Skip to content

Commit 13c4878

Browse files
committed
Modernize: PEAR/FileComment: use class constant for constant array
Note: this also affects the `PEAR.Commenting.ClassComment` sniff which extends this sniff. That sniff doesn't access the deprecated property directly, but if other sniffs `extend` the `ClassComment` sniff, they may be affected.
1 parent f4b3afa commit 13c4878

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class FileCommentSniff implements Sniff
1919
/**
2020
* Tags in correct order and related info.
2121
*
22-
* @var array
22+
* @var array<string, array<string, bool>>
2323
*/
24-
protected $tags = [
24+
protected const EXPECTED_TAGS = [
2525
'@category' => [
2626
'required' => true,
2727
'allow_multiple' => false,
@@ -68,6 +68,15 @@ class FileCommentSniff implements Sniff
6868
],
6969
];
7070

71+
/**
72+
* Tags in correct order and related info.
73+
*
74+
* @var array<string, array<string, bool>>
75+
*
76+
* @deprecated 4.0.0 Use the FileCommentSniff::EXPECTED_TAGS constant instead.
77+
*/
78+
protected $tags = self::EXPECTED_TAGS;
79+
7180

7281
/**
7382
* Returns an array of tokens this test wants to listen for.
@@ -235,11 +244,11 @@ protected function processTags($phpcsFile, $stackPtr, $commentStart)
235244
$tagTokens = [];
236245
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
237246
$name = $tokens[$tag]['content'];
238-
if (isset($this->tags[$name]) === false) {
247+
if (isset(static::EXPECTED_TAGS[$name]) === false) {
239248
continue;
240249
}
241250

242-
if ($this->tags[$name]['allow_multiple'] === false && isset($tagTokens[$name]) === true) {
251+
if (static::EXPECTED_TAGS[$name]['allow_multiple'] === false && isset($tagTokens[$name]) === true) {
243252
$error = 'Only one %s tag is allowed in a %s comment';
244253
$data = [
245254
$name,
@@ -265,7 +274,7 @@ protected function processTags($phpcsFile, $stackPtr, $commentStart)
265274

266275
// Check if the tags are in the correct position.
267276
$pos = 0;
268-
foreach ($this->tags as $tag => $tagData) {
277+
foreach (static::EXPECTED_TAGS as $tag => $tagData) {
269278
if (isset($tagTokens[$tag]) === false) {
270279
if ($tagData['required'] === true) {
271280
$error = 'Missing %s tag in %s comment';

0 commit comments

Comments
 (0)