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

Modernize more basic CS #9258

Merged
merged 21 commits into from
Dec 17, 2023
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
41 changes: 16 additions & 25 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,

// required by PSR-12
'concat_space' => [
Expand Down Expand Up @@ -53,26 +55,15 @@
'use_arrow_functions' => false,

// disable too destructive formating for now
'declare_strict_types' => false,
'escape_implicit_backslashes' => false,
'heredoc_to_nowdoc' => false,
'no_useless_else' => false,
'no_useless_return' => false,
'phpdoc_no_empty_return' => false,
'phpdoc_order' => false,
'phpdoc_var_annotation_correct_order' => false,
'protected_to_private' => false,
'simple_to_complex_string_variable' => false,
'psr_autoloading' => false,
'single_line_comment_style' => false,

// enable some safe rules from @PHP71Migration:risky
'pow_to_exponentiation' => true,
'is_null' => true,
'modernize_types_casting' => true,
'dir_constant' => true,
'combine_nested_dirname' => true,
'non_printable_character' => [
'use_escape_sequences_in_strings' => true,
],
'strict_comparison' => false,
'string_length_to_empty' => false,

// TODO
'align_multiline_comment' => false,
Expand All @@ -88,18 +79,15 @@
'concat_space' => false,
'constant_case' => false,
'control_structure_continuation_position' => false,
'dir_constant' => false,
'elseif' => false,
'empty_loop_condition' => false,
'explicit_indirect_variable' => false,
'explicit_string_variable' => false,
'function_declaration' => false,
'general_phpdoc_annotation_remove' => false,
'global_namespace_import' => false,
'heredoc_indentation' => false,
'increment_style' => false,
'integer_literal_case' => false,
'is_null' => false,
'list_syntax' => false,
'method_argument_space' => false,
'method_chaining_indentation' => false,
Expand All @@ -113,18 +101,13 @@
'no_empty_statement' => false,
'no_extra_blank_lines' => false,
'no_null_property_initialization' => false,
'no_superfluous_phpdoc_tags' => false,
'no_unneeded_control_parentheses' => false,
'no_useless_concat_operator' => false,
'operator_linebreak' => false,
'php_unit_method_casing' => false,
'phpdoc_align' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_no_alias_tag' => false,
'phpdoc_no_package' => false,
'phpdoc_scalar' => false,
'phpdoc_separation' => false,
'phpdoc_single_line_var_spacing' => false,
'phpdoc_summary' => false,
'phpdoc_to_comment' => false,
'phpdoc_trim' => false,
Expand All @@ -135,9 +118,17 @@
'single_trait_insert_per_statement' => false,
'standardize_increment' => false,
'ternary_to_null_coalescing' => false,
'trailing_comma_in_multiline' => false,
'visibility_required' => false,
'yoda_style' => false,

// TODO - risky
'no_unset_on_property' => false,
'php_unit_data_provider_name' => false,
'php_unit_strict' => false,
'php_unit_test_case_static_method_calls' => false,
'random_api_migration' => false,
'self_accessor' => false,
'static_lambda' => false,
'strict_param' => false,
])
->setFinder($finder)
->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer.' . md5(__DIR__) . '.cache');
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
'task' => 'login',
'error' => $session_error,
// Return 401 only on failed logins (#7010)
'http_code' => empty($session_error) && !empty($error_message) ? 401 : 200
'http_code' => empty($session_error) && !empty($error_message) ? 401 : 200,
]);

$RCMAIL->set_task($plugin['task']);
Expand Down
6 changes: 3 additions & 3 deletions installer/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

$dirs[] = !empty($RCI->config['temp_dir']) ? $RCI->config['temp_dir'] : 'temp';
if ($RCI->config['log_driver'] != 'syslog') {
$dirs[] = $RCI->config['log_dir'] ? $RCI->config['log_dir'] : 'logs';
$dirs[] = $RCI->config['log_dir'] ?: 'logs';
}

