|
15 | 15 | class FileCommentSniff implements Sniff
|
16 | 16 | {
|
17 | 17 |
|
| 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 | + |
18 | 30 |
|
19 | 31 | /**
|
20 | 32 | * Returns an array of tokens this test wants to listen for.
|
@@ -123,18 +135,10 @@ public function process(File $phpcsFile, $stackPtr)
|
123 | 135 | $phpcsFile->addError($error, $commentEnd, 'SpacingAfterComment');
|
124 | 136 | }
|
125 | 137 |
|
126 |
| - // Required tags in correct order. |
127 |
| - $required = [ |
128 |
| - '@package' => true, |
129 |
| - '@subpackage' => true, |
130 |
| - '@author' => true, |
131 |
| - '@copyright' => true, |
132 |
| - ]; |
133 |
| - |
134 | 138 | $foundTags = [];
|
135 | 139 | foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
|
136 | 140 | $name = $tokens[$tag]['content'];
|
137 |
| - $isRequired = isset($required[$name]); |
| 141 | + $isRequired = isset(self::REQUIRED_TAGS[$name]); |
138 | 142 |
|
139 | 143 | if ($isRequired === true && in_array($name, $foundTags, true) === true) {
|
140 | 144 | $error = 'Only one %s tag is allowed in a file comment';
|
@@ -185,7 +189,7 @@ public function process(File $phpcsFile, $stackPtr)
|
185 | 189 |
|
186 | 190 | // Check if the tags are in the correct position.
|
187 | 191 | $pos = 0;
|
188 |
| - foreach ($required as $tag => $true) { |
| 192 | + foreach (self::REQUIRED_TAGS as $tag => $true) { |
189 | 193 | if (in_array($tag, $foundTags, true) === false) {
|
190 | 194 | $error = 'Missing %s tag in file comment';
|
191 | 195 | $data = [$tag];
|
|
0 commit comments