Skip to content

Commit

Permalink
Fixes various code style issues and integrate PHP CS Fixer into drone (
Browse files Browse the repository at this point in the history
…joomla#39745)

* Integrate PHP CS Fixer into drone

* Fix code base

* more verbose

* Ignore psr12 scripts

* Test

* revert

* Ignore also rebase script

* Align array and variable declarations

* Merges

* Fix the no break comment starting with upper case

* Fix alignment in arrays

* Article controller alignment
  • Loading branch information
laoneo authored Jan 31, 2023
1 parent 8f94ab0 commit 1e7527b
Show file tree
Hide file tree
Showing 911 changed files with 5,260 additions and 5,612 deletions.
1 change: 1 addition & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ steps:
depends_on: [ composer ]
commands:
- echo $(date)
- ./libraries/vendor/bin/php-cs-fixer fix -vvv --dry-run
- ./libraries/vendor/bin/phpcs --extensions=php -p --standard=ruleset.xml .
- echo $(date)

Expand Down
43 changes: 26 additions & 17 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,8 @@
* ./libraries/vendor/bin/php-cs-fixer fix administrator/index.php
*/

// Only index the files in /libraries and no deeper, to prevent /libraries/vendor being indexed
$topFilesFinder = PhpCsFixer\Finder::create()
->in(
[
__DIR__ . '/libraries'
]
)
->files()
->depth(0);

// Add all the core Joomla folders and append to this list the files indexed above from /libraries
$mainFinder = PhpCsFixer\Finder::create()
// Add all the core Joomla folders
$finder = PhpCsFixer\Finder::create()
->in(
[
__DIR__ . '/administrator',
Expand All @@ -57,20 +47,39 @@
__DIR__ . '/plugins',
__DIR__ . '/templates',
__DIR__ . '/tests',
__DIR__ . '/layouts',
]
)
->append($topFilesFinder);
// Ignore template files as PHP CS fixer can't handle them properly
// https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/3702#issuecomment-396717120
->notPath('/tmpl/')
->notPath('/layouts/')
->notPath('/cassiopeia/')
->notPath('/atum/')
// Ignore psr12 scripts because they contain invalid syntax
->notPath('/psr12/')
->notName('github_rebase.php');

$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setHideProgress(false)
->setUsingCache(false)
->setRules(
[
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
// Basic ruleset is PSR 12
'@PSR12' => true,
// Short array syntax
'array_syntax' => ['syntax' => 'short'],
// Lists should not have a trailing comma like list($foo, $bar,) = ...
'no_trailing_comma_in_list_call' => true,
// Arrays on multiline should have a trailing comma
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
// Align elements in multiline array and variable declarations on new lines below each other
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align']],
// The "No break" comment in switch statements
'no_break_comment' => ['comment_text' => 'No break'],
]
)
->setFinder($mainFinder);
->setFinder($finder);

return $config;
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
*
* @since 4.0.0
*/
return new class implements ServiceProviderInterface
{
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getOptions()

foreach ($extensions as $extension) {
ActionlogsHelper::loadTranslationFiles($extension);
$extensionName = Text::_($extension);
$extensionName = Text::_($extension);
$options[ApplicationHelper::stringURLSafe($extensionName) . '_' . $extension] = HTMLHelper::_('select.option', $extension, $extensionName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function getCsvData($data): Generator
'extension' => self::escapeCsvFormula(Text::_($extension)),
'date' => (new Date($log->log_date, new \DateTimeZone('UTC')))->format('Y-m-d H:i:s T'),
'name' => self::escapeCsvFormula($log->name),
'ip_address' => self::escapeCsvFormula($log->ip_address === 'COM_ACTIONLOGS_DISABLED' ? $disabledText : $log->ip_address)
'ip_address' => self::escapeCsvFormula($log->ip_address === 'COM_ACTIONLOGS_DISABLED' ? $disabledText : $log->ip_address),
];
}
}
Expand All @@ -95,7 +95,7 @@ public static function getCsvData($data): Generator
public static function loadTranslationFiles($extension)
{
static $cache = [];
$extension = strtolower($extension);
$extension = strtolower($extension);

if (isset($cache[$extension])) {
return;
Expand Down Expand Up @@ -277,13 +277,13 @@ public static function loadActionLogPluginsLanguage()
'folder',
'element',
'params',
'extension_id'
'extension_id',
],
[
'type',
'name',
'params',
'id'
'id',
]
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ protected function sendNotificationEmails($messages, $username, $context)
$temp = [];

foreach ($messages as $message) {
$m = [];
$m = [];
$m['extension'] = Text::_($extension);
$m['message'] = ActionlogsHelper::getHumanReadableLogMessage($message);
$m['date'] = HTMLHelper::_('date', $message->log_date, 'Y-m-d H:i:s T', 'UTC');
$m['username'] = $username;
$temp[] = $m;
$temp[] = $m;
}

$templateData = [
'messages' => $temp
'messages' => $temp,
];

$mailer = new MailTemplate('com_actionlogs.notification', $app->getLanguage()->getTag());
Expand Down
32 changes: 16 additions & 16 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ protected function uninstallRepeatableFieldsPlugin()
* for each of the sub fields of the `repeatable` instance.
*/
$data = [
'context' => $row->context,
'group_id' => $row->group_id,
'title' => $oldField->fieldname,
'name' => (
'context' => $row->context,
'group_id' => $row->group_id,
'title' => $oldField->fieldname,
'name' => (
$fieldname_prefix
. $oldField->fieldname
. ($fieldname_suffix > 0 ? ('_' . $fieldname_suffix) : '')
Expand Down Expand Up @@ -7886,7 +7886,7 @@ public function deleteUnexistingFiles($dryRun = false, $suppressOutput = false)
'/libraries/vendor/paragonie/sodium_compat/dist',
];

$status['files_checked'] = $files;
$status['files_checked'] = $files;
$status['folders_checked'] = $folders;

foreach ($files as $file) {
Expand Down Expand Up @@ -8351,7 +8351,7 @@ private function contactItems(Table $tableItem): array
'client_id' => 1,
'publish_up' => null,
'publish_down' => null,
]
],
];

return $menuItems;
Expand Down Expand Up @@ -8510,7 +8510,7 @@ private function finderItems(Table $tableItem): array
'client_id' => 1,
'publish_up' => null,
'publish_down' => null,
]
],
];

