Skip to content

Commit bdee9de

Browse files
staabmsebastianbergmann
authored andcommitted
use faster array_key_exists()
1 parent fc22b11 commit bdee9de

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Logging/TestDox/NamePrettifier.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use function explode;
2020
use function gettype;
2121
use function implode;
22-
use function in_array;
2322
use function is_bool;
2423
use function is_float;
2524
use function is_int;
@@ -54,7 +53,7 @@
5453
final class NamePrettifier
5554
{
5655
/**
57-
* @psalm-var list<string>
56+
* @psalm-var array<string, int>
5857
*/
5958
private static array $strings = [];
6059

@@ -117,10 +116,10 @@ public function prettifyTestMethodName(string $name): string
117116

118117
$string = (string) preg_replace('#\d+$#', '', $name, -1, $count);
119118

120-
if (in_array($string, self::$strings, true)) {
119+
if (array_key_exists($string, self::$strings)) {
121120
$name = $string;
122121
} elseif ($count === 0) {
123-
self::$strings[] = $string;
122+
self::$strings[$string] = 1;
124123
}
125124

126125
if (str_starts_with($name, 'test_')) {
@@ -136,13 +135,15 @@ public function prettifyTestMethodName(string $name): string
136135
$name[0] = strtoupper($name[0]);
137136

138137
$noUnderscore = str_replace('_', ' ', $name);
138+
139139
if ($noUnderscore !== $name) {
140140
return trim($noUnderscore);
141141
}
142142

143143
$wasNumeric = false;
144144

145145
$buffer = '';
146+
146147
foreach (range(0, strlen($name) - 1) as $i) {
147148
if ($i > 0 && $name[$i] >= 'A' && $name[$i] <= 'Z') {
148149
$buffer .= ' ' . strtolower($name[$i]);

0 commit comments

Comments
 (0)