Skip to content

Commit 51e6f6a

Browse files
authored
Merge pull request #9343 from samsonasik/refactor-add-arrow-function-return
refactor: enable AddArrowFunctionReturnTypeRector
2 parents 51cdd7d + 47d69b6 commit 51e6f6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+130
-128
lines changed

app/Views/errors/cli/error_exception.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
$function .= $padClass . $error['function'];
5151
}
5252

53-
$args = implode(', ', array_map(static fn ($value) => match (true) {
53+
$args = implode(', ', array_map(static fn ($value): string => match (true) {
5454
is_object($value) => 'Object(' . $value::class . ')',
5555
is_array($value) => $value !== [] ? '[...]' : '[]',
5656
$value === null => 'null', // return the lowercased version

rector.php

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
4242
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
4343
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
44+
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
4445
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
4546
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
4647
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
@@ -201,6 +202,7 @@
201202
TypedPropertyFromAssignsRector::class,
202203
ClosureReturnTypeRector::class,
203204
FlipTypeControlToUseExclusiveTypeRector::class,
205+
AddArrowFunctionReturnTypeRector::class,
204206
])
205207
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
206208
// keep '\\' prefix string on string '\Foo\Bar'

system/CLI/CLI.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
339339
$pattern = preg_match_all('/^\d+(,\d+)*$/', trim($input));
340340

341341
// separate input by comma and convert all to an int[]
342-
$inputToArray = array_map(static fn ($value) => (int) $value, explode(',', $input));
342+
$inputToArray = array_map(static fn ($value): int => (int) $value, explode(',', $input));
343343
// find max from key of $options
344344
$maxOptions = array_key_last($options);
345345
// find max from input

system/Commands/Utilities/Routes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function run(array $params)
187187

188188
// Sort by Handler.
189189
if ($sortByHandler) {
190-
usort($tbody, static fn ($handler1, $handler2) => strcmp($handler1[3], $handler2[3]));
190+
usort($tbody, static fn ($handler1, $handler2): int => strcmp($handler1[3], $handler2[3]));
191191
}
192192

193193
if ($host !== null) {

system/Database/BaseBuilder.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
20182018
$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $keys) . ")\n{:_table_:}ON DUPLICATE KEY UPDATE\n" . implode(
20192019
",\n",
20202020
array_map(
2021-
static fn ($key, $value) => $table . '.' . $key . ($value instanceof RawSql ?
2021+
static fn ($key, $value): string => $table . '.' . $key . ($value instanceof RawSql ?
20222022
' = ' . $value :
20232023
' = VALUES(' . $value . ')'),
20242024
array_keys($updateFields),
@@ -2108,7 +2108,7 @@ public function onConstraint($set)
21082108
if (is_string($set)) {
21092109
$set = explode(',', $set);
21102110

2111-
$set = array_map(static fn ($key) => trim($key), $set);
2111+
$set = array_map(static fn ($key): string => trim($key), $set);
21122112
}
21132113

21142114
if ($set instanceof RawSql) {
@@ -2152,7 +2152,7 @@ public function setQueryAsData($query, ?string $alias = null, $columns = null):
21522152
if (is_string($query)) {
21532153
if ($columns !== null && is_string($columns)) {
21542154
$columns = explode(',', $columns);
2155-
$columns = array_map(static fn ($key) => trim($key), $columns);
2155+
$columns = array_map(static fn ($key): string => trim($key), $columns);
21562156
}
21572157

21582158
$columns = (array) $columns;
@@ -2190,7 +2190,7 @@ protected function fieldsFromQuery(string $sql): array
21902190
*/
21912191
protected function formatValues(array $values): array
21922192
{
2193-
return array_map(static fn ($index) => '(' . implode(',', $index) . ')', $values);
2193+
return array_map(static fn ($index): string => '(' . implode(',', $index) . ')', $values);
21942194
}
21952195

21962196
/**
@@ -2649,7 +2649,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
26492649
$sql .= implode(
26502650
",\n",
26512651
array_map(
2652-
static fn ($key, $value) => $key . ($value instanceof RawSql ?
2652+
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
26532653
' = ' . $value :
26542654
' = ' . $alias . '.' . $value),
26552655
array_keys($updateFields),
@@ -2691,8 +2691,8 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
26912691
$data = implode(
26922692
" UNION ALL\n",
26932693
array_map(
2694-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
2695-
static fn ($key, $index) => $index . ' ' . $key,
2694+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
2695+
static fn ($key, $index): string => $index . ' ' . $key,
26962696
$keys,
26972697
$value
26982698
)),
@@ -2946,8 +2946,8 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
29462946
$data = implode(
29472947
" UNION ALL\n",
29482948
array_map(
2949-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
2950-
static fn ($key, $index) => $index . ' ' . $key,
2949+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
2950+
static fn ($key, $index): string => $index . ' ' . $key,
29512951
$keys,
29522952
$value
29532953
)),

system/Database/Forge.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ protected function _alterTable(string $alterType, string $table, $processedField
861861
$columnNamesToDrop = explode(',', $columnNamesToDrop);
862862
}
863863

864-
$columnNamesToDrop = array_map(fn ($field) => 'DROP COLUMN ' . $this->db->escapeIdentifiers(trim($field)), $columnNamesToDrop);
864+
$columnNamesToDrop = array_map(fn ($field): string => 'DROP COLUMN ' . $this->db->escapeIdentifiers(trim($field)), $columnNamesToDrop);
865865

866866
return $sql . implode(', ', $columnNamesToDrop);
867867
}

system/Database/MySQLi/Builder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
115115
$sql .= implode(
116116
",\n",
117117
array_map(
118-
static fn ($key, $value) => $table . '.' . $key . ($value instanceof RawSql ?
118+
static fn ($key, $value): string => $table . '.' . $key . ($value instanceof RawSql ?
119119
' = ' . $value :
120120
' = ' . $alias . '.' . $value),
121121
array_keys($updateFields),
@@ -132,8 +132,8 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
132132
$data = implode(
133133
" UNION ALL\n",
134134
array_map(
135-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
136-
static fn ($key, $index) => $index . ' ' . $key,
135+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
136+
static fn ($key, $index): string => $index . ' ' . $key,
137137
$keys,
138138
$value
139139
)),

system/Database/OCI8/Builder.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ protected function _insertBatch(string $table, array $keys, array $values): stri
8989
$data = implode(
9090
" FROM DUAL UNION ALL\n",
9191
array_map(
92-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
93-
static fn ($key, $index) => $index . ' ' . $key,
92+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
93+
static fn ($key, $index): string => $index . ' ' . $key,
9494
$keys,
9595
$value
9696
)),
@@ -107,7 +107,7 @@ protected function _insertBatch(string $table, array $keys, array $values): stri
107107
*/
108108
protected function _replace(string $table, array $keys, array $values): string
109109
{
110-
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '"'), $keys);
110+
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '"'), $keys);
111111

112112
$uniqueIndexes = array_filter($this->db->getIndexData($table), static function ($index) use ($fieldNames): bool {
113113
$hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields);
@@ -126,24 +126,24 @@ protected function _replace(string $table, array $keys, array $values): string
126126

127127
$sql = 'MERGE INTO ' . $table . "\n USING (SELECT ";
128128

129-
$sql .= implode(', ', array_map(static fn ($columnName, $value) => $value . ' ' . $columnName, $keys, $values));
129+
$sql .= implode(', ', array_map(static fn ($columnName, $value): string => $value . ' ' . $columnName, $keys, $values));
130130

131131
$sql .= ' FROM DUAL) "_replace" ON ( ';
132132

133133
$onList = [];
134134
$onList[] = '1 != 1';
135135

136136
foreach ($uniqueIndexes as $index) {
137-
$onList[] = '(' . implode(' AND ', array_map(static fn ($columnName) => $table . '."' . $columnName . '" = "_replace"."' . $columnName . '"', $index->fields)) . ')';
137+
$onList[] = '(' . implode(' AND ', array_map(static fn ($columnName): string => $table . '."' . $columnName . '" = "_replace"."' . $columnName . '"', $index->fields)) . ')';
138138
}
139139

140140
$sql .= implode(' OR ', $onList) . ') WHEN MATCHED THEN UPDATE SET ';
141141

142-
$sql .= implode(', ', array_map(static fn ($columnName) => $columnName . ' = "_replace".' . $columnName, $replaceableFields));
142+
$sql .= implode(', ', array_map(static fn ($columnName): string => $columnName . ' = "_replace".' . $columnName, $replaceableFields));
143143

144144
$sql .= ' WHEN NOT MATCHED THEN INSERT (' . implode(', ', $replaceableFields) . ') VALUES ';
145145

146-
return $sql . (' (' . implode(', ', array_map(static fn ($columnName) => '"_replace".' . $columnName, $replaceableFields)) . ')');
146+
return $sql . (' (' . implode(', ', array_map(static fn ($columnName): string => '"_replace".' . $columnName, $replaceableFields)) . ')');
147147
}
148148

149149
/**
@@ -298,7 +298,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
298298
$sql .= implode(
299299
",\n",
300300
array_map(
301-
static fn ($key, $value) => $table . '.' . $key . ($value instanceof RawSql ?
301+
static fn ($key, $value): string => $table . '.' . $key . ($value instanceof RawSql ?
302302
' = ' . $value :
303303
' = ' . $alias . '.' . $value),
304304
array_keys($updateFields),
@@ -315,8 +315,8 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
315315
$data = implode(
316316
" UNION ALL\n",
317317
array_map(
318-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
319-
static fn ($key, $index) => $index . ' ' . $key,
318+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
319+
static fn ($key, $index): string => $index . ' ' . $key,
320320
$keys,
321321
$value
322322
)) . ' FROM DUAL',
@@ -342,7 +342,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
342342
$constraints = $this->QBOptions['constraints'] ?? [];
343343

344344
if (empty($constraints)) {
345-
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '"'), $keys);
345+
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '"'), $keys);
346346

347347
$uniqueIndexes = array_filter($this->db->getIndexData($table), static function ($index) use ($fieldNames): bool {
348348
$hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields);
@@ -401,7 +401,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
401401
$sql .= implode(
402402
",\n",
403403
array_map(
404-
static fn ($key, $value) => $key . ($value instanceof RawSql ?
404+
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
405405
" = {$value}" :
406406
" = {$alias}.{$value}"),
407407
array_keys($updateFields),
@@ -412,7 +412,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
412412
$sql .= "\nWHEN NOT MATCHED THEN INSERT (" . implode(', ', $keys) . ")\nVALUES ";
413413

414414
$sql .= (' ('
415-
. implode(', ', array_map(static fn ($columnName) => "{$alias}.{$columnName}", $keys))
415+
. implode(', ', array_map(static fn ($columnName): string => "{$alias}.{$columnName}", $keys))
416416
. ')');
417417

418418
$this->QBOptions['sql'] = $sql;
@@ -424,8 +424,8 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
424424
$data = implode(
425425
" FROM DUAL UNION ALL\n",
426426
array_map(
427-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
428-
static fn ($key, $index) => $index . ' ' . $key,
427+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
428+
static fn ($key, $index): string => $index . ' ' . $key,
429429
$keys,
430430
$value
431431
)),
@@ -503,8 +503,8 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
503503
$data = implode(
504504
" FROM DUAL UNION ALL\n",
505505
array_map(
506-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
507-
static fn ($key, $index) => $index . ' ' . $key,
506+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
507+
static fn ($key, $index): string => $index . ' ' . $key,
508508
$keys,
509509
$value
510510
)),

system/Database/OCI8/Result.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getFieldCount(): int
3737
*/
3838
public function getFieldNames(): array
3939
{
40-
return array_map(fn ($fieldIndex) => oci_field_name($this->resultID, $fieldIndex), range(1, $this->getFieldCount()));
40+
return array_map(fn ($fieldIndex): false|string => oci_field_name($this->resultID, $fieldIndex), range(1, $this->getFieldCount()));
4141
}
4242

4343
/**

system/Database/Postgre/Builder.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
353353
$sql .= implode(
354354
",\n",
355355
array_map(
356-
static fn ($key, $value) => $key . ($value instanceof RawSql ?
356+
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
357357
' = ' . $value :
358358
' = ' . $that->cast($alias . '.' . $value, $that->getFieldType($table, $key))),
359359
array_keys($updateFields),
@@ -394,8 +394,8 @@ static function ($key, $value) use ($table, $alias, $that): string|RawSql {
394394
$data = implode(
395395
" UNION ALL\n",
396396
array_map(
397-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
398-
static fn ($key, $index) => $index . ' ' . $key,
397+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
398+
static fn ($key, $index): string => $index . ' ' . $key,
399399
$keys,
400400
$value
401401
)),
@@ -458,7 +458,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
458458

459459
// if this is the first iteration of batch then we need to build skeleton sql
460460
if ($sql === '') {
461-
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '"'), $keys);
461+
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '"'), $keys);
462462

463463
$constraints = $this->QBOptions['constraints'] ?? [];
464464

@@ -524,7 +524,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
524524
$sql .= implode(
525525
",\n",
526526
array_map(
527-
static fn ($key, $value) => $key . ($value instanceof RawSql ?
527+
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
528528
" = {$value}" :
529529
" = {$alias}.{$value}"),
530530
array_keys($updateFields),
@@ -617,8 +617,8 @@ static function ($key, $value) use ($table, $alias, $that): RawSql|string {
617617
$data = implode(
618618
" UNION ALL\n",
619619
array_map(
620-
static fn ($value) => 'SELECT ' . implode(', ', array_map(
621-
static fn ($key, $index) => $index . ' ' . $key,
620+
static fn ($value): string => 'SELECT ' . implode(', ', array_map(
621+
static fn ($key, $index): string => $index . ' ' . $key,
622622
$keys,
623623
$value
624624
)),

system/Database/Postgre/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ protected function _indexData(string $table): array
371371
$obj = new stdClass();
372372
$obj->name = $row->indexname;
373373
$_fields = explode(',', preg_replace('/^.*\((.+?)\)$/', '$1', trim($row->indexdef)));
374-
$obj->fields = array_map(static fn ($v) => trim($v), $_fields);
374+
$obj->fields = array_map(static fn ($v): string => trim($v), $_fields);
375375

376376
if (str_starts_with($row->indexdef, 'CREATE UNIQUE INDEX pk')) {
377377
$obj->type = 'PRIMARY';

system/Database/Query.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public function debugToolbarDisplay(): string
418418
*/
419419
$search = '/\b(?:' . implode('|', $highlight) . ')\b(?![^(')]*'(?:(?:[^(')]*'){2})*[^(')]*$)/';
420420

