mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
refactor: use first class callable on function call
This commit is contained in:
parent
86480f498a
commit
073306c0dc
@ -163,7 +163,7 @@ abstract class BaseCommand
|
||||
if ($this->arguments !== []) {
|
||||
CLI::newLine();
|
||||
CLI::write(lang('CLI.helpArguments'), 'yellow');
|
||||
$length = max(array_map('strlen', array_keys($this->arguments)));
|
||||
$length = max(array_map(strlen(...), array_keys($this->arguments)));
|
||||
|
||||
foreach ($this->arguments as $argument => $description) {
|
||||
CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description);
|
||||
@ -173,7 +173,7 @@ abstract class BaseCommand
|
||||
if ($this->options !== []) {
|
||||
CLI::newLine();
|
||||
CLI::write(lang('CLI.helpOptions'), 'yellow');
|
||||
$length = max(array_map('strlen', array_keys($this->options)));
|
||||
$length = max(array_map(strlen(...), array_keys($this->options)));
|
||||
|
||||
foreach ($this->options as $option => $description) {
|
||||
CLI::write(CLI::color($this->setPad($option, $length, 2, 2), 'green') . $description);
|
||||
|
@ -393,7 +393,7 @@ class CLI
|
||||
private static function printKeysAndValues(array $options): void
|
||||
{
|
||||
// +2 for the square brackets around the key
|
||||
$keyMaxLength = max(array_map('mb_strwidth', array_keys($options))) + 2;
|
||||
$keyMaxLength = max(array_map(mb_strwidth(...), array_keys($options))) + 2;
|
||||
|
||||
foreach ($options as $key => $description) {
|
||||
$name = str_pad(' [' . $key . '] ', $keyMaxLength + 4, ' ');
|
||||
|
@ -325,7 +325,7 @@ trait GeneratorTrait
|
||||
implode(
|
||||
'\\',
|
||||
array_map(
|
||||
'pascalize',
|
||||
pascalize(...),
|
||||
explode('\\', str_replace('/', '\\', trim($class)))
|
||||
)
|
||||
),
|
||||
|
@ -101,7 +101,7 @@ class ListCommands extends BaseCommand
|
||||
$groups[$command['group']][$title] = $command;
|
||||
}
|
||||
|
||||
$length = max(array_map('strlen', array_keys($commands)));
|
||||
$length = max(array_map(strlen(...), array_keys($commands)));
|
||||
|
||||
ksort($groups);
|
||||
|
||||
|
@ -119,8 +119,8 @@ class Routes extends BaseCommand
|
||||
$route['route'],
|
||||
$routeName,
|
||||
$route['handler'],
|
||||
implode(' ', array_map('class_basename', $filters['before'])),
|
||||
implode(' ', array_map('class_basename', $filters['after'])),
|
||||
implode(' ', array_map(class_basename(...), $filters['before'])),
|
||||
implode(' ', array_map(class_basename(...), $filters['after'])),
|
||||
];
|
||||
}
|
||||
|
||||
@ -166,8 +166,8 @@ class Routes extends BaseCommand
|
||||
// There is no `AUTO` method, but it is intentional not to get route filters.
|
||||
$filters = $filterCollector->get('AUTO', $uriGenerator->get($routes[1]));
|
||||
|
||||
$routes[] = implode(' ', array_map('class_basename', $filters['before']));
|
||||
$routes[] = implode(' ', array_map('class_basename', $filters['after']));
|
||||
$routes[] = implode(' ', array_map(class_basename(...), $filters['before']));
|
||||
$routes[] = implode(' ', array_map(class_basename(...), $filters['after']));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,8 +125,8 @@ final class AutoRouteCollector
|
||||
$filters['before'] = array_intersect($filtersLongest['before'], $filtersShortest['before']);
|
||||
$filters['after'] = array_intersect($filtersLongest['after'], $filtersShortest['after']);
|
||||
|
||||
$route['before'] = implode(' ', array_map('class_basename', $filters['before']));
|
||||
$route['after'] = implode(' ', array_map('class_basename', $filters['after']));
|
||||
$route['before'] = implode(' ', array_map(class_basename(...), $filters['before']));
|
||||
$route['after'] = implode(' ', array_map(class_basename(...), $filters['after']));
|
||||
}
|
||||
|
||||
return $routes;
|
||||
|
@ -283,7 +283,7 @@ class Cookie implements ArrayAccess, CloneableCookieInterface
|
||||
$name .= $this->getName();
|
||||
} else {
|
||||
$search = str_split(self::$reservedCharsList);
|
||||
$replace = array_map('rawurlencode', $search);
|
||||
$replace = array_map(rawurlencode(...), $search);
|
||||
|
||||
$name .= str_replace($search, $replace, $this->getName());
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ final class DataCaster
|
||||
// type[param, param2,param3]
|
||||
if (preg_match('/\A(.+)\[(.+)\]\z/', $type, $matches)) {
|
||||
$type = $matches[1];
|
||||
$params = array_map('trim', explode(',', $matches[2]));
|
||||
$params = array_map(trim(...), explode(',', $matches[2]));
|
||||
}
|
||||
|
||||
if ($isNullable && ! $this->strict) {
|
||||
|
@ -1519,7 +1519,7 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
if (! empty($this->dataCache['table_names'])) {
|
||||
$key = array_search(
|
||||
strtolower($tableName),
|
||||
array_map('strtolower', $this->dataCache['table_names']),
|
||||
array_map(strtolower(...), $this->dataCache['table_names']),
|
||||
true
|
||||
);
|
||||
|
||||
|
@ -306,7 +306,7 @@ class Forge
|
||||
if (! empty($this->db->dataCache['db_names'])) {
|
||||
$key = array_search(
|
||||
strtolower($dbName),
|
||||
array_map('strtolower', $this->db->dataCache['db_names']),
|
||||
array_map(strtolower(...), $this->db->dataCache['db_names']),
|
||||
true
|
||||
);
|
||||
if ($key !== false) {
|
||||
@ -667,7 +667,7 @@ class Forge
|
||||
if ($query && ! empty($this->db->dataCache['table_names'])) {
|
||||
$key = array_search(
|
||||
strtolower($this->db->DBPrefix . $tableName),
|
||||
array_map('strtolower', $this->db->dataCache['table_names']),
|
||||
array_map(strtolower(...), $this->db->dataCache['table_names']),
|
||||
true
|
||||
);
|
||||
|
||||
@ -729,7 +729,7 @@ class Forge
|
||||
if ($result && ! empty($this->db->dataCache['table_names'])) {
|
||||
$key = array_search(
|
||||
strtolower($this->db->DBPrefix . $tableName),
|
||||
array_map('strtolower', $this->db->dataCache['table_names']),
|
||||
array_map(strtolower(...), $this->db->dataCache['table_names']),
|
||||
true
|
||||
);
|
||||
|
||||
|
@ -686,7 +686,7 @@ class MigrationRunner
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
return array_map('intval', array_column($batches, 'batch'));
|
||||
return array_map(intval(...), array_column($batches, 'batch'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,7 +202,7 @@ class Forge extends BaseForge
|
||||
$constraint = ' CHECK(' . $this->db->escapeIdentifiers($processedField['name'])
|
||||
. ' IN ' . $processedField['length'] . ')';
|
||||
|
||||
$processedField['length'] = '(' . max(array_map('mb_strlen', explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
|
||||
$processedField['length'] = '(' . max(array_map(mb_strlen(...), explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
|
||||
} elseif (isset($this->primaryKeys['fields']) && count($this->primaryKeys['fields']) === 1 && $processedField['name'] === $this->primaryKeys['fields'][0]) {
|
||||
$processedField['unique'] = '';
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ class Forge extends BaseForge
|
||||
}
|
||||
|
||||
if (! empty($this->db->dataCache['db_names'])) {
|
||||
$key = array_search(strtolower($dbName), array_map('strtolower', $this->db->dataCache['db_names']), true);
|
||||
$key = array_search(strtolower($dbName), array_map(strtolower(...), $this->db->dataCache['db_names']), true);
|
||||
if ($key !== false) {
|
||||
unset($this->db->dataCache['db_names'][$key]);
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ class GDHandler extends BaseHandler
|
||||
|
||||
// shorthand hex, #f00
|
||||
if (strlen($color) === 3) {
|
||||
$color = implode('', array_map('str_repeat', str_split($color), [2, 2, 2]));
|
||||
$color = implode('', array_map(str_repeat(...), str_split($color), [2, 2, 2]));
|
||||
}
|
||||
|
||||
$color = str_split(substr($color, 0, 6), 2);
|
||||
|
@ -853,7 +853,7 @@ class RouteCollection implements RouteCollectionInterface
|
||||
// In order to allow customization of the route the
|
||||
// resources are sent to, we need to have a new name
|
||||
// to store the values in.
|
||||
$newName = implode('\\', array_map('ucfirst', explode('/', $name)));
|
||||
$newName = implode('\\', array_map(ucfirst(...), explode('/', $name)));
|
||||
|
||||
// If a new controller is specified, then we replace the
|
||||
// $name value with the name of the new controller.
|
||||
@ -947,7 +947,7 @@ class RouteCollection implements RouteCollectionInterface
|
||||
// In order to allow customization of the route the
|
||||
// resources are sent to, we need to have a new name
|
||||
// to store the values in.
|
||||
$newName = implode('\\', array_map('ucfirst', explode('/', $name)));
|
||||
$newName = implode('\\', array_map(ucfirst(...), explode('/', $name)));
|
||||
|
||||
// If a new controller is specified, then we replace the
|
||||
// $name value with the name of the new controller.
|
||||
|
@ -159,7 +159,7 @@ class Rules
|
||||
$value = (string) $value;
|
||||
}
|
||||
|
||||
$list = array_map('trim', explode(',', $list));
|
||||
$list = array_map(trim(...), explode(',', $list));
|
||||
|
||||
return in_array($value, $list, true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user