Skip to content

Commit

Permalink
Merge pull request #7924 from Sesquipedalian/more_cs-fixer_tweaks
Browse files Browse the repository at this point in the history
More PHP-CS-Fixer tweaks
  • Loading branch information
Sesquipedalian authored Nov 28, 2023
2 parents b51c0b2 + 07606db commit 16483a1
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 62 deletions.
61 changes: 47 additions & 14 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,27 @@
return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,

// PSR12 overrides.
'no_closing_tag' => false,
'concat_space' => ['spacing' => 'one'],
'no_break_comment' => false, // A bit buggy with comments.
'statement_indentation' => false, // A bit buggy with comments.

// Array notation.
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'no_leading_namespace_whitespace' => true,
'no_trailing_comma_in_singleline' => true,
'normalize_index_brace' => true,
'whitespace_after_comma_in_array' => true,

// Basic.
'no_trailing_comma_in_singleline' => true,

// Casing.
'class_reference_name_casing' => true,

// Cast notation.
'cast_spaces' => ['space' => 'single'],
'single_line_comment_spacing' => true,

// Control structure.
'include' => true,
'no_superfluous_elseif' => true,
'no_useless_else' => true,
Expand All @@ -63,18 +66,40 @@
'parameters',
],
],

// Function notation.
'lambda_not_used_import' => true,
'nullable_type_declaration_for_default_null_value' => true,
'nullable_type_declaration' => ['syntax' => 'question_mark'],

// Import.
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],

// Language construct.
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'nullable_type_declaration' => ['syntax' => 'question_mark'],

// Namespace notation.
'no_leading_namespace_whitespace' => true,

// Operator.
'concat_space' => ['spacing' => 'one'],
'operator_linebreak' => [
'only_booleans' => true,
'position' => 'beginning',
],
'standardize_not_equals' => true,
'ternary_to_null_coalescing' => true,

// PHPDoc.
'phpdoc_indent' => true,
'phpdoc_line_span' => [
'const' => 'multi',
Expand Down Expand Up @@ -110,14 +135,22 @@
'groups' => ['alias', 'meta', 'simple'],
],
'phpdoc_var_without_name' => true,

// Return notation.
'no_useless_return' => true,
'simplified_null_return' => true,
'no_empty_statement' => true,

// Semicolon.
'multiline_whitespace_before_semicolons' => true,
'no_empty_statement' => true,
'no_singleline_whitespace_before_semicolons' => true,

// String notation.
'explicit_string_variable' => true,
'simple_to_complex_string_variable' => true,
'single_quote' => true,