421-
return preg_replace_callback($search, static fn ($matches) => '<strong>' . str_replace(' ', '&nbsp;', $matches[0]) . '</strong>', $sql);
421+
return preg_replace_callback($search, static fn ($matches): string => '<strong>' . str_replace(' ', '&nbsp;', $matches[0]) . '</strong>', $sql);
422422
}
423423

424424
/**

system/Database/SQLSRV/Builder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
694694

695695
$identityInFields = in_array($tableIdentity, $keys, true);
696696

697-
$fieldNames = array_map(static fn ($columnName) => trim($columnName, '"'), $keys);
697+
$fieldNames = array_map(static fn ($columnName): string => trim($columnName, '"'), $keys);
698698

699699
if (empty($constraints)) {
700700
$tableIndexes = $this->db->getIndexData($table);
@@ -773,7 +773,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
773773
$sql .= implode(
774774
",\n",
775775
array_map(
776-
static fn ($key, $value) => $key . ($value instanceof RawSql ?
776+
static fn ($key, $value): string => $key . ($value instanceof RawSql ?
777777
' = ' . $value :
778778
" = {$alias}.{$value}"),
779779
array_keys($updateFields),
@@ -787,7 +787,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
787787
'(' . implode(
788788
', ',
789789
array_map(
790-
static fn ($columnName) => $columnName === $tableIdentity
790+
static fn ($columnName): string => $columnName === $tableIdentity
791791
? "CASE WHEN {$alias}.{$columnName} IS NULL THEN (SELECT "
792792
. 'isnull(IDENT_CURRENT(\'' . $fullTableName . '\')+IDENT_INCR(\''
793793
. $fullTableName . "'),1)) ELSE {$alias}.{$columnName} END"

0 commit comments

Comments
 (0)