Skip to content

Commit fc5dd88

Browse files
authored
Merge pull request #9004 from samsonasik/refactor-first-class
refactor: use first class callable on function call
2 parents 86480f4 + 073306c commit fc5dd88

File tree

16 files changed

+24
-24
lines changed

16 files changed

+24
-24
lines changed

system/CLI/BaseCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function showHelp()
163163
if ($this->arguments !== []) {
164164
CLI::newLine();
165165
CLI::write(lang('CLI.helpArguments'), 'yellow');
166-
$length = max(array_map('strlen', array_keys($this->arguments)));
166+
$length = max(array_map(strlen(...), array_keys($this->arguments)));
167167

168168
foreach ($this->arguments as $argument => $description) {
169169
CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description);
@@ -173,7 +173,7 @@ public function showHelp()
173173
if ($this->options !== []) {
174174
CLI::newLine();
175175
CLI::write(lang('CLI.helpOptions'), 'yellow');
176-
$length = max(array_map('strlen', array_keys($this->options)));
176+
$length = max(array_map(strlen(...), array_keys($this->options)));
177177

178178
foreach ($this->options as $option => $description) {
179179
CLI::write(CLI::color($this->setPad($option, $length, 2, 2), 'green') . $description);

system/CLI/CLI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private static function isZeroOptions(array $options): void
393393
private static function printKeysAndValues(array $options): void
394394
{
395395
// +2 for the square brackets around the key
396-
$keyMaxLength = max(array_map('mb_strwidth', array_keys($options))) + 2;
396+
$keyMaxLength = max(array_map(mb_strwidth(...), array_keys($options))) + 2;
397397

398398
foreach ($options as $key => $description) {
399399
$name = str_pad(' [' . $key . '] ', $keyMaxLength + 4, ' ');

system/CLI/GeneratorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ private function normalizeInputClassName(): string
325325
implode(
326326
'\\',
327327
array_map(
328-
'pascalize',
328+
pascalize(...),
329329
explode('\\', str_replace('/', '\\', trim($class)))
330330
)
331331
),

system/Commands/ListCommands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function listFull(array $commands)
101101
$groups[$command['group']][$title] = $command;
102102
}
103103

104-
$length = max(array_map('strlen', array_keys($commands)));
104+
$length = max(array_map(strlen(...), array_keys($commands)));
105105

106106
ksort($groups);
107107

system/Commands/Utilities/Routes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public function run(array $params)
119119
$route['route'],
120120
$routeName,
121121
$route['handler'],
122-
implode(' ', array_map('class_basename', $filters['before'])),
123-
implode(' ', array_map('class_basename', $filters['after'])),
122+
implode(' ', array_map(class_basename(...), $filters['before'])),
123+
implode(' ', array_map(class_basename(...), $filters['after'])),
124124
];
125125
}
126126

@@ -166,8 +166,8 @@ public function run(array $params)
166166
// There is no `AUTO` method, but it is intentional not to get route filters.
167167
$filters = $filterCollector->get('AUTO', $uriGenerator->get($routes[1]));
168168

169-
$routes[] = implode(' ', array_map('class_basename', $filters['before']));
170-
$routes[] = implode(' ', array_map('class_basename', $filters['after']));
169+
$routes[] = implode(' ', array_map(class_basename(...), $filters['before']));
170+
$routes[] = implode(' ', array_map(class_basename(...), $filters['after']));
171171
}
172172
}
173173

system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ private function addFilters($routes)
125125
$filters['before'] = array_intersect($filtersLongest['before'], $filtersShortest['before']);
126126
$filters['after'] = array_intersect($filtersLongest['after'], $filtersShortest['after']);
127127

128-
$route['before'] = implode(' ', array_map('class_basename', $filters['before']));
129-
$route['after'] = implode(' ', array_map('class_basename', $filters['after']));
128+
$route['before'] = implode(' ', array_map(class_basename(...), $filters['before']));
129+
$route['after'] = implode(' ', array_map(class_basename(...), $filters['after']));
130130
}
131131

132132
return $routes;

system/Cookie/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function getPrefixedName(): string
283283
$name .= $this->getName();
284284
} else {
285285
$search = str_split(self::$reservedCharsList);
286-
$replace = array_map('rawurlencode', $search);
286+
$replace = array_map(rawurlencode(...), $search);
287287

288288
$name .= str_replace($search, $replace, $this->getName());
289289
}

system/DataCaster/DataCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function castAs(mixed $value, string $field, string $method = 'get'): mix
156156
// type[param, param2,param3]
157157
if (preg_match('/\A(.+)\[(.+)\]\z/', $type, $matches)) {
158158
$type = $matches[1];
159-
$params = array_map('trim', explode(',', $matches[2]));
159+
$params = array_map(trim(...), explode(',', $matches[2]));
160160
}
161161

162162
if ($isNullable && ! $this->strict) {

system/Database/BaseConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ public function tableExists(string $tableName, bool $cached = true): bool
15191519
if (! empty($this->dataCache['table_names'])) {
15201520
$key = array_search(
15211521
strtolower($tableName),
1522-
array_map('strtolower', $this->dataCache['table_names']),
1522+
array_map(strtolower(...), $this->dataCache['table_names']),
15231523
true
15241524
);
15251525

system/Database/Forge.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function dropDatabase(string $dbName): bool
306306
if (! empty($this->db->dataCache['db_names'])) {
307307
$key = array_search(
308308
strtolower($dbName),
309-
array_map('strtolower', $this->db->dataCache['db_names']),
309+
array_map(strtolower(...), $this->db->dataCache['db_names']),
310310
true
311311
);
312312
if ($key !== false) {
@@ -667,7 +667,7 @@ public function dropTable(string $tableName, bool $ifExists = false, bool $casca
667667
if ($query && ! empty($this->db->dataCache['table_names'])) {
668668
$key = array_search(
669669
strtolower($this->db->DBPrefix . $tableName),
670-
array_map('strtolower', $this->db->dataCache['table_names']),
670+
array_map(strtolower(...), $this->db->dataCache['table_names']),
671671
true
672672
);
673673

@@ -729,7 +729,7 @@ public function renameTable(string $tableName, string $newTableName)
729729
if ($result && ! empty($this->db->dataCache['table_names'])) {
730730
$key = array_search(
731731
strtolower($this->db->DBPrefix . $tableName),
732-
array_map('strtolower', $this->db->dataCache['table_names']),
732+
array_map(strtolower(...), $this->db->dataCache['table_names']),
733733
true
734734
);
735735

0 commit comments

Comments
 (0)