// Whitespace.
'array_indentation' => true,
'blank_line_before_statement' => [
'statements' => [
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Admin/ACP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,8 @@ function ($type) {
switch ($type) {
case 'multiple':
$config_multis[$var] = $def['type'];

// no break

case 'double':
$config_nums[] = $var;
break;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Admin/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2868,7 +2868,7 @@ protected function setGroupContext(): void
Utils::$context['group']['name'] = Lang::$txt['membergroups_members'];
break;

// Can't set permissions for admins.
// Can't set permissions for admins.
case 1:
Utils::redirectexit('action=admin;area=permissions');
break;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Actions/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ protected function setAlertPref()
$this->alert_pref = self::PREF_BOTH;
break;

// self::MODE_NO_EMAIL is used to turn off email notifications
// while leaving the alert preference unchanged.
// self::MODE_NO_EMAIL is used to turn off email notifications
// while leaving the alert preference unchanged.
case self::MODE_NO_EMAIL:
// Use bitwise operator to turn off the email part of the setting.
$this->alert_pref = self::getNotifyPrefs($this->member_info['id'], [$this->type . '_notify_' . $this->id], true) & self::PREF_ALERT;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Actions/Profile/GroupMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function save(): void

return;

// Leaving/joining a group.
// Leaving/joining a group.
case 'free':
// Are they leaving?
if (Profile::$member->group_id == $new_group_id) {
Expand All @@ -249,7 +249,7 @@ public function save(): void

break;

// Finally, we must be setting the primary.
// Finally, we must be setting the primary.
default:
if (Profile::$member->group_id != 0) {
$new_additional_groups[] = Profile::$member->group_id;
Expand Down
2 changes: 1 addition & 1 deletion Sources/BBCodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ public function unparse(string $string): string
$replacement .= '[font=' . strtr($style_value, ["'" => '']) . ']';
break;

// This is a hack for images with dimensions embedded.
// This is a hack for images with dimensions embedded.
case 'width':
case 'height':
if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2895,12 +2895,12 @@ public static function memoryReturnBytes(string $val): int
switch ($last) {
case 'g':
$num *= 1024;

// no break

case 'm':
$num *= 1024;

// no break

case 'k':
$num *= 1024;
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ public function __set(string $prop, $value): void
case 'start_second':
case 'end_second':
$this->{$start_end}->second = $value;

// no break

case 'start_timestamp':
case 'end_timestamp':
$this->{$start_end}->timestamp = $value;
Expand Down Expand Up @@ -576,7 +576,7 @@ public function __set(string $prop, $value): void
$value = $this->setNumDays($value);
break;

// These computed properties are read-only.
// These computed properties are read-only.
case 'tz_abbrev':
case 'new':
case 'is_selected':
Expand Down
8 changes: 4 additions & 4 deletions Sources/Graphics/Gif/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function load($data, &$datLen)

break;

// Image...
// Image...
case 0x2C:
// Load the header and color table.
$len = 0;
Expand Down Expand Up @@ -117,16 +117,16 @@ public function skipExt(&$data, &$extLen)
$this->m_nTrans = ord($data[4]);
break;

// Comment...
// Comment...
case 0xFE:
$this->m_lpComm = substr($data, 1, ord($data[0]));
break;

// Plain text...
// Plain text...
case 0x01:
break;

// Application...
// Application...
case 0xFF:
break;
}
Expand Down
26 changes: 13 additions & 13 deletions Sources/Graphics/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,51 +924,51 @@ protected function getSvgDimensions(): void
case 'px':
break;

// Points.
// Points.
case 'pt':
$$dimension *= 0.75;
break;

// Picas.
// Picas.
case 'pc':
$$dimension *= 16;
break;

// Inches.
// Inches.
case 'in':
$$dimension *= 96;
break;

// Centimetres.
// Centimetres.
case 'cm':
$$dimension *= 37.8;
break;

// Millimetres.
// Millimetres.
case 'mm':
$$dimension *= 3.78;
break;

// Font height.
// Assume browser default of 1em = 1pc.
// Font height.
// Assume browser default of 1em = 1pc.
case 'em':
$$dimension *= 16;
break;

// Font x-height.
// Assume half of font height.
// Font x-height.
// Assume half of font height.
case 'ex':
$$dimension *= 8;
break;

// Font '0' character width.
// Assume a typical monospace font at 1em = 1pc.
// Font '0' character width.
// Assume a typical monospace font at 1em = 1pc.
case 'ch':
$$dimension *= 9.6;
break;

// Percentage.
// SVG spec says to use viewBox dimensions in this case.
// Percentage.
// SVG spec says to use viewBox dimensions in this case.
default:
unset($$dimension);
break;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -1111,12 +1111,12 @@ public static function lock(): void

break;

// Was locked by a regular user, so unlock it.
// Was locked by a regular user, so unlock it.
case 1:
$poll->voting_locked = 0;
break;

// Not locked, so lock it.
// Not locked, so lock it.
default:
// Remember whether this was locked by moderator or a regular user.
$poll->voting_locked = User::$me->allowedTo('moderate_board') ? 2 : 1;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Search/APIs/Custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function supportsMethod($methodName, $query_params = null): bool
$return = true;
break;

// All other methods, too bad dunno you.
// All other methods, too bad dunno you.
default:
$return = false;
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Search/APIs/Fulltext.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function supportsMethod($methodName, $query_params = null): bool
$return = true;
break;

// All other methods, too bad dunno you.
// All other methods, too bad dunno you.
default:
$return = false;
break;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Search/SearchApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function supportsMethod($methodName, $query_params = []): bool
case 'getQueryParams':
return true;

// All other methods, too bad dunno you.
// All other methods, too bad dunno you.
default:
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/Subs-Compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* @version 3.0 Alpha 1
*/

use SMF\Config;
use SMF\Lang;
use SMF\Punycode;

if (!defined('SMF')) {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,12 @@ public static function addJavaScriptVar($key, $value, $escape = false)
case 'resource':
break;

// Convert PHP objects to arrays before processing.
// Convert PHP objects to arrays before processing.
case 'object':
$value = (array) $value;

// Apply Utils::JavaScriptEscape() to any strings in the array.
// no break

// Apply Utils::JavaScriptEscape() to any strings in the array.
case 'array':
$replacements = [];
array_walk_recursive(
Expand Down
Loading

0 comments on commit 16483a1

Please sign in to comment.