foreach ($dirs as $dir) {
Expand Down Expand Up @@ -179,7 +179,7 @@
}
else if ($err = $RCI->db_schema_check($DB, $update = !empty($_POST['updatedb']))) {
$RCI->fail('DB Schema', "Database schema differs");
echo '<ul style="margin:0"><li>' . join("</li>\n<li>", $err) . "</li></ul>";
echo '<ul style="margin:0"><li>' . implode("</li>\n<li>", $err) . "</li></ul>";

$select = $RCI->versions_select(['name' => 'version']);
$select->add('0.9 or newer', '');
Expand Down Expand Up @@ -376,7 +376,7 @@
$RCI->pass('SMTP send');
}
else {
$RCI->fail('SMTP send', join('; ', $smtp_response));
$RCI->fail('SMTP send', implode('; ', $smtp_response));
}
}
else {
Expand Down
18 changes: 9 additions & 9 deletions plugins/acl/acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ function folder_form($args)
if (!isset($args['form']['props']['fieldsets']['info'])) {
$args['form']['props']['fieldsets']['info'] = [
'name' => $this->rc->gettext('info'),
'content' => []
'content' => [],
];
}

// Display folder rights to 'Info' fieldset
$args['form']['props']['fieldsets']['info']['content']['myrights'] = [
'label' => rcube::Q($this->gettext('myrights')),
'value' => $this->acl2text($myrights)
'value' => $this->acl2text($myrights),
];

// Return if not folder admin
Expand Down Expand Up @@ -257,7 +257,7 @@ function templ_rights($attrib)
$supported = $data['rights'];

// depending on server capability either use 'te' or 'd' for deleting msgs
$deleteright = implode(array_intersect(str_split('ted'), $supported));
$deleteright = implode('', array_intersect(str_split('ted'), $supported));

$out = '';
$ul = '';
Expand All @@ -282,7 +282,7 @@ function templ_rights($attrib)
'read' => 'lrs',
'write' => 'wi',
'delete' => $deleteright,
'other' => preg_replace('/[lrswi'.$deleteright.']/', '', implode($supported)),
'other' => preg_replace('/[lrswi'.$deleteright.']/', '', implode('', $supported)),
];

// give plugins the opportunity to adjust this list
Expand Down Expand Up @@ -399,7 +399,7 @@ private function list_rights($attrib = [])
$supported = $data['rights'];

// depending on server capability either use 'te' or 'd' for deleting msgs
$deleteright = implode(array_intersect(str_split('ted'), $supported));
$deleteright = implode('', array_intersect(str_split('ted'), $supported));

// Use advanced or simple (grouped) rights
$advanced = $this->rc->config->get('acl_advanced_mode');
Expand All @@ -415,7 +415,7 @@ private function list_rights($attrib = [])
'read' => 'lrs',
'write' => 'wi',
'delete' => $deleteright,
'other' => preg_replace('/[lrswi'.$deleteright.']/', '', implode($supported)),
'other' => preg_replace('/[lrswi'.$deleteright.']/', '', implode('', $supported)),
];

// give plugins the opportunity to adjust this list
Expand Down Expand Up @@ -476,7 +476,7 @@ private function list_rights($attrib = [])
$table->add('acl' . $key . ' ' . $class, '<span></span>');
}

$js_table[$userid] = implode($userrights);
$js_table[$userid] = implode('', $userrights);
}

$this->rc->output->set_env('acl', $js_table);
Expand Down Expand Up @@ -542,8 +542,8 @@ private function action_save()
'username' => $username,
'title' => $title,
'display' => $display,
'acl' => implode($acl),
'old' => $oldid
'acl' => implode('', $acl),
'old' => $oldid,
]);
$result++;
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/archive/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ function prefs_table($args)

$args['blocks']['main']['options']['archive_mbox'] = [
'title' => html::label('_archive_mbox', rcube::Q($this->gettext('archivefolder'))),
'content' => $select->show($mbox, ['id' => '_archive_mbox', 'name' => '_archive_mbox'])
'content' => $select->show($mbox, ['id' => '_archive_mbox', 'name' => '_archive_mbox']),
];

