|
16 | 16 | class InlineCommentSniff implements Sniff
|
17 | 17 | {
|
18 | 18 |
|
| 19 | + /** |
| 20 | + * Characters which are accepted to end a sentence. |
| 21 | + * |
| 22 | + * @var array<string, string> |
| 23 | + */ |
| 24 | + private const VALID_SENTENCE_END_CHARS = [ |
| 25 | + 'full-stops' => '.', |
| 26 | + 'exclamation marks' => '!', |
| 27 | + 'or question marks' => '?', |
| 28 | + ]; |
| 29 | + |
19 | 30 |
|
20 | 31 | /**
|
21 | 32 | * Returns an array of tokens this test wants to listen for.
|
@@ -227,17 +238,11 @@ public function process(File $phpcsFile, $stackPtr)
|
227 | 238 | // Only check the end of comment character if the start of the comment
|
228 | 239 | // is a letter, indicating that the comment is just standard text.
|
229 | 240 | if (preg_match('/^\p{L}/u', $commentText) === 1) {
|
230 |
| - $commentCloser = $commentText[(strlen($commentText) - 1)]; |
231 |
| - $acceptedClosers = [ |
232 |
| - 'full-stops' => '.', |
233 |
| - 'exclamation marks' => '!', |
234 |
| - 'or question marks' => '?', |
235 |
| - ]; |
236 |
| - |
237 |
| - if (in_array($commentCloser, $acceptedClosers, true) === false) { |
| 241 | + $commentCloser = $commentText[(strlen($commentText) - 1)]; |
| 242 | + if (in_array($commentCloser, self::VALID_SENTENCE_END_CHARS, true) === false) { |
238 | 243 | $error = 'Inline comments must end in %s';
|
239 | 244 | $ender = '';
|
240 |
| - foreach ($acceptedClosers as $closerName => $symbol) { |
| 245 | + foreach (self::VALID_SENTENCE_END_CHARS as $closerName => $symbol) { |
241 | 246 | $ender .= ' '.$closerName.',';
|
242 | 247 | }
|
243 | 248 |
|
|
0 commit comments