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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+4-4
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+3-3
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

system/Database/MigrationRunner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ public function getBatches(): array
686686
->get()
687687
->getResultArray();
688688

689-
return array_map('intval', array_column($batches, 'batch'));
689+
return array_map(intval(...), array_column($batches, 'batch'));
690690
}
691691

692692
/**

system/Database/OCI8/Forge.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ protected function _processColumn(array $processedField): string
202202
$constraint = ' CHECK(' . $this->db->escapeIdentifiers($processedField['name'])
203203
. ' IN ' . $processedField['length'] . ')';
204204

205-
$processedField['length'] = '(' . max(array_map('mb_strlen', explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
205+
$processedField['length'] = '(' . max(array_map(mb_strlen(...), explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
206206
} elseif (isset($this->primaryKeys['fields']) && count($this->primaryKeys['fields']) === 1 && $processedField['name'] === $this->primaryKeys['fields'][0]) {
207207
$processedField['unique'] = '';
208208
}

system/Database/SQLite3/Forge.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function dropDatabase(string $dbName): bool
101101
}
102102

103103
if (! empty($this->db->dataCache['db_names'])) {
104-
$key = array_search(strtolower($dbName), array_map('strtolower', $this->db->dataCache['db_names']), true);
104+
$key = array_search(strtolower($dbName), array_map(strtolower(...), $this->db->dataCache['db_names']), true);
105105
if ($key !== false) {
106106
unset($this->db->dataCache['db_names'][$key]);
107107
}

system/Images/Handlers/GDHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ protected function textOverlay(string $text, array $options = [], bool $isShadow
471471

472472
// shorthand hex, #f00
473473
if (strlen($color) === 3) {
474-
$color = implode('', array_map('str_repeat', str_split($color), [2, 2, 2]));
474+
$color = implode('', array_map(str_repeat(...), str_split($color), [2, 2, 2]));
475475
}
476476

477477
$color = str_split(substr($color, 0, 6), 2);

system/Router/RouteCollection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ public function resource(string $name, ?array $options = null): RouteCollectionI
853853
// In order to allow customization of the route the
854854
// resources are sent to, we need to have a new name
855855
// to store the values in.
856-
$newName = implode('\\', array_map('ucfirst', explode('/', $name)));
856+
$newName = implode('\\', array_map(ucfirst(...), explode('/', $name)));
857857

858858
// If a new controller is specified, then we replace the
859859
// $name value with the name of the new controller.
@@ -947,7 +947,7 @@ public function presenter(string $name, ?array $options = null): RouteCollection
947947
// In order to allow customization of the route the
948948
// resources are sent to, we need to have a new name
949949
// to store the values in.
950-
$newName = implode('\\', array_map('ucfirst', explode('/', $name)));
950+
$newName = implode('\\', array_map(ucfirst(...), explode('/', $name)));
951951

952952
// If a new controller is specified, then we replace the
953953
// $name value with the name of the new controller.

system/Validation/Rules.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function in_list($value, string $list): bool
159159
$value = (string) $value;
160160
}
161161

162-
$list = array_map('trim', explode(',', $list));
162+
$list = array_map(trim(...), explode(',', $list));
163163

164164
return in_array($value, $list, true);
165165
}

0 commit comments

Comments
 (0)