Skip to content

Commit 43f8d67

Browse files
committed
Modernize: Squiz/InlineComment: use class constant for constant array
1 parent 775bd10 commit 43f8d67

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
class InlineCommentSniff implements Sniff
1717
{
1818

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+
1930

2031
/**
2132
* Returns an array of tokens this test wants to listen for.
@@ -227,17 +238,11 @@ public function process(File $phpcsFile, $stackPtr)
227238
// Only check the end of comment character if the start of the comment
228239
// is a letter, indicating that the comment is just standard text.
229240
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) {
238243
$error = 'Inline comments must end in %s';
239244
$ender = '';
240-
foreach ($acceptedClosers as $closerName => $symbol) {
245+
foreach (self::VALID_SENTENCE_END_CHARS as $closerName => $symbol) {
241246
$ender .= ' '.$closerName.',';
242247
}
243248

0 commit comments

Comments
 (0)