Merge pull request #9343 from samsonasik/refactor-add-arrow-function-return

refactor: enable AddArrowFunctionReturnTypeRector
This commit is contained in:
Abdul Malik Ikhsan 2024-12-29 03:59:02 +07:00 committed by GitHub
commit 51e6f6aa03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
51 changed files with 130 additions and 128 deletions

View File

@ -50,7 +50,7 @@ if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) {
$function .= $padClass . $error['function'];
}
$args = implode(', ', array_map(static fn ($value) => match (true) {
$args = implode(', ', array_map(static fn ($value): string => match (true) {
is_object($value) => 'Object(' . $value::class . ')',
is_array($value) => $value !== [] ? '[...]' : '[]',
$value === null => 'null', // return the lowercased version

View File

@ -41,6 +41,7 @@ use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
@ -201,6 +202,7 @@ return RectorConfig::configure()
TypedPropertyFromAssignsRector::class,
ClosureReturnTypeRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
AddArrowFunctionReturnTypeRector::class,
])
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
// keep '\\' prefix string on string '\Foo\Bar'

View File

@ -339,7 +339,7 @@ class CLI
$pattern = preg_match_all('/^\d+(,\d+)*$/', trim($input));
// separate input by comma and convert all to an int[]
$inputToArray = array_map(static fn ($value) => (int) $value, explode(',', $input));
$inputToArray = array_map(static fn ($value): int => (int) $value, explode(',', $input));
// find max from key of $options
$maxOptions = array_key_last($options);
// find max from input

View File

@ -187,7 +187,7 @@ class Routes extends BaseCommand
// Sort by Handler.
if ($sortByHandler) {
usort($tbody, static fn ($handler1, $handler2) => strcmp($handler1[3], $handler2[3]));
usort($tbody, static fn ($handler1, $handler2): int => strcmp($handler1[3], $handler2[3]));
}
if ($host !== null) {

View File

@ -2018,7 +2018,7 @@ class BaseBuilder
$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $keys) . ")\n{:_table_:}ON DUPLICATE KEY UPDATE\n" . implode(
",\n",
array_map(
static fn ($key, $value) => $table . '.' . $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $table . '.' . $key . ($value instanceof RawSql ?
' = ' . $value :
' = VALUES(' . $value . ')'),
array_keys($updateFields),
@ -2108,7 +2108,7 @@ class BaseBuilder
if (is_string($set)) {
$set = explode(',', $set);
$set = array_map(static fn ($key) => trim($key), $set);
$set = array_map(static fn ($key): string => trim($key), $set);
}
if ($set instanceof RawSql) {
@ -2152,7 +2152,7 @@ class BaseBuilder
if (is_string($query)) {
if ($columns !== null && is_string($columns)) {
$columns = explode(',', $columns);
$columns = array_map(static fn ($key) => trim($key), $columns);
$columns = array_map(static fn ($key): string => trim($key), $columns);
}
$columns = (array) $columns;
@ -2190,7 +2190,7 @@ class BaseBuilder
*/
protected function formatValues(array $values): array
{
return array_map(static fn ($index) => '(' . implode(',', $index) . ')', $values);
return array_map(static fn ($index): string => '(' . implode(',', $index) . ')', $values);
}
/**
@ -2649,7 +2649,7 @@ class BaseBuilder
$sql .= implode(
",\n",
array_map(
static fn ($key, $value) => $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
' = ' . $value :
' = ' . $alias . '.' . $value),
array_keys($updateFields),
@ -2691,8 +2691,8 @@ class BaseBuilder
$data = implode(
" UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),
@ -2946,8 +2946,8 @@ class BaseBuilder
$data = implode(
" UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),

View File

@ -861,7 +861,7 @@ class Forge
$columnNamesToDrop = explode(',', $columnNamesToDrop);
}
$columnNamesToDrop = array_map(fn ($field) => 'DROP COLUMN ' . $this->db->escapeIdentifiers(trim($field)), $columnNamesToDrop);
$columnNamesToDrop = array_map(fn ($field): string => 'DROP COLUMN ' . $this->db->escapeIdentifiers(trim($field)), $columnNamesToDrop);
return $sql . implode(', ', $columnNamesToDrop);
}

View File

@ -115,7 +115,7 @@ class Builder extends BaseBuilder
$sql .= implode(
",\n",
array_map(
static fn ($key, $value) => $table . '.' . $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $table . '.' . $key . ($value instanceof RawSql ?
' = ' . $value :
' = ' . $alias . '.' . $value),
array_keys($updateFields),
@ -132,8 +132,8 @@ class Builder extends BaseBuilder
$data = implode(
" UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),

View File

@ -89,8 +89,8 @@ class Builder extends BaseBuilder
$data = implode(
" FROM DUAL UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),
@ -107,7 +107,7 @@ class Builder extends BaseBuilder
*/
protected function _replace(string $table, array $keys, array $values): string
{
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '"'), $keys);
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '"'), $keys);
$uniqueIndexes = array_filter($this->db->getIndexData($table), static function ($index) use ($fieldNames): bool {
$hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields);
@ -126,7 +126,7 @@ class Builder extends BaseBuilder
$sql = 'MERGE INTO ' . $table . "\n USING (SELECT ";
$sql .= implode(', ', array_map(static fn ($columnName, $value) => $value . ' ' . $columnName, $keys, $values));
$sql .= implode(', ', array_map(static fn ($columnName, $value): string => $value . ' ' . $columnName, $keys, $values));
$sql .= ' FROM DUAL) "_replace" ON ( ';
@ -134,16 +134,16 @@ class Builder extends BaseBuilder
$onList[] = '1 != 1';
foreach ($uniqueIndexes as $index) {
$onList[] = '(' . implode(' AND ', array_map(static fn ($columnName) => $table . '."' . $columnName . '" = "_replace"."' . $columnName . '"', $index->fields)) . ')';
$onList[] = '(' . implode(' AND ', array_map(static fn ($columnName): string => $table . '."' . $columnName . '" = "_replace"."' . $columnName . '"', $index->fields)) . ')';
}
$sql .= implode(' OR ', $onList) . ') WHEN MATCHED THEN UPDATE SET ';
$sql .= implode(', ', array_map(static fn ($columnName) => $columnName . ' = "_replace".' . $columnName, $replaceableFields));
$sql .= implode(', ', array_map(static fn ($columnName): string => $columnName . ' = "_replace".' . $columnName, $replaceableFields));
$sql .= ' WHEN NOT MATCHED THEN INSERT (' . implode(', ', $replaceableFields) . ') VALUES ';
return $sql . (' (' . implode(', ', array_map(static fn ($columnName) => '"_replace".' . $columnName, $replaceableFields)) . ')');
return $sql . (' (' . implode(', ', array_map(static fn ($columnName): string => '"_replace".' . $columnName, $replaceableFields)) . ')');
}
/**
@ -298,7 +298,7 @@ class Builder extends BaseBuilder
$sql .= implode(
",\n",
array_map(
static fn ($key, $value) => $table . '.' . $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $table . '.' . $key . ($value instanceof RawSql ?
' = ' . $value :
' = ' . $alias . '.' . $value),
array_keys($updateFields),
@ -315,8 +315,8 @@ class Builder extends BaseBuilder
$data = implode(
" UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)) . ' FROM DUAL',
@ -342,7 +342,7 @@ class Builder extends BaseBuilder
$constraints = $this->QBOptions['constraints'] ?? [];
if (empty($constraints)) {
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '"'), $keys);
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '"'), $keys);
$uniqueIndexes = array_filter($this->db->getIndexData($table), static function ($index) use ($fieldNames): bool {
$hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields);
@ -401,7 +401,7 @@ class Builder extends BaseBuilder
$sql .= implode(
",\n",
array_map(
static fn ($key, $value) => $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
" = {$value}" :
" = {$alias}.{$value}"),
array_keys($updateFields),
@ -412,7 +412,7 @@ class Builder extends BaseBuilder
$sql .= "\nWHEN NOT MATCHED THEN INSERT (" . implode(', ', $keys) . ")\nVALUES ";
$sql .= (' ('
. implode(', ', array_map(static fn ($columnName) => "{$alias}.{$columnName}", $keys))
. implode(', ', array_map(static fn ($columnName): string => "{$alias}.{$columnName}", $keys))
. ')');
$this->QBOptions['sql'] = $sql;
@ -424,8 +424,8 @@ class Builder extends BaseBuilder
$data = implode(
" FROM DUAL UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),
@ -503,8 +503,8 @@ class Builder extends BaseBuilder
$data = implode(
" FROM DUAL UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),

View File

@ -37,7 +37,7 @@ class Result extends BaseResult
*/
public function getFieldNames(): array
{
return array_map(fn ($fieldIndex) => oci_field_name($this->resultID, $fieldIndex), range(1, $this->getFieldCount()));
return array_map(fn ($fieldIndex): false|string => oci_field_name($this->resultID, $fieldIndex), range(1, $this->getFieldCount()));
}
/**

View File

@ -353,7 +353,7 @@ class Builder extends BaseBuilder
$sql .= implode(
",\n",
array_map(
static fn ($key, $value) => $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
' = ' . $value :
' = ' . $that->cast($alias . '.' . $value, $that->getFieldType($table, $key))),
array_keys($updateFields),
@ -394,8 +394,8 @@ class Builder extends BaseBuilder
$data = implode(
" UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),
@ -458,7 +458,7 @@ class Builder extends BaseBuilder
// if this is the first iteration of batch then we need to build skeleton sql
if ($sql === '') {
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '"'), $keys);
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '"'), $keys);
$constraints = $this->QBOptions['constraints'] ?? [];
@ -524,7 +524,7 @@ class Builder extends BaseBuilder
$sql .= implode(
",\n",
array_map(
static fn ($key, $value) => $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
" = {$value}" :
" = {$alias}.{$value}"),
array_keys($updateFields),
@ -617,8 +617,8 @@ class Builder extends BaseBuilder
$data = implode(
" UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),

View File

@ -371,7 +371,7 @@ class Connection extends BaseConnection
$obj = new stdClass();
$obj->name = $row->indexname;
$_fields = explode(',', preg_replace('/^.*\((.+?)\)$/', '$1', trim($row->indexdef)));
$obj->fields = array_map(static fn ($v) => trim($v), $_fields);
$obj->fields = array_map(static fn ($v): string => trim($v), $_fields);
if (str_starts_with($row->indexdef, 'CREATE UNIQUE INDEX pk')) {
$obj->type = 'PRIMARY';

View File

@ -418,7 +418,7 @@ class Query implements QueryInterface, Stringable
*/
$search = '/\b(?:' . implode('|', $highlight) . ')\b(?![^(')]*'(?:(?:[^(')]*'){2})*[^(')]*$)/';
return preg_replace_callback($search, static fn ($matches) => '<strong>' . str_replace(' ', '&nbsp;', $matches[0]) . '</strong>', $sql);
return preg_replace_callback($search, static fn ($matches): string => '<strong>' . str_replace(' ', '&nbsp;', $matches[0]) . '</strong>', $sql);
}
/**

View File

@ -694,7 +694,7 @@ class Builder extends BaseBuilder
$identityInFields = in_array($tableIdentity, $keys, true);
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '"'), $keys);
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '"'), $keys);
if (empty($constraints)) {
$tableIndexes = $this->db->getIndexData($table);
@ -773,7 +773,7 @@ class Builder extends BaseBuilder
$sql .= implode(
",\n",
array_map(
static fn ($key, $value) => $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
' = ' . $value :
" = {$alias}.{$value}"),
array_keys($updateFields),
@ -787,7 +787,7 @@ class Builder extends BaseBuilder
'(' . implode(
', ',
array_map(
static fn ($columnName) => $columnName === $tableIdentity
static fn ($columnName): string => $columnName === $tableIdentity
? "CASE WHEN {$alias}.{$columnName} IS NULL THEN (SELECT "
. 'isnull(IDENT_CURRENT(\'' . $fullTableName . '\')+IDENT_INCR(\''
. $fullTableName . "'),1)) ELSE {$alias}.{$columnName} END"

View File

@ -257,7 +257,7 @@ class Connection extends BaseConnection
$obj->name = $row->index_name;
$_fields = explode(',', trim($row->index_keys));
$obj->fields = array_map(static fn ($v) => trim($v), $_fields);
$obj->fields = array_map(static fn ($v): string => trim($v), $_fields);
if (str_contains($row->index_description, 'primary key located on')) {
$obj->type = 'PRIMARY';

View File

@ -225,7 +225,7 @@ class Forge extends BaseForge
$sql = 'ALTER TABLE ' . $fullTable . ' DROP ';
$fields = array_map(static fn ($item) => 'COLUMN [' . trim($item) . ']', (array) $columnNamesToDrop);
$fields = array_map(static fn ($item): string => 'COLUMN [' . trim($item) . ']', (array) $columnNamesToDrop);
return $sql . implode(',', $fields);
}
@ -380,7 +380,7 @@ class Forge extends BaseForge
// https://learn.microsoft.com/en-us/sql/t-sql/data-types/char-and-varchar-transact-sql?view=sql-server-ver16#remarks
$maxLength = max(
array_map(
static fn ($value) => strlen($value),
static fn ($value): int => strlen($value),
$attributes['CONSTRAINT']
)
);

View File

@ -143,7 +143,7 @@ class Builder extends BaseBuilder
$constraints = $this->QBOptions['constraints'] ?? [];
if (empty($constraints)) {
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '`'), $keys);
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '`'), $keys);
$allIndexes = array_filter($this->db->getIndexData($table), static function ($index) use ($fieldNames): bool {
$hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields);
@ -179,7 +179,7 @@ class Builder extends BaseBuilder
$sql = 'INSERT INTO ' . $table . ' (';
$sql .= implode(', ', array_map(static fn ($columnName) => $columnName, $keys));
$sql .= implode(', ', array_map(static fn ($columnName): string => $columnName, $keys));
$sql .= ")\n";
@ -192,7 +192,7 @@ class Builder extends BaseBuilder
$sql .= implode(
",\n",
array_map(
static fn ($key, $value) => $key . ($value instanceof RawSql ?
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
" = {$value}" :
" = {$alias}.{$value}"),
array_keys($updateFields),
@ -265,8 +265,8 @@ class Builder extends BaseBuilder
$data = implode(
" UNION ALL\n",
array_map(
static fn ($value) => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index) => $index . ' ' . $key,
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
static fn ($key, $index): string => $index . ' ' . $key,
$keys,
$value
)),

View File

@ -113,7 +113,7 @@ class Table
$this->keys = array_merge($this->keys, $this->formatKeys($this->db->getIndexData($table)));
// if primary key index exists twice then remove psuedo index name 'primary'.
$primaryIndexes = array_filter($this->keys, static fn ($index) => $index['type'] === 'primary');
$primaryIndexes = array_filter($this->keys, static fn ($index): bool => $index['type'] === 'primary');
if ($primaryIndexes !== [] && count($primaryIndexes) > 1 && array_key_exists('primary', $this->keys)) {
unset($this->keys['primary']);
@ -202,7 +202,7 @@ class Table
*/
public function dropPrimaryKey(): Table
{
$primaryIndexes = array_filter($this->keys, static fn ($index) => strtolower($index['type']) === 'primary');
$primaryIndexes = array_filter($this->keys, static fn ($index): bool => strtolower($index['type']) === 'primary');
foreach (array_keys($primaryIndexes) as $key) {
unset($this->keys[$key]);
@ -235,7 +235,7 @@ class Table
*/
public function addPrimaryKey(array $fields): Table
{
$primaryIndexes = array_filter($this->keys, static fn ($index) => strtolower($index['type']) === 'primary');
$primaryIndexes = array_filter($this->keys, static fn ($index): bool => strtolower($index['type']) === 'primary');
// if primary key already exists we can't add another one
if ($primaryIndexes !== []) {
@ -308,7 +308,7 @@ class Table
$this->keys = array_filter(
$this->keys,
static fn ($index) => count(array_intersect($index['fields'], $fieldNames)) === count($index['fields'])
static fn ($index): bool => count(array_intersect($index['fields'], $fieldNames)) === count($index['fields'])
);
// Unique/Index keys

View File

@ -218,7 +218,7 @@ class Database extends BaseCollector
$this->getConnections();
$queryCount = count(static::$queries);
$uniqueCount = count(array_filter(static::$queries, static fn ($query) => $query['duplicate'] === false));
$uniqueCount = count(array_filter(static::$queries, static fn ($query): bool => $query['duplicate'] === false));
$connectionCount = count($this->connections);
return sprintf(

View File

@ -181,7 +181,7 @@ class Entity implements JsonSerializable
{
$this->_cast = $cast;
$keys = array_filter(array_keys($this->attributes), static fn ($key) => ! str_starts_with($key, '_'));
$keys = array_filter(array_keys($this->attributes), static fn ($key): bool => ! str_starts_with($key, '_'));
if (is_array($this->datamap)) {
$keys = array_unique(

View File

@ -108,7 +108,7 @@ class FileCollection implements Countable, IteratorAggregate
$pattern = "#\\A{$pattern}\\z#";
}
return array_filter($files, static fn ($value) => (bool) preg_match($pattern, basename($value)));
return array_filter($files, static fn ($value): bool => (bool) preg_match($pattern, basename($value)));
}
// --------------------------------------------------------------------

View File

@ -1021,7 +1021,7 @@ class URI implements Stringable
// Encode characters
$path = preg_replace_callback(
'/(?:[^' . static::CHAR_UNRESERVED . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
static fn (array $matches) => rawurlencode($matches[0]),
static fn (array $matches): string => rawurlencode($matches[0]),
$path
);
@ -1167,9 +1167,9 @@ class URI implements Stringable
$return = [];
$query = explode('&', $query);
$params = array_map(static fn (string $chunk) => preg_replace_callback(
$params = array_map(static fn (string $chunk): ?string => preg_replace_callback(
'/^(?<key>[^&=]+?)(?:\[[^&=]*\])?=(?<value>[^&=]+)/',
static fn (array $match) => str_replace($match['key'], bin2hex($match['key']), $match[0]),
static fn (array $match): string => str_replace($match['key'], bin2hex($match['key']), $match[0]),
urldecode($chunk)
), $query);

View File

@ -58,7 +58,7 @@ final class ArrayHelper
);
return array_map(
static fn ($key) => str_replace('\.', '.', $key),
static fn ($key): string => str_replace('\.', '.', $key),
$segments
);
}
@ -96,7 +96,7 @@ final class ArrayHelper
$answer[] = self::arraySearchDot($indexes, $value);
}
$answer = array_filter($answer, static fn ($value) => $value !== null);
$answer = array_filter($answer, static fn ($value): bool => $value !== null);
if ($answer !== []) {
// If array only has one element, we return that element for BC.

View File

@ -739,10 +739,10 @@ if (! function_exists('validation_show_error')) {
$config = config(Validation::class);
$view = service('renderer');
$errors = array_filter(validation_errors(), static fn ($key) => preg_match(
$errors = array_filter(validation_errors(), static fn ($key): bool => preg_match(
'/^' . str_replace(['\.\*', '\*\.'], ['\..+', '.+\.'], preg_quote($field, '/')) . '$/',
$key
), ARRAY_FILTER_USE_KEY);
) === 1, ARRAY_FILTER_USE_KEY);
if ($errors === []) {
return '';

View File

@ -206,11 +206,11 @@ class Language
$argsString = implode(
', ',
array_map(static fn ($element) => '"' . $element . '"', $args)
array_map(static fn ($element): string => '"' . $element . '"', $args)
);
$argsUrlEncoded = implode(
', ',
array_map(static fn ($element) => '"' . rawurlencode($element) . '"', $args)
array_map(static fn ($element): string => '"' . rawurlencode($element) . '"', $args)
);
log_message(

View File

@ -184,7 +184,7 @@ final class AutoRouter implements AutoRouterInterface
*/
private function scanControllers(array $segments): array
{
$segments = array_filter($segments, static fn ($segment) => $segment !== '');
$segments = array_filter($segments, static fn ($segment): bool => $segment !== '');
// numerically reindex the array, removing gaps
$segments = array_values($segments);

View File

@ -136,7 +136,7 @@ final class AutoRouterImproved implements AutoRouterInterface
private function createSegments(string $uri): array
{
$segments = explode('/', $uri);
$segments = array_filter($segments, static fn ($segment) => $segment !== '');
$segments = array_filter($segments, static fn ($segment): bool => $segment !== '');
// numerically reindex the array, removing gaps
return array_values($segments);
@ -209,7 +209,7 @@ final class AutoRouterImproved implements AutoRouterInterface
}
$namespaces = array_map(
fn ($segment) => $this->translateURI($segment),
fn ($segment): string => $this->translateURI($segment),
$segments
);

View File

@ -1504,7 +1504,7 @@ class RouteCollection implements RouteCollectionInterface
for ($i = (int) $options['offset'] + 1; $i < (int) $options['offset'] + 7; $i++) {
$to = preg_replace_callback(
'/\$X/',
static fn ($m) => '$' . $i,
static fn ($m): string => '$' . $i,
$to,
1
);

View File

@ -590,7 +590,7 @@ class Router implements RouterInterface
*/
protected function scanControllers(array $segments): array
{
$segments = array_filter($segments, static fn ($segment) => $segment !== '');
$segments = array_filter($segments, static fn ($segment): bool => $segment !== '');
// numerically reindex the array, removing gaps
$segments = array_values($segments);

View File

@ -41,7 +41,7 @@ trait ReflectionHelper
$refMethod = new ReflectionMethod($obj, $method);
$obj = (gettype($obj) === 'object') ? $obj : null;
return static fn (...$args) => $refMethod->invokeArgs($obj, $args);
return static fn (...$args): mixed => $refMethod->invokeArgs($obj, $args);
}
/**

View File

@ -32,7 +32,7 @@ final class DotArrayFilter
foreach ($indexes as $index) {
$segments = preg_split('/(?<!\\\\)\./', $index, -1, PREG_SPLIT_NO_EMPTY);
$segments = array_map(static fn ($key) => str_replace('\.', '.', $key), $segments);
$segments = array_map(static fn ($key): string => str_replace('\.', '.', $key), $segments);
$filteredArray = self::filter($segments, $array);

View File

@ -176,7 +176,7 @@ class Validation implements ValidationInterface
$values = array_filter(
$flattenedArray,
static fn ($key) => preg_match(self::getRegex($field), $key),
static fn ($key): bool => preg_match(self::getRegex($field), $key) === 1,
ARRAY_FILTER_USE_KEY
);
@ -413,7 +413,7 @@ class Validation implements ValidationInterface
}
// Otherwise remove the if_exist rule and continue the process
$rules = array_filter($rules, static fn ($rule) => $rule instanceof Closure || $rule !== 'if_exist');
$rules = array_filter($rules, static fn ($rule): bool => $rule instanceof Closure || $rule !== 'if_exist');
}
return $rules;
@ -460,7 +460,7 @@ class Validation implements ValidationInterface
}
}
$rules = array_filter($rules, static fn ($rule) => $rule instanceof Closure || $rule !== 'permit_empty');
$rules = array_filter($rules, static fn ($rule): bool => $rule instanceof Closure || $rule !== 'permit_empty');
}
return $rules;
@ -867,7 +867,7 @@ class Validation implements ValidationInterface
$errors = array_filter(
$this->getErrors(),
static fn ($key) => preg_match(self::getRegex($field), $key),
static fn ($key): bool => preg_match(self::getRegex($field), $key) === 1,
ARRAY_FILTER_USE_KEY
);

View File

@ -228,13 +228,13 @@ class Table
$missingKeys = array_diff_key($keyIndex, $tmpRow);
// Remove all keys which don't exist in $keyIndex
$tmpRow = array_filter($tmpRow, static fn ($k) => array_key_exists($k, $keyIndex), ARRAY_FILTER_USE_KEY);
$tmpRow = array_filter($tmpRow, static fn ($k): bool => array_key_exists($k, $keyIndex), ARRAY_FILTER_USE_KEY);
// add missing keys to row, but use $this->emptyCells
$tmpRow = array_merge($tmpRow, array_map(fn ($v) => ['data' => $this->emptyCells], $missingKeys));
$tmpRow = array_merge($tmpRow, array_map(fn ($v): array => ['data' => $this->emptyCells], $missingKeys));
// order keys by $keyIndex values
uksort($tmpRow, static fn ($k1, $k2) => $keyIndex[$k1] <=> $keyIndex[$k2]);
uksort($tmpRow, static fn ($k1, $k2): int => $keyIndex[$k1] <=> $keyIndex[$k2]);
}
$this->rows[] = $tmpRow;

View File

@ -15,7 +15,7 @@ namespace Tests\Support\Config;
// This is a simple file to include for testing the RouteCollection class.
$routes->add('testing', 'TestController::index', ['as' => 'testing-index']);
$routes->get('closure', static fn () => 'closure test');
$routes->get('closure', static fn (): string => 'closure test');
$routes->get('/', 'Blog::index', ['hostname' => 'blog.example.com']);
$routes->get('/', 'Sub::index', ['subdomain' => 'sub']);
$routes->get('/all', 'AllDomain::index', ['subdomain' => '*']);

View File

@ -136,7 +136,7 @@ final class FrameworkCodeTest extends TestCase
$testClasses = array_filter(
$testClasses,
static fn (string $class) => is_subclass_of($class, TestCase::class)
static fn (string $class): bool => is_subclass_of($class, TestCase::class)
);
sort($testClasses);

View File

@ -42,7 +42,7 @@ final class DummyHandlerTest extends CIUnitTestCase
public function testRemember(): void
{
$dummyHandler = $this->handler->remember('key', 2, static fn () => 'value');
$dummyHandler = $this->handler->remember('key', 2, static fn (): string => 'value');
$this->assertNull($dummyHandler);
}

View File

@ -135,7 +135,7 @@ final class FileHandlerTest extends AbstractHandlerTestCase
*/
public function testRemember(): void
{
$this->handler->remember(self::$key1, 2, static fn () => 'value');
$this->handler->remember(self::$key1, 2, static fn (): string => 'value');
$this->assertSame('value', $this->handler->get(self::$key1));
$this->assertNull($this->handler->get(self::$dummy));

View File

@ -86,7 +86,7 @@ final class MemcachedHandlerTest extends AbstractHandlerTestCase
*/
public function testRemember(): void
{
$this->handler->remember(self::$key1, 2, static fn () => 'value');
$this->handler->remember(self::$key1, 2, static fn (): string => 'value');
$this->assertSame('value', $this->handler->get(self::$key1));
$this->assertNull($this->handler->get(self::$dummy));

View File

@ -91,7 +91,7 @@ final class PredisHandlerTest extends AbstractHandlerTestCase
*/
public function testRemember(): void
{
$this->handler->remember(self::$key1, 2, static fn () => 'value');
$this->handler->remember(self::$key1, 2, static fn (): string => 'value');
$this->assertSame('value', $this->handler->get(self::$key1));
$this->assertNull($this->handler->get(self::$dummy));

View File

@ -97,7 +97,7 @@ final class RedisHandlerTest extends AbstractHandlerTestCase
*/
public function testRemember(): void
{
$this->handler->remember(self::$key1, 2, static fn () => 'value');
$this->handler->remember(self::$key1, 2, static fn (): string => 'value');
$this->assertSame('value', $this->handler->get(self::$key1));
$this->assertNull($this->handler->get(self::$dummy));

View File

@ -214,7 +214,7 @@ final class CodeIgniterTest extends CIUnitTestCase
$routes = service('routes');
$routes->add(
'pages/(:segment)',
static fn ($segment) => 'You want to see "' . esc($segment) . '" page.'
static fn ($segment): string => 'You want to see "' . esc($segment) . '" page.'
);
$router = service('router', $routes, service('incomingrequest'));
Services::injectMock('router', $router);

View File

@ -47,7 +47,7 @@ final class UnionTest extends CIUnitTestCase
$builder = $this->db->table('test');
$builder->union(static fn ($builder) => $builder->from('test'));
$builder->union(static fn ($builder): BaseBuilder => $builder->from('test'));
$this->assertSame($expected, $this->buildSelect($builder));
}
@ -85,7 +85,7 @@ final class UnionTest extends CIUnitTestCase
$builder = $db->table('users');
$builder->union(static fn ($builder) => $builder->from('users'));
$builder->union(static fn ($builder): BaseBuilder => $builder->from('users'));
$this->assertSame($expected, $this->buildSelect($builder));
}

View File

@ -1707,7 +1707,7 @@ final class ForgeTest extends CIUnitTestCase
// check that db_actions_name key exists
$indexes = array_filter(
$allIndexes,
static fn ($index) => ($index->name === 'db_actions_name')
static fn ($index): bool => ($index->name === 'db_actions_name')
&& ($index->fields === [0 => 'name'])
);
$this->assertCount(1, $indexes);
@ -1715,7 +1715,7 @@ final class ForgeTest extends CIUnitTestCase
// check that db_actions_category_name key exists
$indexes = array_filter(
$allIndexes,
static fn ($index) => ($index->name === 'db_actions_category_name')
static fn ($index): bool => ($index->name === 'db_actions_category_name')
&& ($index->fields === [0 => 'category', 1 => 'name'])
);
$this->assertCount(1, $indexes);
@ -1723,7 +1723,7 @@ final class ForgeTest extends CIUnitTestCase
// check that the primary key exists
$indexes = array_filter(
$allIndexes,
static fn ($index) => $index->type === 'PRIMARY'
static fn ($index): bool => $index->type === 'PRIMARY'
);
$this->assertCount(1, $indexes);
@ -1755,7 +1755,7 @@ final class ForgeTest extends CIUnitTestCase
// check that db_actions_name key exists
$indexes = array_filter(
$allIndexes,
static fn ($index) => ($index->name === 'db_actions_name')
static fn ($index): bool => ($index->name === 'db_actions_name')
&& ($index->fields === [0 => 'name'])
);
$this->assertCount(1, $indexes);
@ -1781,7 +1781,7 @@ final class ForgeTest extends CIUnitTestCase
// check that the primary key exists
$indexes = array_filter(
$allIndexes,
static fn ($index) => $index->type === 'PRIMARY'
static fn ($index): bool => $index->type === 'PRIMARY'
);
$this->assertCount(1, $indexes);

View File

@ -157,7 +157,7 @@ final class TimerTest extends CIUnitTestCase
public function testRecordArrowFunction(): void
{
$timer = new Timer();
$returnValue = $timer->record('longjohn', static fn () => strlen('CI4'));
$returnValue = $timer->record('longjohn', static fn (): int => strlen('CI4'));
$this->assertLessThan(0.1, $timer->getElapsedTime('longjohn'));
$this->assertSame(3, $returnValue);
@ -196,7 +196,7 @@ final class TimerTest extends CIUnitTestCase
public function testCommonNoNameCallableExpectTimer(): void
{
$returnValue = timer(null, static fn () => strlen('CI4'));
$returnValue = timer(null, static fn (): int => strlen('CI4'));
$this->assertInstanceOf(Timer::class, $returnValue);
}
@ -212,7 +212,7 @@ final class TimerTest extends CIUnitTestCase
public function testCommonCallableExpectWithReturn(): void
{
$returnValue = timer('common', static fn () => strlen('CI4'));
$returnValue = timer('common', static fn (): int => strlen('CI4'));
$this->assertNotInstanceOf(Timer::class, $returnValue);
$this->assertSame(3, $returnValue);

View File

@ -441,7 +441,7 @@ final class ContentSecurityPolicyTest extends CIUnitTestCase
$result = $this->work($body);
$nonceStyle = array_filter(
$this->getPrivateProperty($this->csp, 'styleSrc'),
static fn ($value) => str_starts_with($value, 'nonce-')
static fn ($value): bool => str_starts_with($value, 'nonce-')
);
$this->assertStringContainsString('nonce=', $this->response->getBody());
@ -516,7 +516,7 @@ final class ContentSecurityPolicyTest extends CIUnitTestCase
$result = $this->work($body);
$nonceScript = array_filter(
$this->getPrivateProperty($this->csp, 'scriptSrc'),
static fn ($value) => str_starts_with($value, 'nonce-')
static fn ($value): bool => str_starts_with($value, 'nonce-')
);
$this->assertStringContainsString('nonce=', $this->response->getBody());

View File

@ -51,8 +51,8 @@ final class DefinedRouteCollectorTest extends CIUnitTestCase
$routes->get('journals', 'Blogs');
$routes->get('100', 'Home::index');
$routes->get('product/(:num)', 'Catalog::productLookupByID/$1');
$routes->get('feed', static fn () => 'A Closure route.');
$routes->get('200', static fn () => 'A Closure route.');
$routes->get('feed', static fn (): string => 'A Closure route.');
$routes->get('200', static fn (): string => 'A Closure route.');
$routes->view('about', 'pages/about');
$collector = new DefinedRouteCollector($routes);

View File

@ -68,8 +68,8 @@ final class RouterTest extends CIUnitTestCase
'posts/(:num)' => 'Blog::show/$1',
'posts/(:num)/edit' => 'Blog::edit/$1',
'books/(:num)/(:alpha)/(:num)' => 'Blog::show/$3/$1',
'closure/(:num)/(:alpha)' => static fn ($num, $str) => $num . '-' . $str,
'closure-dash/(:num)/(:alpha)' => static fn ($num, $str) => $num . '-' . $str,
'closure/(:num)/(:alpha)' => static fn ($num, $str): string => $num . '-' . $str,
'closure-dash/(:num)/(:alpha)' => static fn ($num, $str): string => $num . '-' . $str,
'{locale}/pages' => 'App\Pages::list_all',
'test/(:any)/lang/{locale}' => 'App\Pages::list_all',
'admin/admins' => 'App\Admin\Admins::list_all',

View File

@ -54,7 +54,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'GET',
'home',
static fn () => 'Hello World',
static fn (): string => 'Hello World',
],
]);
$response = $this->get('home');
@ -74,7 +74,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'GET',
'foo/bar/1/2/3',
static fn () => 'Hello World',
static fn (): string => 'Hello World',
],
]);
$response = $this->get('foo/bar/1/2/3');
@ -90,7 +90,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'GET',
'admin',
static fn () => 'Admin Area',
static fn (): string => 'Admin Area',
['filter' => 'test-redirectfilter'],
],
]);
@ -123,7 +123,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'POST',
'home',
static fn () => 'Hello Mars',
static fn (): string => 'Hello Mars',
],
]);
$response = $this->post('home');
@ -137,7 +137,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'POST',
'home',
static fn () => 'Hello ' . service('request')->getPost('foo') . '!',
static fn (): string => 'Hello ' . service('request')->getPost('foo') . '!',
],
]);
$response = $this->post('home', ['foo' => 'Mars']);
@ -181,7 +181,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'PUT',
'home',
static fn () => 'Hello Pluto',
static fn (): string => 'Hello Pluto',
],
]);
$response = $this->put('home');
@ -195,7 +195,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'PATCH',
'home',
static fn () => 'Hello Jupiter',
static fn (): string => 'Hello Jupiter',
],
]);
$response = $this->patch('home');
@ -209,7 +209,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'OPTIONS',
'home',
static fn () => 'Hello George',
static fn (): string => 'Hello George',
],
]);
$response = $this->options('home');
@ -223,7 +223,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'DELETE',
'home',
static fn () => 'Hello Wonka',
static fn (): string => 'Hello Wonka',
],
]);
$response = $this->delete('home');
@ -237,7 +237,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'GET',
'home',
static fn () => 'Home',
static fn (): string => 'Home',
],
])->withSession([
'fruit' => 'apple',
@ -259,7 +259,7 @@ final class FeatureTestTraitTest extends CIUnitTestCase
[
'GET',
'home',
static fn () => 'Home',
static fn (): string => 'Home',
],
])->withSession()->get('home');

