From 98dda3987f81d330193f385d100adb1a230bcb34 Mon Sep 17 00:00:00 2001 From: splitbrain Date: Mon, 13 Nov 2023 22:52:02 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Automatic=20code=20style=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LangProcessor.php | 4 +-- SVGIcon.php | 7 ++-- Skeletor.php | 8 ++--- cli.php | 80 +++++++++++++++++++++++++++++------------- skel/action.php | 4 +-- skel/cli.php | 3 -- skel/conf/default.php | 2 +- skel/conf/metadata.php | 3 +- skel/lang/lang.php | 2 +- skel/lang/settings.php | 2 +- www/PluginWizard.php | 9 +---- www/index.php | 2 +- 12 files changed, 72 insertions(+), 54 deletions(-) diff --git a/LangProcessor.php b/LangProcessor.php index 57b8029..f4aa1b3 100644 --- a/LangProcessor.php +++ b/LangProcessor.php @@ -6,7 +6,6 @@ class LangProcessor { - /** @var CLI */ protected $logger; @@ -63,7 +62,7 @@ public function processSettingsFile($file) include $file; $drop = array_diff_key($lang, $this->settingKeys); - foreach ($drop as $key => $value) { + foreach (array_keys($drop) as $key) { $this->removeLangKey($file, $key); } } @@ -229,7 +228,6 @@ private function extract($file, $regex) if (!isset($found[$key])) { $found[$key] = $file . ':' . ($lno + 1); } - } } diff --git a/SVGIcon.php b/SVGIcon.php index ae3ff21..a55faa4 100644 --- a/SVGIcon.php +++ b/SVGIcon.php @@ -10,8 +10,7 @@ */ class SVGIcon { - - const SOURCES = [ + public const SOURCES = [ 'mdi' => "https://raw.githubusercontent.com/Templarian/MaterialDesign/master/svg/%s.svg", 'fab' => "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/svgs/brands/%s.svg", 'fas' => "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/svgs/solid/%s.svg", @@ -97,7 +96,7 @@ public function cleanSVGFile($file) public function remoteIcon($ident) { if (strpos($ident, ':')) { - list($prefix, $name) = explode(':', $ident); + [$prefix, $name] = explode(':', $ident); } else { $prefix = 'mdi'; $name = $ident; @@ -130,6 +129,7 @@ protected function cleanSVG($svgdata) $dom = new \DOMDocument(); $dom->loadXML($svgdata, LIBXML_NOBLANKS); + $dom->formatOutput = false; $dom->preserveWhiteSpace = false; @@ -225,5 +225,4 @@ protected function fetchSVG($url) return $svg; } - } diff --git a/Skeletor.php b/Skeletor.php index 5bcaca0..17778e1 100644 --- a/Skeletor.php +++ b/Skeletor.php @@ -13,10 +13,10 @@ class Skeletor { // FIXME this may change upstream we may want to update it via github action - const PLUGIN_TYPES = ['auth', 'admin', 'syntax', 'action', 'renderer', 'helper', 'remote', 'cli']; + public const PLUGIN_TYPES = ['auth', 'admin', 'syntax', 'action', 'renderer', 'helper', 'remote', 'cli']; - const TYPE_PLUGIN = 'plugin'; - const TYPE_TEMPLATE = 'template'; + public const TYPE_PLUGIN = 'plugin'; + public const TYPE_TEMPLATE = 'template'; protected $type; protected $base; @@ -65,7 +65,7 @@ public function __construct($type, $base, $desc, $author, $email, $name = '', $u * @param string $dir * @return Skeletor */ - static public function fromDir($dir) + public static function fromDir($dir) { if (file_exists($dir . '/plugin.info.txt')) { $type = self::TYPE_PLUGIN; diff --git a/cli.php b/cli.php index be21e36..b93b7f2 100755 --- a/cli.php +++ b/cli.php @@ -31,8 +31,12 @@ protected function setup(Options $options) $options->registerCommand('init', 'Initialize a new plugin or template in the current directory.'); $options->registerCommand('addTest', 'Add the testing framework files and a test. (_test/)'); - $options->registerArgument('test', 'Optional name of the new test. Defaults to the general test.', false, - 'addTest'); + $options->registerArgument( + 'test', + 'Optional name of the new test. Defaults to the general test.', + false, + 'addTest' + ); $options->registerCommand('addConf', 'Add the configuration files. (conf/)'); $options->registerCommand('addLang', 'Add the language files. (lang/)'); @@ -45,10 +49,18 @@ function (&$item) { ); $options->registerCommand('addComponent', 'Add a new plugin component.'); - $options->registerArgument('type', 'Type of the component. Needs to be one of ' . join(', ', $types), true, - 'addComponent'); - $options->registerArgument('name', 'Optional name of the component. Defaults to a base component.', false, - 'addComponent'); + $options->registerArgument( + 'type', + 'Type of the component. Needs to be one of ' . implode(', ', $types), + true, + 'addComponent' + ); + $options->registerArgument( + 'name', + 'Optional name of the component. Defaults to a base component.', + false, + 'addComponent' + ); $options->registerCommand('deletedFiles', 'Create the list of deleted files based on the git history.'); $options->registerCommand('rmObsolete', 'Delete obsolete files.'); @@ -62,21 +74,41 @@ function (&$item) { ); $options->registerCommand('downloadSvg', 'Download an SVG file from a known icon repository.'); - $options->registerArgument('prefix:name', - 'Colon-prefixed name of the icon. Available prefixes: ' . join(', ', $prefixes), true, 'downloadSvg'); - $options->registerArgument('output', 'File to save, defaults to .svg in current dir', false, - 'downloadSvg'); - $options->registerOption('keep-ns', 'Keep the SVG namespace. Use when the file is not inlined into HTML.', 'k', - false, 'downloadSvg'); + $options->registerArgument( + 'prefix:name', + 'Colon-prefixed name of the icon. Available prefixes: ' . implode(', ', $prefixes), + true, + 'downloadSvg' + ); + $options->registerArgument( + 'output', + 'File to save, defaults to .svg in current dir', + false, + 'downloadSvg' + ); + $options->registerOption( + 'keep-ns', + 'Keep the SVG namespace. Use when the file is not inlined into HTML.', + 'k', + false, + 'downloadSvg' + ); $options->registerCommand('cleanSvg', 'Clean a existing SVG files to reduce their file size.'); $options->registerArgument('files...', 'The files to clean (will be overwritten)', true, 'cleanSvg'); - $options->registerOption('keep-ns', 'Keep the SVG namespace. Use when the file is not inlined into HTML.', 'k', - false, 'cleanSvg'); + $options->registerOption( + 'keep-ns', + 'Keep the SVG namespace. Use when the file is not inlined into HTML.', + 'k', + false, + 'cleanSvg' + ); - $options->registerCommand('cleanLang', + $options->registerCommand( + 'cleanLang', 'Clean language files from unused language strings. Detecting which strings are truly in use may ' . - 'not always correctly work. Use with caution.'); + 'not always correctly work. Use with caution.' + ); $options->registerCommand('test', 'Run the unit tests for this extension.'); @@ -243,7 +275,7 @@ protected function deleteFile($file) protected function git(...$args) { $args = array_map('escapeshellarg', $args); - $cmd = 'git ' . join(' ', $args); + $cmd = 'git ' . implode(' ', $args); $output = []; $result = 0; @@ -363,14 +395,14 @@ protected function cmdDeletedFiles() }); sort($output); - if (!count($output)) { + if ($output === []) { $this->info('No deleted files found'); return 0; } $content = "# This is a list of files that were present in previous releases\n" . "# but were removed later. They should not exist in your installation.\n" . - join("\n", $output) . "\n"; + implode("\n", $output) . "\n"; file_put_contents('deleted.files', $content); $this->success('written deleted.files'); @@ -464,7 +496,7 @@ protected function cmdTest() '--configuration', fullpath(__DIR__ . '/../../../_test/phpunit.xml'), '--group', $type . '_' . $base, ]; - $cmd = join(' ', array_map('escapeshellarg', $args)); + $cmd = implode(' ', array_map('escapeshellarg', $args)); $this->info("Running $cmd"); $result = 0; @@ -492,7 +524,7 @@ protected function cmdCheck($files = []) $args[] = fullpath($dir); } - $cmd = join(' ', array_map('escapeshellarg', $args)); + $cmd = implode(' ', array_map('escapeshellarg', $args)); $this->info("Running $cmd"); $result = 0; @@ -522,12 +554,12 @@ protected function cmdFix($files = []) $args[] = fullpath($dir); } - $cmd = join(' ', array_map('escapeshellarg', $args)); + $cmd = implode(' ', array_map('escapeshellarg', $args)); $this->info("Running $cmd"); $result = 0; passthru($cmd, $result); - if($result !== 0) return $result; + if ($result !== 0) return $result; // now run phpcbf to clean up code style $args = [ @@ -543,7 +575,7 @@ protected function cmdFix($files = []) $args[] = fullpath($dir); } - $cmd = join(' ', array_map('escapeshellarg', $args)); + $cmd = implode(' ', array_map('escapeshellarg', $args)); $this->info("Running $cmd"); $result = 0; diff --git a/skel/action.php b/skel/action.php index 85dba19..3009fd5 100644 --- a/skel/action.php +++ b/skel/action.php @@ -15,8 +15,8 @@ class @@PLUGIN_COMPONENT_NAME@@ extends ActionPlugin /** @inheritDoc */ public function register(EventHandler $controller) { -@@REGISTER@@ + @@REGISTER@@ } -@@HANDLERS@@ + @@HANDLERS@@ } diff --git a/skel/cli.php b/skel/cli.php index f5d6b1f..7015587 100644 --- a/skel/cli.php +++ b/skel/cli.php @@ -10,7 +10,6 @@ */ class @@PLUGIN_COMPONENT_NAME@@ extends \dokuwiki\Extension\CLIPlugin { - /** @inheritDoc */ protected function setup(Options $options) { @@ -33,6 +32,4 @@ protected function main(Options $options) // $command = $options->getCmd() // $arguments = $options->getArgs() } - } - diff --git a/skel/conf/default.php b/skel/conf/default.php index 539fa29..be7cc5b 100644 --- a/skel/conf/default.php +++ b/skel/conf/default.php @@ -1,4 +1,5 @@ */ - //$meta['fixme'] = array('string'); - diff --git a/skel/lang/lang.php b/skel/lang/lang.php index 0f89867..539df09 100644 --- a/skel/lang/lang.php +++ b/skel/lang/lang.php @@ -1,4 +1,5 @@ addTest(); foreach ($_POST['components'] as $id) { - list($type, /*"plugin"*/, /*base*/, $component) = array_pad(explode('_', $id, 4), 4, ''); + [$type, , , $component] = array_pad(explode('_', $id, 4), 4, ''); if (isset($_POST['options'][$id])) { $options = array_filter(array_map('trim', explode(',', $_POST['options'][$id]))); } else { @@ -69,10 +68,4 @@ public function getEvents() { return array_map('trim', file(__DIR__ . '/../events.txt', FILE_IGNORE_NEW_LINES)); } - } - - - - - diff --git a/www/index.php b/www/index.php index 6aec1b1..466b688 100644 --- a/www/index.php +++ b/www/index.php @@ -117,7 +117,7 @@