Skip to content

Commit a3ddbb1

Browse files
committed
TypeString::normalizeCase(): normalize FQN true/false/null to unqualified
Includes tests.
1 parent f0a8295 commit a3ddbb1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

PHPCSUtils/Utils/TypeString.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public static function isKeyword($type)
137137
* Normalize the case for a single type.
138138
*
139139
* - Types which are recognized PHP "keyword" types will be returned in lowercase.
140+
* - Types which are recognized PHP "keyword" types and can be fully qualified (true/false/null)
141+
* will be returned as unqualified.
140142
* - Class/Interface/Enum names will be returned in their original case.
141143
*
142144
* @since 1.1.0
@@ -152,7 +154,7 @@ public static function normalizeCase($type)
152154
}
153155

154156
if (self::isKeyword($type)) {
155-
return \strtolower($type);
157+
return \strtolower(\ltrim($type, '\\'));
156158
}
157159

158160
return $type;

Tests/Utils/TypeString/NormalizeCaseTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ public static function dataNormalizeCase()
135135
];
136136
}
137137

138+
$data['true: fully qualified'] = [
139+
'type' => '\true',
140+
'expected' => 'true',
141+
];
142+
$data['false: fully qualified'] = [
143+
'type' => '\false',
144+
'expected' => 'false',
145+
];
146+
$data['null: fully qualified'] = [
147+
'type' => '\null',
148+
'expected' => 'null',
149+
];
150+
$data['true: fully qualified, uppercase'] = [
151+
'type' => '\TRUE',
152+
'expected' => 'true',
153+
];
154+
$data['false: fully qualified, uppercase'] = [
155+
'type' => '\FALSE',
156+
'expected' => 'false',
157+
];
158+
$data['null: fully qualified, uppercase'] = [
159+
'type' => '\NULL',
160+
'expected' => 'null',
161+
];
162+
138163
$data['Classname: UnqualifiedName'] = [
139164
'type' => 'UnqualifiedName',
140165
'expected' => 'UnqualifiedName',

0 commit comments

Comments
 (0)