Skip to content

Commit

Permalink
Use first class callables
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
  • Loading branch information
kamil-tekiela committed Mar 2, 2023
1 parent b5e5e07 commit e71b8c2
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion libraries/classes/Config/Validator.php
Expand Up @@ -8,6 +8,7 @@
namespace PhpMyAdmin\Config;

use PhpMyAdmin\Core;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Util;

use function __;
Expand Down Expand Up @@ -183,7 +184,7 @@ public static function validate(
$result[$key] = [];
}

$errorList = array_map('PhpMyAdmin\Sanitize::sanitizeMessage', (array) $errorList);
$errorList = array_map(Sanitize::sanitizeMessage(...), (array) $errorList);
$result[$key] = array_merge($result[$key], $errorList);
}
}
Expand Down
Expand Up @@ -15,6 +15,7 @@

use function array_map;
use function explode;
use function intval;
use function is_string;

final class ColumnPreferencesController extends AbstractController
Expand All @@ -41,14 +42,14 @@ public function __invoke(ServerRequest $request): void
// set column order
$colorder = $request->getParsedBodyParam('col_order');
if (is_string($colorder)) {
$propertyValue = array_map('intval', explode(',', $colorder));
$propertyValue = array_map(intval(...), explode(',', $colorder));
$status = $tableObject->setUiProp(Table::PROP_COLUMN_ORDER, $propertyValue, $tableCreateTime);
}

// set column visibility
$colvisib = $request->getParsedBodyParam('col_visib');
if ($status === true && is_string($colvisib)) {
$propertyValue = array_map('intval', explode(',', $colvisib));
$propertyValue = array_map(intval(...), explode(',', $colvisib));
$status = $tableObject->setUiProp(Table::PROP_COLUMN_ORDER, $propertyValue, $tableCreateTime);
}

Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Table/TrackingController.php
Expand Up @@ -28,6 +28,7 @@
use function is_array;
use function mb_strlen;
use function sprintf;
use function trim;

final class TrackingController extends AbstractController
{
Expand Down Expand Up @@ -114,7 +115,7 @@ public function __invoke(ServerRequest $request): void
/** @var string $users */
$users = $request->getParsedBodyParam('users', '*');

$GLOBALS['filter_users'] = array_map('trim', explode(',', $users));
$GLOBALS['filter_users'] = array_map(trim(...), explode(',', $users));
}

$dateFrom ??= new DateTimeImmutable();
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Encoding.php
Expand Up @@ -19,6 +19,7 @@
use function mb_detect_encoding;
use function mb_list_encodings;
use function recode_string;
use function strtolower;
use function tempnam;
use function unlink;

Expand Down Expand Up @@ -340,7 +341,7 @@ public static function listEncodings(): array
}

return array_intersect(
array_map('strtolower', mb_list_encodings()),
array_map(strtolower(...), mb_list_encodings()),
$GLOBALS['cfg']['AvailableCharsets'],
);
}
Expand Down
3 changes: 1 addition & 2 deletions libraries/classes/Server/Privileges.php
Expand Up @@ -233,8 +233,7 @@ public function extractPrivInfo($row = null, $enableHTML = false, $tablePrivs =
) {
// Required for proper escaping of ` (backtick) in a column name
$grantCols = array_map(
/** @param string $val */
static fn ($val): string => Util::backquote($val),
Util::backquote(...),
$GLOBALS[$currentGrant[0]],
);

Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Table.php
Expand Up @@ -36,6 +36,7 @@
use function htmlspecialchars;
use function implode;
use function in_array;
use function intval;
use function is_array;
use function is_string;
use function json_decode;
Expand Down Expand Up @@ -1832,7 +1833,7 @@ public function getUiProp($property): mixed

// check if the table has not been modified
if ($this->getStatusInfo('Create_time') == $this->uiprefs['CREATE_TIME']) {
return array_map('intval', $this->uiprefs[$property]);
return array_map(intval(...), $this->uiprefs[$property]);
}

// remove the property, since the table has been modified
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Util.php
Expand Up @@ -2509,7 +2509,7 @@ public static function isErrorReportingAvailable(): bool
$disabled = ini_get('disable_functions');
if (is_string($disabled)) {
$disabled = explode(',', $disabled);
$disabled = array_map(static fn (string $part) => trim($part), $disabled);
$disabled = array_map(trim(...), $disabled);

return ! in_array('error_reporting', $disabled);
}
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Utils/Gis.php
Expand Up @@ -7,6 +7,7 @@
use function array_map;
use function bin2hex;
use function mb_strtolower;
use function mb_strtoupper;
use function preg_match;
use function trim;

Expand Down Expand Up @@ -78,7 +79,7 @@ public static function getDataTypes($upperCase = false): array
'geometrycollection',
];
if ($upperCase) {
return array_map('mb_strtoupper', $gisDataTypes);
return array_map(mb_strtoupper(...), $gisDataTypes);
}

return $gisDataTypes;
Expand Down
2 changes: 0 additions & 2 deletions psalm-baseline.xml
Expand Up @@ -680,7 +680,6 @@
<code>$uv[$i]</code>
<code>$values[$path]</code>
<code>$vid</code>
<code>(array) $errorList</code>
<code><![CDATA[empty($values['Servers/1/controlpass']) ? '' : $values['Servers/1/controlpass']]]></code>
<code><![CDATA[empty($values['Servers/1/controluser']) ? '' : $values['Servers/1/controluser']]]></code>
<code><![CDATA[empty($values['Servers/1/host']) ? '' : $values['Servers/1/host']]]></code>
Expand Down Expand Up @@ -13903,7 +13902,6 @@
<code><![CDATA[$row['Field']]]></code>
<code><![CDATA[$row['Type']]]></code>
<code><![CDATA[$row['Type']]]></code>
<code><![CDATA[$this->uiprefs[$property]]]></code>
<code><![CDATA[$trigger['create']]]></code>
<code><![CDATA[$trigger['name']]]></code>
</MixedArrayAccess>
Expand Down

0 comments on commit e71b8c2

Please sign in to comment.