// If the server supports only either messages or folders in a folder
Expand All @@ -443,17 +443,17 @@ function prefs_table($args)
'options' => [
'archive_type' => [
'title' => html::label('ff_archive_type', rcube::Q($this->gettext('archivetype'))),
'content' => $archive_type->show($type)
]
]
'content' => $archive_type->show($type),
],
],
];
}
}
else if ($args['section'] == 'server' && !in_array('read_on_archive', $dont_override)) {
$chbox = new html_checkbox(['name' => '_read_on_archive', 'id' => 'ff_read_on_archive', 'value' => 1]);
$args['blocks']['main']['options']['read_on_archive'] = [
'title' => html::label('ff_read_on_archive', rcube::Q($this->gettext('readonarchive'))),
'content' => $chbox->show($rcmail->config->get('read_on_archive') ? 1 : 0)
'content' => $chbox->show($rcmail->config->get('read_on_archive') ? 1 : 0),
];
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/emoticons/emoticons.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function preferences_list($args)

$args['blocks']['main']['options']['emoticons_display'] = [
'title' => html::label($field_id, $this->gettext('emoticonsdisplay')),
'content' => $checkbox->show(intval($rcube->config->get('emoticons_display', false)))
'content' => $checkbox->show(intval($rcube->config->get('emoticons_display', false))),
];
}
else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) {
Expand All @@ -98,7 +98,7 @@ function preferences_list($args)

$args['blocks']['main']['options']['emoticons_compose'] = [
'title' => html::label($field_id, $this->gettext('emoticonscompose')),
'content' => $checkbox->show(intval($rcube->config->get('emoticons_compose', true)))
'content' => $checkbox->show(intval($rcube->config->get('emoticons_compose', true))),
];
}

Expand Down
10 changes: 5 additions & 5 deletions plugins/enigma/lib/enigma_driver_gnupg.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ protected function db_sync()
if ($data === null || $data === false) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'message' => "Enigma: Failed to sync $file ({$record['file_id']}). Decode error."
'message' => "Enigma: Failed to sync $file ({$record['file_id']}). Decode error.",
], true, false);

continue;
Expand Down Expand Up @@ -647,7 +647,7 @@ protected function db_sync()

rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'message' => "Enigma: Failed to sync $file."
'message' => "Enigma: Failed to sync $file.",
], true, false);
}
}
Expand Down Expand Up @@ -715,7 +715,7 @@ protected function db_save($is_empty = false)
if ($datasize > $maxsize) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'message' => "Enigma: Failed to save $file. Size exceeds max_allowed_packet."
'message' => "Enigma: Failed to save $file. Size exceeds max_allowed_packet.",
], true, false);

continue;
Expand All @@ -727,7 +727,7 @@ protected function db_save($is_empty = false)
if ($db->is_error($result)) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'message' => "Enigma: Failed to save $file into database."
'message' => "Enigma: Failed to save $file into database.",
], true, false);

break;
Expand All @@ -749,7 +749,7 @@ protected function db_save($is_empty = false)
if ($db->is_error($result)) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'message' => "Enigma: Failed to delete $file from database."
'message' => "Enigma: Failed to delete $file from database.",
], true, false);

break;
Expand Down
2 changes: 1 addition & 1 deletion plugins/enigma/lib/enigma_driver_phpssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private function get_openssl_error()
$tmp[] = $errorstr;
}

return join("\n", array_values($tmp));
return implode("\n", array_values($tmp));
}

private function parse_sig_cert($file, $validity)
Expand Down
8 changes: 4 additions & 4 deletions plugins/enigma/lib/enigma_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function load_pgp_driver()
if (!$this->pgp_driver) {
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Enigma plugin: Unable to load PGP driver: $driver"
'message' => "Enigma plugin: Unable to load PGP driver: $driver",
], true, true
);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ function load_smime_driver()
if (!$this->smime_driver) {
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Enigma plugin: Unable to load S/MIME driver: $driver"
'message' => "Enigma plugin: Unable to load S/MIME driver: $driver",
], true, true
);
}
Expand Down Expand Up @@ -845,7 +845,7 @@ private function parse_pgp_encrypted(&$p)
$this->part_structure([
'object' => $p['object'],
'structure' => $struct,
'mimetype' => $struct->mimetype
'mimetype' => $struct->mimetype,
], $body);

// Attach the decryption message to all parts
Expand Down Expand Up @@ -1468,7 +1468,7 @@ protected static function raise_error($result, $line, $abort = false)
'code' => 600,
'file' => __FILE__,
'line' => $line,
'message' => "Enigma plugin: " . $result->getMessage()
'message' => "Enigma plugin: " . $result->getMessage(),
], true, $abort
);
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/enigma/lib/enigma_signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function get_sender($engine, $message, $part_id = null)
$parts = $message->mime_parts();

while (array_pop($level) !== null) {
$parent = join('.', $level);
$parent = implode('.', $level);
if (!empty($parts[$parent]) && $parts[$parent]->mimetype == 'message/rfc822') {
$from = $parts[$parent]->headers['from'];
$charset = $parts[$parent]->charset;
Expand Down
Loading
Loading