Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates PHP-CS-Fixer rules from PSR-12 to PER, and applies them #8370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
new \SMF\Fixer\Whitespace\closing_tag_fixer(),
])
->setRules([
'@PSR12' => true,
'@PER-CS2.0' => true,

// A custom fixer for us to apply our line endings.
'SMF/closing_tag_fixer' => true,
Expand Down
4 changes: 1 addition & 3 deletions Sources/ActionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public static function call(): void
/**
* Constructor. Protected to force instantiation via self::load().
*/
protected function __construct()
{
}
protected function __construct() {}
}

?>
4 changes: 2 additions & 2 deletions Sources/Actions/Admin/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ public static function init_inline_permissions(array $permissions, array $exclud
Group::load([], $query_customizations),
);

Group::loadPermissionsBatch(array_map(fn ($group) => $group->id, $groups), 0);
Group::loadPermissionsBatch(array_map(fn($group) => $group->id, $groups), 0);

foreach ($permissions as $permission) {
foreach ($groups as $group) {
Expand Down Expand Up @@ -2221,7 +2221,7 @@ public static function updateChildPermissions(int|array|null $parents = null, ?i
$child_groups = array_merge($child_groups, array_keys($parent_group->children));
}

$parents = array_map(fn ($parent_group) => $parent_group->id, $parent_groups);
$parents = array_map(fn($parent_group) => $parent_group->id, $parent_groups);

// Not a sausage, or a child?
if (empty($children)) {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Actions/Admin/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function boardAccess(): void
$this->setKeys('rows', $groups);
$this->newTable(Lang::$txt['gr_type_board_access'], '—', 'all', '100', 'center', '200', 'left');
$this->addData($groups);
uasort($data, fn ($a, $b) => $a['col'] <=> $b['col']);
uasort($data, fn($a, $b) => $a['col'] <=> $b['col']);

foreach ($data as $d) {
$this->addData($d);
Expand Down Expand Up @@ -391,7 +391,7 @@ public function boardPerms(): void
Group::LOAD_NORMAL | (int) !empty(Config::$modSettings['permission_enable_postgroups']),
[Group::ADMIN],
);
Group::loadPermissionsBatch(array_map(fn ($group) => $group->id, $group_data), null, true);
Group::loadPermissionsBatch(array_map(fn($group) => $group->id, $group_data), null, true);

// Certain permissions should not really be shown.
$disabled_permissions = [];
Expand Down Expand Up @@ -434,7 +434,7 @@ public function boardPerms(): void
$this->newTable(Utils::$context['profiles'][$id_profile]['name'], '&mdash;', 'all', '100', 'center', '200', 'left');

$this->addData($groups);
uasort($board_profile_data, fn ($a, $b) => $a['col'] <=> $b['col']);
uasort($board_profile_data, fn($a, $b) => $a['col'] <=> $b['col']);

foreach ($board_profile_data as $d) {
$this->addData($d);
Expand Down Expand Up @@ -494,7 +494,7 @@ public function groupPerms(): void
Group::LOAD_NORMAL | (int) !empty(Config::$modSettings['permission_enable_postgroups']),
[Group::ADMIN, Group::MOD],
);
Group::loadPermissionsBatch(array_map(fn ($group) => $group->id, $group_data), 0);
Group::loadPermissionsBatch(array_map(fn($group) => $group->id, $group_data), 0);

// Certain permissions should not really be shown.
$disabled_permissions = [];
Expand Down Expand Up @@ -537,7 +537,7 @@ public function groupPerms(): void
$this->setKeys('rows', $groups);
$this->newTable(Lang::$txt['gr_type_group_perms'], '&mdash;', 'all', '100', 'center', '200', 'left');
$this->addData($groups);
uasort($data, fn ($a, $b) => $a['col'] <=> $b['col']);
uasort($data, fn($a, $b) => $a['col'] <=> $b['col']);

foreach ($data as $d) {
$this->addData($d);
Expand Down Expand Up @@ -862,7 +862,7 @@ protected function finishTables(): void

$this->tables[$id]['column_count'] = array_reduce(
$table['data'],
fn (int $accumulator, $data): int => max($accumulator, count($data)),
fn(int $accumulator, $data): int => max($accumulator, count($data)),
0,
);

Expand Down
8 changes: 4 additions & 4 deletions Sources/Actions/Admin/Smileys.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function editSets(): void
}

self::$smiley_sets[$_POST['smiley_sets_path']] = [
'id' => max(array_map(fn ($set) => $set['id'], self::$smiley_sets)) + 1,
'id' => max(array_map(fn($set) => $set['id'], self::$smiley_sets)) + 1,
'raw_path' => $_POST['smiley_sets_path'],
'raw_name' => $_POST['smiley_sets_name'],
'path' => Utils::htmlspecialchars($_POST['smiley_sets_path']),
Expand Down Expand Up @@ -407,7 +407,7 @@ public function editSets(): void
// Creating a new set, but there are no available directories.
// Therefore, show the UI for making a new directory.
if (Utils::$context['current_set']['is_new']) {
Utils::$context['make_new'] = array_filter(Utils::$context['smiley_set_dirs'], fn ($dir) => $dir['selectable']) === [];
Utils::$context['make_new'] = array_filter(Utils::$context['smiley_set_dirs'], fn($dir) => $dir['selectable']) === [];
}
}
}
Expand Down Expand Up @@ -595,7 +595,7 @@ public function add(): void

// Uploading just one smiley for all of them?
if (isset($_POST['sameall'], $_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') {
$filename_array = array_merge($filename_array, $this->moveImageIntoPlace($_FILES['uploadSmiley']['name'], $_FILES['uploadSmiley']['tmp_name'], array_map(fn ($set) => $set['raw_path'], self::$smiley_sets)));
$filename_array = array_merge($filename_array, $this->moveImageIntoPlace($_FILES['uploadSmiley']['name'], $_FILES['uploadSmiley']['tmp_name'], array_map(fn($set) => $set['raw_path'], self::$smiley_sets)));
}
// What about uploading several files?
elseif ($_POST['method'] != 'existing') {
Expand Down Expand Up @@ -2058,7 +2058,7 @@ public static function getConfigVars(): array
'',

// array('select', 'smiley_sets_default', self::$smiley_sets),
['select', 'smiley_sets_default', array_map(fn ($set) => $set['raw_name'], self::$smiley_sets)],
['select', 'smiley_sets_default', array_map(fn($set) => $set['raw_name'], self::$smiley_sets)],
['check', 'smiley_sets_enable'],
['check', 'smiley_enable', 'subtext' => Lang::$txt['smileys_enable_note']],
['text', 'smileys_url', 40],
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function select(): void
Utils::$context['groups'] = Group::load($groups);

// Count the members in each group.
$groups_to_count = array_map(fn ($group) => $group->id, Utils::$context['groups']);
$groups_to_count = array_map(fn($group) => $group->id, Utils::$context['groups']);

// Counting all the regular members could be a performance hit on large forums,
// so don't do that for anyone without high level permissions.
Expand Down
3 changes: 1 addition & 2 deletions Sources/Actions/AttachmentDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ public function execute(): void
}

// No access if you don't have permission to see this attachment.
if
(
if (
// This was from SMF or a hook didn't claim it.
(
empty($file->source)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/BoardIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public static function get(array $board_index_options): array

// Find all boards and categories, as well as related information.
foreach (Board::queryData($selects, $params, $joins, $where, $order) as $row_board) {
$row_board = array_filter($row_board, fn ($prop) => !is_null($prop));
$row_board = array_filter($row_board, fn($prop) => !is_null($prop));

$parent = Board::$loaded[$row_board['id_parent']] ?? null;

Expand Down
14 changes: 7 additions & 7 deletions Sources/Actions/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,12 @@ public function clock(): void
$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
Utils::$context['linktree'][] = ['url' => Config::$scripturl . '?action=calendar;sa=clock;time=' . $_REQUEST['time'], 'name' => 'Requested Time'];
Utils::$context['clockicons'] = [
'year' => array_fill_keys(array_map(fn ($p) => 2 ** $p, range(6, 0)), false),
'mon' => array_fill_keys(array_map(fn ($p) => 2 ** $p, range(3, 0)), false),
'mday' => array_fill_keys(array_map(fn ($p) => 2 ** $p, range(4, 0)), false),
'hours' => array_fill_keys(array_map(fn ($p) => 2 ** $p, range(5, 0)), false),
'minutes' => array_fill_keys(array_map(fn ($p) => 2 ** $p, range(5, 0)), false),
'seconds' => array_fill_keys(array_map(fn ($p) => 2 ** $p, range(5, 0)), false),
'year' => array_fill_keys(array_map(fn($p) => 2 ** $p, range(6, 0)), false),
'mon' => array_fill_keys(array_map(fn($p) => 2 ** $p, range(3, 0)), false),
'mday' => array_fill_keys(array_map(fn($p) => 2 ** $p, range(4, 0)), false),
'hours' => array_fill_keys(array_map(fn($p) => 2 ** $p, range(5, 0)), false),
'minutes' => array_fill_keys(array_map(fn($p) => 2 ** $p, range(5, 0)), false),
'seconds' => array_fill_keys(array_map(fn($p) => 2 ** $p, range(5, 0)), false),
];

foreach (Utils::$context['clockicons'] as $t => $vs) {
Expand Down Expand Up @@ -1722,7 +1722,7 @@ protected function getBoardsForExport(User $user): array
[],
);

$board_ids = array_map(fn ($row) => $row['id_board'], Db::$db->fetch_all($request));
$board_ids = array_map(fn($row) => $row['id_board'], Db::$db->fetch_all($request));

Db::$db->free_result($request);

Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public static function list_getMembergroups($start, $items_per_page, $sort, $mem
}

$temp = Group::load([], $query_customizations);
Group::loadModeratorsBatch(array_map(fn ($group) => $group->id, $temp));
Group::loadModeratorsBatch(array_map(fn($group) => $group->id, $temp));

foreach ($temp as $group) {
// We only list the groups they can see.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ protected function view(): void
$loaded = User::load($members);

if (count($loaded) != count($members)) {
$members = array_diff($members, array_map(fn ($member) => $member->id, $loaded));
$members = array_diff($members, array_map(fn($member) => $member->id, $loaded));

foreach ($members as $not_loaded) {
unset(Utils::$context['likers'][$not_loaded]);
Expand Down
4 changes: 1 addition & 3 deletions Sources/Actions/NotifyAnnouncements.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ class NotifyAnnouncements extends Notify
/**
* This does nothing for announcements.
*/
protected function setId(): void
{
}
protected function setId(): void {}

/**
* Converts $_GET['sa'] to $_GET['mode'].
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/PersonalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public function applyActions(): void

// Don't do labels unless we're in the inbox.
if ($this->folder !== 'inbox') {
$_REQUEST['pm_actions'] = array_filter($_REQUEST['pm_actions'], fn ($action) => $action === 'delete');
$_REQUEST['pm_actions'] = array_filter($_REQUEST['pm_actions'], fn($action) => $action === 'delete');
}

// If we are in conversation, we may need to apply this to every PM in the conversation.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Profile/GroupMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ protected function canEditPrimary(?int $new_group_id = null): bool
if (isset($new_group_id)) {
$can_edit_primary = Profile::$member->current_and_assignable_groups[$new_group_id]->can_be_primary;
} else {
$possible_primary_groups = array_filter(Profile::$member->current_and_assignable_groups, fn ($group) => !empty($group->can_be_primary));
$possible_primary_groups = array_filter(Profile::$member->current_and_assignable_groups, fn($group) => !empty($group->can_be_primary));

$can_edit_primary = !empty($possible_primary_groups);
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/Actions/QuoteFast.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use SMF\ActionInterface;
use SMF\ActionTrait;
use SMF\Config;
use SMF\Db\DatabaseApi as Db;
use SMF\IntegrationHook;
use SMF\Lang;
use SMF\Msg;
Expand Down Expand Up @@ -69,7 +68,7 @@ public function execute(): void
],
'where' => [
'{query_see_message_board}',
'm.id_msg IN ({array_int:message_list})'
'm.id_msg IN ({array_int:message_list})',
],
'order' => [],
'params' => [
Expand Down
6 changes: 3 additions & 3 deletions Sources/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public function save(bool $update_count = true): void

// Update the keys in self::$loaded.
self::$loaded = array_combine(
array_map(fn ($alert) => $alert->id, self::$loaded),
array_map(fn($alert) => $alert->id, self::$loaded),
self::$loaded,
);

Expand Down Expand Up @@ -712,13 +712,13 @@ public static function createBatch(array $props_batch = []): array

// Update the keys in self::$loaded.
self::$loaded = array_combine(
array_map(fn ($alert) => $alert->id, self::$loaded),
array_map(fn($alert) => $alert->id, self::$loaded),
self::$loaded,
);

// Update the keys in $created.
$created = array_combine(
array_map(fn ($alert) => $alert->id, $created),
array_map(fn($alert) => $alert->id, $created),
$created,
);

Expand Down
6 changes: 3 additions & 3 deletions Sources/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public static function load(array|string|int $ids, int $approval_status = self::
foreach (self::queryData($selects, $params, $from, $joins, $where, $order, $limit) as $props) {
$id = (int) $props['id_attach'];

$props = array_filter($props, fn ($prop) => !is_null($prop));
$props = array_filter($props, fn($prop) => !is_null($prop));

$loaded[$id] = new self($id, $props);
}
Expand Down Expand Up @@ -592,7 +592,7 @@ public static function loadByMsg(array|int $msgs, int $approval_status = self::A
foreach (self::queryData($selects, $params, $from, $joins, $where, $order, $limit) as $props) {
$id = (int) $props['id_attach'];

$props = array_filter($props, fn ($prop) => !is_null($prop));
$props = array_filter($props, fn($prop) => !is_null($prop));

// Don't reload unnecessarily.
if (isset(self::$loaded[$id])) {
Expand Down Expand Up @@ -652,7 +652,7 @@ public static function loadByMember(array|int $members, int $approval_status = s
foreach (self::queryData($selects, $params, $from, $joins, $where, $order, $limit) as $props) {
$id = (int) $props['id_attach'];

$props = array_filter($props, fn ($prop) => !is_null($prop));
$props = array_filter($props, fn($prop) => !is_null($prop));

// Don't reload unnecessarily.
if (isset(self::$loaded[$id])) {
Expand Down
14 changes: 7 additions & 7 deletions Sources/Autolinker.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public function detectUrls(string $string, bool $plaintext_only = false): array
$this->setEntitiesRegex();
$string = preg_replace_callback(
'~(' . $this->entities_regex . ')*(?=\s|$)~u',
fn ($matches) => str_repeat(' ', strlen($matches[0])),
fn($matches) => str_repeat(' ', strlen($matches[0])),
$string,
);

Expand All @@ -410,14 +410,14 @@ public function detectUrls(string $string, bool $plaintext_only = false): array
// 4 = Closing BBC markup element.
'(\[/\2\])' .
'~i' . ($this->encoding === 'UTF-8' ? 'u' : ''),
fn ($matches) => $matches[1] . str_repeat('x', strlen($matches[3])) . $matches[4],
fn($matches) => $matches[1] . str_repeat('x', strlen($matches[3])) . $matches[4],
$string,
);

// Overwrite all BBC markup elements.
$string = preg_replace_callback(
'~\[/?' . Parser::getBBCodeTagsRegex() . '[^\]]*\]~i' . ($this->encoding === 'UTF-8' ? 'u' : ''),
fn ($matches) => str_repeat(' ', strlen($matches[0])),
fn($matches) => str_repeat(' ', strlen($matches[0])),
$string,
);

Expand All @@ -431,14 +431,14 @@ public function detectUrls(string $string, bool $plaintext_only = false): array
// 3 = Closing 'a' markup element.
'(</a>)' .
'~i' . ($this->encoding === 'UTF-8' ? 'u' : ''),
fn ($matches) => $matches[1] . str_repeat('x', strlen($matches[2])) . $matches[3],
fn($matches) => $matches[1] . str_repeat('x', strlen($matches[2])) . $matches[3],
$string,
);

// Overwrite all HTML elements.
$string = preg_replace_callback(
'~</?(\w+)\b([^>]*)>~i' . ($this->encoding === 'UTF-8' ? 'u' : ''),
fn ($matches) => str_repeat(' ', strlen($matches[0])),
fn($matches) => str_repeat(' ', strlen($matches[0])),
$string,
);
}
Expand Down Expand Up @@ -736,7 +736,7 @@ public function fixUrlsInBBC(string $string): string
$parts[$i],
array_combine(
$detected_urls,
array_map(fn ($url) => '[' . $bbc . ']' . $url . '[/' . $bbc . ']', $detected_urls),
array_map(fn($url) => '[' . $bbc . ']' . $url . '[/' . $bbc . ']', $detected_urls),
),
);
}
Expand Down Expand Up @@ -822,7 +822,7 @@ protected function setEntitiesRegex(): void
return;
}

$this->entities_regex = '(?' . '>&(?' . '>' . Utils::buildRegex(array_map(fn ($ent) => ltrim($ent, '&'), get_html_translation_table(HTML_ENTITIES, ENT_HTML5 | ENT_QUOTES)), '~') . '|(?' . '>#(?' . '>x[0-9a-fA-F]{1,6}|\d{1,7});)))';
$this->entities_regex = '(?' . '>&(?' . '>' . Utils::buildRegex(array_map(fn($ent) => ltrim($ent, '&'), get_html_translation_table(HTML_ENTITIES, ENT_HTML5 | ENT_QUOTES)), '~') . '|(?' . '>#(?' . '>x[0-9a-fA-F]{1,6}|\d{1,7});)))';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Sources/Board.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ public function save(array $boardOptions = []): void
'insert',
'{db_prefix}moderators',
['id_board' => 'int', 'id_member' => 'int'],
array_map(fn ($mod) => [$this->id, $mod], $this->moderators),
array_map(fn($mod) => [$this->id, $mod], $this->moderators),
['id_board', 'id_member'],
);
}
Expand All @@ -690,7 +690,7 @@ public function save(array $boardOptions = []): void
'insert',
'{db_prefix}moderator_groups',
['id_board' => 'int', 'id_group' => 'int'],
array_map(fn ($mod) => [$this->id, $mod], $this->moderator_groups),
array_map(fn($mod) => [$this->id, $mod], $this->moderator_groups),
['id_board', 'id_group'],
);
}
Expand Down
Loading
Loading