Skip to content

Commit 7e0f822

Browse files
committed
Generic/LowerCaseType: refactor [1] - move array to property
Move the `$phpTypes` array to a property and add the new types introduced in PHP 8.0 to it.
1 parent 8084948 commit 7e0f822

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@
1616
class LowerCaseTypeSniff implements Sniff
1717
{
1818

19+
/**
20+
* Native types supported by PHP.
21+
*
22+
* @var array
23+
*/
24+
private $phpTypes = [
25+
'self' => true,
26+
'parent' => true,
27+
'array' => true,
28+
'callable' => true,
29+
'bool' => true,
30+
'float' => true,
31+
'int' => true,
32+
'string' => true,
33+
'iterable' => true,
34+
'void' => true,
35+
'object' => true,
36+
'mixed' => true,
37+
'static' => true,
38+
'false' => true,
39+
'null' => true,
40+
];
41+
1942

2043
/**
2144
* Returns an array of tokens this test wants to listen for.
@@ -71,28 +94,14 @@ public function process(File $phpcsFile, $stackPtr)
7194
return;
7295
}//end if
7396

74-
$phpTypes = [
75-
'self' => true,
76-
'parent' => true,
77-
'array' => true,
78-
'callable' => true,
79-
'bool' => true,
80-
'float' => true,
81-
'int' => true,
82-
'string' => true,
83-
'iterable' => true,
84-
'void' => true,
85-
'object' => true,
86-
];
87-
8897
$props = $phpcsFile->getMethodProperties($stackPtr);
8998

9099
// Strip off potential nullable indication.
91100
$returnType = ltrim($props['return_type'], '?');
92101
$returnTypeLower = strtolower($returnType);
93102

94103
if ($returnType !== ''
95-
&& isset($phpTypes[$returnTypeLower]) === true
104+
&& isset($this->phpTypes[$returnTypeLower]) === true
96105
) {
97106
// A function return type.
98107
if ($returnTypeLower !== $returnType) {
@@ -129,7 +138,7 @@ public function process(File $phpcsFile, $stackPtr)
129138
$typeHintLower = strtolower($typeHint);
130139

131140
if ($typeHint !== ''
132-
&& isset($phpTypes[$typeHintLower]) === true
141+
&& isset($this->phpTypes[$typeHintLower]) === true
133142
) {
134143
// A function return type.
135144
if ($typeHintLower !== $typeHint) {

0 commit comments

Comments
 (0)