return $menuItems;
Expand Down Expand Up @@ -8543,7 +8543,7 @@ private function updateContentTypes(): void
];

// Get table definitions.
$db = Factory::getDbo();
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select(
[
Expand Down Expand Up @@ -8612,7 +8612,7 @@ protected function fixFilenameCasing()
$files = [
// 3.10 changes
'/libraries/src/Filesystem/Support/Stringcontroller.php' => '/libraries/src/Filesystem/Support/StringController.php',
'/libraries/src/Form/Rule/SubFormRule.php' => '/libraries/src/Form/Rule/SubformRule.php',
'/libraries/src/Form/Rule/SubFormRule.php' => '/libraries/src/Form/Rule/SubformRule.php',
// 4.0.0
'/media/vendor/skipto/js/skipTo.js' => '/media/vendor/skipto/js/skipto.js',
];
Expand Down Expand Up @@ -8668,14 +8668,14 @@ protected function fixFilenameCasing()
protected function moveRemainingTemplateFiles()
{
$folders = [
'/administrator/templates/atum/css' => '/media/templates/administrator/atum/css',
'/administrator/templates/atum/css' => '/media/templates/administrator/atum/css',
'/administrator/templates/atum/images' => '/media/templates/administrator/atum/images',
'/administrator/templates/atum/js' => '/media/templates/administrator/atum/js',
'/administrator/templates/atum/scss' => '/media/templates/administrator/atum/scss',
'/templates/cassiopeia/css' => '/media/templates/site/cassiopeia/css',
'/templates/cassiopeia/images' => '/media/templates/site/cassiopeia/images',
'/templates/cassiopeia/js' => '/media/templates/site/cassiopeia/js',
'/templates/cassiopeia/scss' => '/media/templates/site/cassiopeia/scss',
'/administrator/templates/atum/js' => '/media/templates/administrator/atum/js',
'/administrator/templates/atum/scss' => '/media/templates/administrator/atum/scss',
'/templates/cassiopeia/css' => '/media/templates/site/cassiopeia/css',
'/templates/cassiopeia/images' => '/media/templates/site/cassiopeia/images',
'/templates/cassiopeia/js' => '/media/templates/site/cassiopeia/js',
'/templates/cassiopeia/scss' => '/media/templates/site/cassiopeia/scss',
];

foreach ($folders as $oldFolder => $newFolder) {
Expand Down
3 changes: 1 addition & 2 deletions administrator/components/com_admin/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
*
* @since 4.0.0
*/
return new class implements ServiceProviderInterface
{
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_admin/src/Model/HelpModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function &getToc()
}

// Get Help files
$files = Folder::files(JPATH_BASE . '/help/' . $lang_tag, '\.xml$|\.html$');
$files = Folder::files(JPATH_BASE . '/help/' . $lang_tag, '\.xml$|\.html$');
$this->toc = [];

foreach ($files as $file) {
Expand Down
40 changes: 20 additions & 20 deletions administrator/components/com_admin/src/Model/SysinfoModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class SysinfoModel extends BaseDatabaseModel
'smtphost',
'tmp_path',
'open_basedir',
]
],
];

/**
Expand Down Expand Up @@ -279,12 +279,12 @@ public function &getConfig(): array
return $this->config;
}

$registry = new Registry(new \JConfig());
$registry = new Registry(new \JConfig());
$this->config = $registry->toArray();
$hidden = [
$hidden = [
'host', 'user', 'password', 'ftp_user', 'ftp_pass',
'smtpuser', 'smtppass', 'redis_server_auth', 'session_redis_server_auth',
'proxy_user', 'proxy_pass', 'secret'
'proxy_user', 'proxy_pass', 'secret',
];

foreach ($hidden as $key) {
Expand Down Expand Up @@ -393,13 +393,13 @@ public function &getPHPInfo(): string
$phpInfo = ob_get_contents();
ob_end_clean();
preg_match_all('#<body[^>]*>(.*)</body>#siU', $phpInfo, $output);
$output = preg_replace('#<table[^>]*>#', '<table class="table">', $output[1][0]);
$output = preg_replace('#(\w),(\w)#', '\1, \2', $output);
$output = preg_replace('#<hr />#', '', $output);
$output = str_replace('<div class="text-center">', '', $output);
$output = preg_replace('#<tr class="h">(.*)</tr>#', '<thead><tr class="h">$1</tr></thead><tbody>', $output);
$output = str_replace('</table>', '</tbody></table>', $output);
$output = str_replace('</div>', '', $output);
$output = preg_replace('#<table[^>]*>#', '<table class="table">', $output[1][0]);
$output = preg_replace('#(\w),(\w)#', '\1, \2', $output);
$output = preg_replace('#<hr />#', '', $output);
$output = str_replace('<div class="text-center">', '', $output);
$output = preg_replace('#<tr class="h">(.*)</tr>#', '<thead><tr class="h">$1</tr></thead><tbody>', $output);
$output = str_replace('</table>', '</tbody></table>', $output);
$output = str_replace('</div>', '', $output);
$this->php_info = $output;

return $this->php_info;
Expand Down Expand Up @@ -482,7 +482,7 @@ public function getExtensions(): array
'author' => $manifest->get('author', ''),
'version' => $manifest->get('version', ''),
'creationDate' => $manifest->get('creationDate', ''),
'authorUrl' => $manifest->get('authorUrl', '')
'authorUrl' => $manifest->get('authorUrl', ''),
];

$installed[$extension->name] = array_merge($installed[$extension->name], $extraData);
Expand Down Expand Up @@ -681,15 +681,15 @@ public function &getEditor(): string
*/
protected function parsePhpInfo(string $html): array
{
$html = strip_tags($html, '<h2><th><td>');
$html = preg_replace('/<th[^>]*>([^<]+)<\/th>/', '<info>\1</info>', $html);
$html = preg_replace('/<td[^>]*>([^<]+)<\/td>/', '<info>\1</info>', $html);
$t = preg_split('/(<h2[^>]*>[^<]+<\/h2>)/', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
$r = [];
$html = strip_tags($html, '<h2><th><td>');
$html = preg_replace('/<th[^>]*>([^<]+)<\/th>/', '<info>\1</info>', $html);
$html = preg_replace('/<td[^>]*>([^<]+)<\/td>/', '<info>\1</info>', $html);
$t = preg_split('/(<h2[^>]*>[^<]+<\/h2>)/', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
$r = [];
$count = \count($t);
$p1 = '<info>([^<]+)<\/info>';
$p2 = '/' . $p1 . '\s*' . $p1 . '\s*' . $p1 . '/';
$p3 = '/' . $p1 . '\s*' . $p1 . '/';
$p1 = '<info>([^<]+)<\/info>';
$p2 = '/' . $p1 . '\s*' . $p1 . '\s*' . $p1 . '/';
$p3 = '/' . $p1 . '\s*' . $p1 . '/';

for ($i = 1; $i < $count; $i++) {
if (preg_match('/<h2[^>]*>([^<]+)<\/h2>/', $t[$i], $matches)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function getLayoutData(): array
'config' => $model->getSafeData('config'),
'directories' => $model->getSafeData('directory', true),
'phpInfo' => $model->getSafeData('phpInfoArray'),
'extensions' => $model->getSafeData('extensions')
'extensions' => $model->getSafeData('extensions'),
];
}
}
14 changes: 7 additions & 7 deletions administrator/components/com_admin/src/View/Sysinfo/TextView.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,28 @@ protected function getLayoutData(): array
return [
'info' => [
'title' => Text::_('COM_ADMIN_SYSTEM_INFORMATION', true),
'data' => $model->getSafeData('info')
'data' => $model->getSafeData('info'),
],
'phpSettings' => [
'title' => Text::_('COM_ADMIN_PHP_SETTINGS', true),
'data' => $model->getSafeData('phpSettings')
'data' => $model->getSafeData('phpSettings'),
],
'config' => [
'title' => Text::_('COM_ADMIN_CONFIGURATION_FILE', true),
'data' => $model->getSafeData('config')
'data' => $model->getSafeData('config'),
],
'directories' => [
'title' => Text::_('COM_ADMIN_DIRECTORY_PERMISSIONS', true),
'data' => $model->getSafeData('directory', true)
'data' => $model->getSafeData('directory', true),
],
'phpInfo' => [
'title' => Text::_('COM_ADMIN_PHP_INFORMATION', true),
'data' => $model->getSafeData('phpInfoArray')
'data' => $model->getSafeData('phpInfoArray'),
],
'extensions' => [
'title' => Text::_('COM_ADMIN_EXTENSIONS', true),
'data' => $model->getSafeData('extensions')
]
'data' => $model->getSafeData('extensions'),
],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
*
* @since 4.0.0
*/
return new class implements ServiceProviderInterface
{
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function getGroups()
foreach ($extensions as $extension) {
if ($extension->get('associationssupport') === true) {
foreach ($extension->get('types') as $type) {
$context = $extension->get('component') . '.' . $type->get('name');
$context = $extension->get('component') . '.' . $type->get('name');
$options[$extension->get('title')][] = HTMLHelper::_('select.option', $context, $type->get('title'));
}
}
Expand Down
Loading

0 comments on commit 1e7527b

Please sign in to comment.