Skip to content

Commit 775bd10

Browse files
committed
Modernize: Squiz/FileComment: use class constant for constant array
1 parent 7dc700b commit 775bd10

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
class FileCommentSniff implements Sniff
1616
{
1717

18+
/**
19+
* Required tags in correct order.
20+
*
21+
* @var array<string, true>
22+
*/
23+
private const REQUIRED_TAGS = [
24+
'@package' => true,
25+
'@subpackage' => true,
26+
'@author' => true,
27+
'@copyright' => true,
28+
];
29+
1830

1931
/**
2032
* Returns an array of tokens this test wants to listen for.
@@ -123,18 +135,10 @@ public function process(File $phpcsFile, $stackPtr)
123135
$phpcsFile->addError($error, $commentEnd, 'SpacingAfterComment');
124136
}
125137

126-
// Required tags in correct order.
127-
$required = [
128-
'@package' => true,
129-
'@subpackage' => true,
130-
'@author' => true,
131-
'@copyright' => true,
132-
];
133-
134138
$foundTags = [];
135139
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
136140
$name = $tokens[$tag]['content'];
137-
$isRequired = isset($required[$name]);
141+
$isRequired = isset(self::REQUIRED_TAGS[$name]);
138142

139143
if ($isRequired === true && in_array($name, $foundTags, true) === true) {
140144
$error = 'Only one %s tag is allowed in a file comment';
@@ -185,7 +189,7 @@ public function process(File $phpcsFile, $stackPtr)
185189

186190
// Check if the tags are in the correct position.
187191
$pos = 0;
188-
foreach ($required as $tag => $true) {
192+
foreach (self::REQUIRED_TAGS as $tag => $true) {
189193
if (in_array($tag, $foundTags, true) === false) {
190194
$error = 'Missing %s tag in file comment';
191195
$data = [$tag];

0 commit comments

Comments
 (0)