View File

@ -119,7 +119,7 @@ class RulesTest extends CIUnitTestCase
],
// Testing with closure
[
['foo' => ['if_exist', static fn ($value) => true]],
['foo' => ['if_exist', static fn ($value): bool => true]],
['foo' => []],
true,
],
@ -299,7 +299,7 @@ class RulesTest extends CIUnitTestCase
],
[
// Testing with closure
['foo' => ['permit_empty', static fn ($value) => true]],
['foo' => ['permit_empty', static fn ($value): bool => true]],
['foo' => ''],
true,
],

View File

@ -91,7 +91,7 @@ final class RulesTest extends TraditionalRulesTest
],
// Testing with closure
[
['foo' => ['permit_empty', static fn ($value) => true]],
['foo' => ['permit_empty', static fn ($value): bool => true]],
['foo' => ''],
true,
],

View File

@ -284,7 +284,7 @@ class ValidationTest extends CIUnitTestCase
{
$this->validation->setRules(
[
'foo' => ['required', static fn ($value) => $value === 'abc'],
'foo' => ['required', static fn ($value): bool => $value === 'abc'],
],
[
// Errors
@ -339,7 +339,7 @@ class ValidationTest extends CIUnitTestCase
$this->validation->setRules([
'secret' => [
'label' => 'シークレット',
'rules' => ['required', static fn ($value) => $value === 'abc'],
'rules' => ['required', static fn ($value): bool => $value === 'abc'],
'errors' => [
// Specify the array key for the closure rule.
1 => 'The {field} is invalid',

View File

@ -797,7 +797,7 @@ final class ParserTest extends CIUnitTestCase
public function testParserPluginClosure(): void
{
$config = $this->config;
$config->plugins['hello'] = static fn (array $params = []) => 'Hello, ' . trim($params[0]);
$config->plugins['hello'] = static fn (array $params = []): string => 'Hello, ' . trim($params[0]);
$this->parser = new Parser($config, $this->viewsDir, $this->loader);
@ -828,7 +828,7 @@ final class ParserTest extends CIUnitTestCase
public function testParserSingleTag(): void
{
$this->parser->addPlugin('hit:it', static fn () => 'Hip to the Hop', false);
$this->parser->addPlugin('hit:it', static fn (): string => 'Hip to the Hop', false);
$template = '{+ hit:it +}';
@ -837,7 +837,7 @@ final class ParserTest extends CIUnitTestCase
public function testParserSingleTagWithParams(): void
{
$this->parser->addPlugin('hit:it', static fn (array $params = []) => "{$params['first']} to the {$params['last']}", false);
$this->parser->addPlugin('hit:it', static fn (array $params = []): string => "{$params['first']} to the {$params['last']}", false);
$template = '{+ hit:it first=foo last=bar +}';
@ -846,7 +846,7 @@ final class ParserTest extends CIUnitTestCase
public function testParserSingleTagWithSingleParams(): void
{
$this->parser->addPlugin('hit:it', static fn (array $params = []) => "{$params[0]} to the {$params[1]}", false);
$this->parser->addPlugin('hit:it', static fn (array $params = []): string => "{$params[0]} to the {$params[1]}", false);
$template = '{+ hit:it foo bar +}';