19
19
use function explode ;
20
20
use function gettype ;
21
21
use function implode ;
22
- use function in_array ;
23
22
use function is_bool ;
24
23
use function is_float ;
25
24
use function is_int ;
54
53
final class NamePrettifier
55
54
{
56
55
/**
57
- * @psalm-var list <string>
56
+ * @psalm-var array <string, int >
58
57
*/
59
58
private static array $ strings = [];
60
59
@@ -117,10 +116,10 @@ public function prettifyTestMethodName(string $name): string
117
116
118
117
$ string = (string ) preg_replace ('#\d+$# ' , '' , $ name , -1 , $ count );
119
118
120
- if (in_array ($ string , self ::$ strings, true )) {
119
+ if (array_key_exists ($ string , self ::$ strings )) {
121
120
$ name = $ string ;
122
121
} elseif ($ count === 0 ) {
123
- self ::$ strings [] = $ string ;
122
+ self ::$ strings [$ string ] = 1 ;
124
123
}
125
124
126
125
if (str_starts_with ($ name , 'test_ ' )) {
@@ -136,13 +135,15 @@ public function prettifyTestMethodName(string $name): string
136
135
$ name [0 ] = strtoupper ($ name [0 ]);
137
136
138
137
$ noUnderscore = str_replace ('_ ' , ' ' , $ name );
138
+
139
139
if ($ noUnderscore !== $ name ) {
140
140
return trim ($ noUnderscore );
141
141
}
142
142
143
143
$ wasNumeric = false ;
144
144
145
145
$ buffer = '' ;
146
+
146
147
foreach (range (0 , strlen ($ name ) - 1 ) as $ i ) {
147
148
if ($ i > 0 && $ name [$ i ] >= 'A ' && $ name [$ i ] <= 'Z ' ) {
148
149
$ buffer .= ' ' . strtolower ($ name [$ i ]);
0 commit comments