Skip to content

Commit e9c4732

Browse files
committed
Modernize: Squiz/DoubleQuoteUsage: use class constant for constant array
1 parent 4db9d02 commit e9c4732

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@
1515
class DoubleQuoteUsageSniff implements Sniff
1616
{
1717

18+
/**
19+
* Escape chars which are supported in double quoted strings, but not in single quoted strings.
20+
*
21+
* @var array<string>
22+
*/
23+
private const ESCAPE_CHARS = [
24+
'\0',
25+
'\1',
26+
'\2',
27+
'\3',
28+
'\4',
29+
'\5',
30+
'\6',
31+
'\7',
32+
'\n',
33+
'\r',
34+
'\f',
35+
'\t',
36+
'\v',
37+
'\x',
38+
'\b',
39+
'\e',
40+
'\u',
41+
'\'',
42+
];
43+
1844

1945
/**
2046
* Returns an array of tokens this test wants to listen for.
@@ -91,28 +117,7 @@ public function process(File $phpcsFile, $stackPtr)
91117
return $skipTo;
92118
}//end if
93119

94-
$allowedChars = [
95-
'\0',
96-
'\1',
97-
'\2',
98-
'\3',
99-
'\4',
100-
'\5',
101-
'\6',
102-
'\7',
103-
'\n',
104-
'\r',
105-
'\f',
106-
'\t',
107-
'\v',
108-
'\x',
109-
'\b',
110-
'\e',
111-
'\u',
112-
'\'',
113-
];
114-
115-
foreach ($allowedChars as $testChar) {
120+
foreach (self::ESCAPE_CHARS as $testChar) {
116121
if (strpos($workingString, $testChar) !== false) {
117122
return $skipTo;
118123
}

0 commit comments

Comments
 (0)