From 890a61358a518cedf37e2d596cdddfd716166aae Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 20 Nov 2018 20:40:13 +0200 Subject: [PATCH] Code cleanup on CLI --- system/src/Grav/Console/Cli/BackupCommand.php | 13 +- system/src/Grav/Console/Cli/CacheCommand.php | 2 +- system/src/Grav/Console/Cli/CleanCommand.php | 5 +- .../src/Grav/Console/Cli/ComposerCommand.php | 1 + .../src/Grav/Console/Cli/InstallCommand.php | 7 +- .../Grav/Console/Cli/NewProjectCommand.php | 1 + .../src/Grav/Console/Cli/SandboxCommand.php | 9 +- .../src/Grav/Console/Cli/SchedulerCommand.php | 16 +-- .../src/Grav/Console/Cli/SecurityCommand.php | 14 +- system/src/Grav/Console/ConsoleCommand.php | 2 +- system/src/Grav/Console/ConsoleTrait.php | 3 +- .../Grav/Console/Gpm/DirectInstallCommand.php | 69 ++++----- system/src/Grav/Console/Gpm/IndexCommand.php | 44 +++--- system/src/Grav/Console/Gpm/InfoCommand.php | 61 ++++---- .../src/Grav/Console/Gpm/InstallCommand.php | 133 +++++++++--------- .../Grav/Console/Gpm/SelfupgradeCommand.php | 65 ++++----- .../src/Grav/Console/Gpm/UninstallCommand.php | 52 +++---- system/src/Grav/Console/Gpm/UpdateCommand.php | 58 ++++---- .../src/Grav/Console/Gpm/VersionCommand.php | 17 +-- 19 files changed, 294 insertions(+), 278 deletions(-) diff --git a/system/src/Grav/Console/Cli/BackupCommand.php b/system/src/Grav/Console/Cli/BackupCommand.php index 7a77204ff..36d1bd3f4 100644 --- a/system/src/Grav/Console/Cli/BackupCommand.php +++ b/system/src/Grav/Console/Cli/BackupCommand.php @@ -1,4 +1,5 @@ setName("backup") + ->setName('backup') ->addArgument( 'id', InputArgument::OPTIONAL, 'The ID of the backup to perform without prompting' ) - ->setDescription("Creates a backup of the Grav instance") + ->setDescription('Creates a backup of the Grav instance') ->setHelp('The backup creates a zipped backup. Optionally can be saved in a different destination.'); $this->source = getcwd(); @@ -65,12 +66,12 @@ class BackupCommand extends ConsoleCommand $id = null; $inline_id = $this->input->getArgument('id'); - if (isset($inline_id) && is_numeric($inline_id)) { + if (null !== $inline_id && is_numeric($inline_id)) { $id = $inline_id; } - if (is_null($id)) { - if (count($backups_list) > 1) { + if (null === $id) { + if (\count($backups_list) > 1) { $helper = $this->getHelper('question'); $question = new ChoiceQuestion( 'Choose a backup?', @@ -79,7 +80,7 @@ class BackupCommand extends ConsoleCommand ); $question->setErrorMessage('Option %s is invalid.'); $backup_name = $helper->ask($this->input, $this->output, $question); - $id = array_search($backup_name, $backups_names); + $id = array_search($backup_name, $backups_names, true); $io->newLine(); $io->note('Selected backup: ' . $backup_name); diff --git a/system/src/Grav/Console/Cli/CacheCommand.php b/system/src/Grav/Console/Cli/CacheCommand.php index 64bf2484b..459045d0d 100644 --- a/system/src/Grav/Console/Cli/CacheCommand.php +++ b/system/src/Grav/Console/Cli/CacheCommand.php @@ -1,4 +1,5 @@ setName("clean") - ->setDescription("Handles cleaning chores for Grav distribution") + ->setName('clean') + ->setDescription('Handles cleaning chores for Grav distribution') ->setHelp('The clean clean extraneous folders and data'); } diff --git a/system/src/Grav/Console/Cli/ComposerCommand.php b/system/src/Grav/Console/Cli/ComposerCommand.php index 4f9c18f63..d11ece9bd 100644 --- a/system/src/Grav/Console/Cli/ComposerCommand.php +++ b/system/src/Grav/Console/Cli/ComposerCommand.php @@ -1,4 +1,5 @@ setName("install") + ->setName('install') ->addOption( 'symlink', 's', @@ -50,7 +51,7 @@ class InstallCommand extends ConsoleCommand InputArgument::OPTIONAL, 'Where to install the required bits (default to current project)' ) - ->setDescription("Installs the dependencies needed by Grav. Optionally can create symbolic links") + ->setDescription('Installs the dependencies needed by Grav. Optionally can create symbolic links') ->setHelp('The install command installs the dependencies needed by Grav. Optionally can create symbolic links'); } @@ -60,7 +61,7 @@ class InstallCommand extends ConsoleCommand protected function serve() { $dependencies_file = '.dependencies'; - $this->destination = ($this->input->getArgument('destination')) ? $this->input->getArgument('destination') : ROOT_DIR; + $this->destination = $this->input->getArgument('destination') ?: ROOT_DIR; // fix trailing slash $this->destination = rtrim($this->destination, DS) . DS; diff --git a/system/src/Grav/Console/Cli/NewProjectCommand.php b/system/src/Grav/Console/Cli/NewProjectCommand.php index 5a8f3d1e4..5b21f12f3 100644 --- a/system/src/Grav/Console/Cli/NewProjectCommand.php +++ b/system/src/Grav/Console/Cli/NewProjectCommand.php @@ -1,4 +1,5 @@ mappings as $source => $target) { - if ((int)$source == $source) { + if ((string)(int)$source === (string)$source) { $source = $target; } @@ -180,7 +181,7 @@ class SandboxCommand extends ConsoleCommand foreach ($this->mappings as $source => $target) { - if ((int)$source == $source) { + if ((string)(int)$source === (string)$source) { $source = $target; } @@ -211,7 +212,7 @@ class SandboxCommand extends ConsoleCommand // Copy files if they do not exist foreach ($this->files as $source => $target) { - if ((int)$source == $source) { + if ((string)(int)$source === (string)$source) { $source = $target; } @@ -242,7 +243,7 @@ class SandboxCommand extends ConsoleCommand $pages_dir = $this->destination . '/user/pages'; $pages_files = array_diff(scandir($pages_dir), ['..', '.']); - if (count($pages_files) == 0) { + if (\count($pages_files) === 0) { $destination = $this->source . '/user/pages'; Folder::rcopy($destination, $pages_dir); $this->output->writeln(' ' . $destination . ' -> Created'); diff --git a/system/src/Grav/Console/Cli/SchedulerCommand.php b/system/src/Grav/Console/Cli/SchedulerCommand.php index e115eb04a..b5525055a 100644 --- a/system/src/Grav/Console/Cli/SchedulerCommand.php +++ b/system/src/Grav/Console/Cli/SchedulerCommand.php @@ -1,4 +1,5 @@ setHelp('foo'); - /** @var use new SymfonyStyle helper $io */ $io = new SymfonyStyle($this->input, $this->output); if ($this->input->getOption('jobs')) { @@ -90,13 +90,13 @@ class SchedulerCommand extends ConsoleCommand $job_status = ucfirst($job_states[$job->getId()]['state'] ?? 'ready'); $last_run = $job_states[$job->getId()]['last-run'] ?? 0; $status = $job_status === 'Failure' ? "{$job_status}" : "{$job_status}"; - $state = $job->getEnabled() ? "Enabled" : "Disabled"; + $state = $job->getEnabled() ? 'Enabled' : 'Disabled'; $row = [ $job->getId(), "{$job->getCommand()}", "{$job->getAt()}", - "{$status}", - "" . ($last_run === 0 ? 'Never' : date('Y-m-d H:i', $last_run)) . "", + $status, + '' . ($last_run === 0 ? 'Never' : date('Y-m-d H:i', $last_run)) . '', $state, ]; @@ -136,16 +136,16 @@ class SchedulerCommand extends ConsoleCommand $row = []; $row[] = $job->getId(); if (!is_null($job_state['last-run'])) { - $row[] = "" . date('Y-m-d H:i', $job_state['last-run']) . ""; + $row[] = '' . date('Y-m-d H:i', $job_state['last-run']) . ''; } else { - $row[] = "" . "Never" . ""; + $row[] = 'Never'; } - $row[] = "" . $next_run->format('Y-m-d H:i') . ""; + $row[] = '' . $next_run->format('Y-m-d H:i') . ''; if ($error) { $row[] = "{$error}"; } else { - $row[] = "None"; + $row[] = 'None'; } $rows[] = $row; } diff --git a/system/src/Grav/Console/Cli/SecurityCommand.php b/system/src/Grav/Console/Cli/SecurityCommand.php index 81e3020a7..0cf820b90 100644 --- a/system/src/Grav/Console/Cli/SecurityCommand.php +++ b/system/src/Grav/Console/Cli/SecurityCommand.php @@ -1,4 +1,5 @@ setName("security") - ->setDescription("Capable of running various Security checks") + ->setName('security') + ->setDescription('Capable of running various Security checks') ->setHelp('The security runs various security checks on your Grav site'); $this->source = getcwd(); @@ -51,7 +53,7 @@ class SecurityCommand extends ConsoleCommand $grav['twig']->init(); $grav['pages']->init(); - $this->progress = new ProgressBar($this->output, (count($grav['pages']->routes()) - 1)); + $this->progress = new ProgressBar($this->output, \count($grav['pages']->routes()) - 1); $this->progress->setFormat('Scanning %current% pages [%bar%] %percent:3s%% %elapsed:6s%'); $this->progress->setBarWidth(100); @@ -74,7 +76,7 @@ class SecurityCommand extends ConsoleCommand $io->writeln($counter++ .' - ' . $route . '' . implode(', ', $results_parts) . ''); } - $io->error('Security Scan complete: ' . count($output) . ' potential XSS issues found...'); + $io->error('Security Scan complete: ' . \count($output) . ' potential XSS issues found...'); } else { $io->success('Security Scan complete: No issues found...'); @@ -92,7 +94,7 @@ class SecurityCommand extends ConsoleCommand switch ($args['type']) { case 'count': $steps = $args['steps']; - $freq = intval($steps > 100 ? round($steps / 100) : $steps); + $freq = (int)($steps > 100 ? round($steps / 100) : $steps); $this->progress->setMaxSteps($steps); $this->progress->setRedrawFrequency($freq); break; diff --git a/system/src/Grav/Console/ConsoleCommand.php b/system/src/Grav/Console/ConsoleCommand.php index a9c221738..4bacff9d2 100644 --- a/system/src/Grav/Console/ConsoleCommand.php +++ b/system/src/Grav/Console/ConsoleCommand.php @@ -1,4 +1,5 @@ output->writeln(''); - $this->output->writeln("ERROR: Destination chosen to install does not appear to be a Grav instance:"); + $this->output->writeln('ERROR: Destination chosen to install does not appear to be a Grav instance:'); $this->output->writeln(" $path"); $this->output->writeln(''); exit; diff --git a/system/src/Grav/Console/Gpm/DirectInstallCommand.php b/system/src/Grav/Console/Gpm/DirectInstallCommand.php index 60c5fa893..003a18e51 100644 --- a/system/src/Grav/Console/Gpm/DirectInstallCommand.php +++ b/system/src/Grav/Console/Gpm/DirectInstallCommand.php @@ -1,4 +1,5 @@ setName("direct-install") + ->setName('direct-install') ->setAliases(['directinstall']) ->addArgument( 'package-file', @@ -47,7 +50,7 @@ class DirectInstallCommand extends ConsoleCommand 'The destination where the package should be installed at. By default this would be where the grav instance has been launched from', GRAV_ROOT ) - ->setDescription("Installs Grav, plugin, or theme directly from a file or a URL") + ->setDescription('Installs Grav, plugin, or theme directly from a file or a URL') ->setHelp('The direct-install command installs Grav, plugin, or theme directly from a file or a URL'); } @@ -63,7 +66,7 @@ class DirectInstallCommand extends ConsoleCommand !Installer::isGravInstance($this->destination) || !Installer::isValidDestination($this->destination, [Installer::EXISTS, Installer::IS_LINK]) ) { - $this->output->writeln("ERROR: " . Installer::lastErrorMsg()); + $this->output->writeln('ERROR: ' . Installer::lastErrorMsg()); exit; } @@ -73,12 +76,12 @@ class DirectInstallCommand extends ConsoleCommand $package_file = $this->input->getArgument('package-file'); $helper = $this->getHelper('question'); - $question = new ConfirmationQuestion('Are you sure you want to direct-install '.$package_file.' [y|N] ', false); + $question = new ConfirmationQuestion("Are you sure you want to direct-install {$package_file} [y|N] ", false); $answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question); if (!$answer) { - $this->output->writeln("exiting..."); + $this->output->writeln('exiting...'); $this->output->writeln(''); exit; } @@ -86,32 +89,32 @@ class DirectInstallCommand extends ConsoleCommand $tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true); $tmp_zip = $tmp_dir . '/Grav-' . uniqid(); - $this->output->writeln(""); - $this->output->writeln("Preparing to install " . $package_file . ""); + $this->output->writeln(''); + $this->output->writeln("Preparing to install {$package_file}"); if (Response::isRemote($package_file)) { - $this->output->write(" |- Downloading package... 0%"); + $this->output->write(' |- Downloading package... 0%'); try { $zip = GPM::downloadPackage($package_file, $tmp_zip); } catch (\RuntimeException $e) { $this->output->writeln(''); - $this->output->writeln(" `- ERROR: " . $e->getMessage() . ""); + $this->output->writeln(" `- ERROR: {$e->getMessage()}"); $this->output->writeln(''); exit; } if ($zip) { $this->output->write("\x0D"); - $this->output->write(" |- Downloading package... 100%"); + $this->output->write(' |- Downloading package... 100%'); $this->output->writeln(''); } } else { - $this->output->write(" |- Copying package... 0%"); + $this->output->write(' |- Copying package... 0%'); $zip = GPM::copyPackage($package_file, $tmp_zip); if ($zip) { $this->output->write("\x0D"); - $this->output->write(" |- Copying package... 100%"); + $this->output->write(' |- Copying package... 100%'); $this->output->writeln(''); } } @@ -119,19 +122,19 @@ class DirectInstallCommand extends ConsoleCommand if (file_exists($zip)) { $tmp_source = $tmp_dir . '/Grav-' . uniqid(); - $this->output->write(" |- Extracting package... "); + $this->output->write(' |- Extracting package... '); $extracted = Installer::unZip($zip, $tmp_source); if (!$extracted) { $this->output->write("\x0D"); - $this->output->writeln(" |- Extracting package... failed"); + $this->output->writeln(' |- Extracting package... failed'); Folder::delete($tmp_source); Folder::delete($tmp_zip); exit; } $this->output->write("\x0D"); - $this->output->writeln(" |- Extracting package... ok"); + $this->output->writeln(' |- Extracting package... ok'); $type = GPM::getPackageType($extracted); @@ -160,13 +163,13 @@ class DirectInstallCommand extends ConsoleCommand $depencencies[] = $dependency; } } - $this->output->writeln(" |- Dependencies found... [" . implode(',', $depencencies) . "]"); + $this->output->writeln(' |- Dependencies found... [' . implode(',', $depencencies) . ']'); $question = new ConfirmationQuestion(" | '- Dependencies will not be satisfied. Continue ? [y|N] ", false); $answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question); if (!$answer) { - $this->output->writeln("exiting..."); + $this->output->writeln('exiting...'); $this->output->writeln(''); Folder::delete($tmp_source); Folder::delete($tmp_zip); @@ -175,14 +178,14 @@ class DirectInstallCommand extends ConsoleCommand } } - if ($type == 'grav') { + if ($type === 'grav') { - $this->output->write(" |- Checking destination... "); + $this->output->write(' |- Checking destination... '); Installer::isValidDestination(GRAV_ROOT . '/system'); if (Installer::IS_LINK === Installer::lastErrorCode()) { $this->output->write("\x0D"); - $this->output->writeln(" |- Checking destination... symbolic link"); - $this->output->writeln(" '- ERROR: symlinks found... " . GRAV_ROOT.""); + $this->output->writeln(' |- Checking destination... symbolic link'); + $this->output->writeln(" '- ERROR: symlinks found... " . GRAV_ROOT . ''); $this->output->writeln(''); Folder::delete($tmp_source); Folder::delete($tmp_zip); @@ -190,15 +193,15 @@ class DirectInstallCommand extends ConsoleCommand } $this->output->write("\x0D"); - $this->output->writeln(" |- Checking destination... ok"); + $this->output->writeln(' |- Checking destination... ok'); - $this->output->write(" |- Installing package... "); + $this->output->write(' |- Installing package... '); Installer::install($zip, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true], $extracted); } else { $name = GPM::getPackageName($extracted); if (!$name) { - $this->output->writeln("ERROR: Name could not be determined. Please specify with --name|-n"); + $this->output->writeln('ERROR: Name could not be determined. Please specify with --name|-n'); $this->output->writeln(''); Folder::delete($tmp_source); Folder::delete($tmp_zip); @@ -208,31 +211,31 @@ class DirectInstallCommand extends ConsoleCommand $install_path = GPM::getInstallPath($type, $name); $is_update = file_exists($install_path); - $this->output->write(" |- Checking destination... "); + $this->output->write(' |- Checking destination... '); Installer::isValidDestination(GRAV_ROOT . DS . $install_path); if (Installer::lastErrorCode() == Installer::IS_LINK) { $this->output->write("\x0D"); - $this->output->writeln(" |- Checking destination... symbolic link"); + $this->output->writeln(' |- Checking destination... symbolic link'); $this->output->writeln(" '- ERROR: symlink found... " . GRAV_ROOT . DS . $install_path . ''); $this->output->writeln(''); Folder::delete($tmp_source); Folder::delete($tmp_zip); exit; - } else { - $this->output->write("\x0D"); - $this->output->writeln(" |- Checking destination... ok"); } - $this->output->write(" |- Installing package... "); + $this->output->write("\x0D"); + $this->output->writeln(' |- Checking destination... ok'); + + $this->output->write(' |- Installing package... '); Installer::install( $zip, $this->destination, $options = [ 'install_path' => $install_path, - 'theme' => (($type == 'theme')), + 'theme' => (($type === 'theme')), 'is_update' => $is_update ], $extracted @@ -244,10 +247,10 @@ class DirectInstallCommand extends ConsoleCommand $this->output->write("\x0D"); if(Installer::lastErrorCode()) { - $this->output->writeln(" '- " . Installer::lastErrorMsg() . ""); + $this->output->writeln(" '- " . Installer::lastErrorMsg() . ''); $this->output->writeln(''); } else { - $this->output->writeln(" |- Installing package... ok"); + $this->output->writeln(' |- Installing package... ok'); $this->output->writeln(" '- Success! "); $this->output->writeln(''); } diff --git a/system/src/Grav/Console/Gpm/IndexCommand.php b/system/src/Grav/Console/Gpm/IndexCommand.php index 8c457063f..876037e6e 100644 --- a/system/src/Grav/Console/Gpm/IndexCommand.php +++ b/system/src/Grav/Console/Gpm/IndexCommand.php @@ -1,4 +1,5 @@ setName("index") + ->setName('index') ->addOption( 'force', 'f', @@ -91,7 +92,7 @@ class IndexCommand extends ConsoleCommand InputOption::VALUE_NONE, 'Reverses the order of the output.' ) - ->setDescription("Lists the plugins and themes available for installation") + ->setDescription('Lists the plugins and themes available for installation') ->setHelp('The index command lists the plugins and themes available for installation') ; } @@ -123,7 +124,7 @@ class IndexCommand extends ConsoleCommand } foreach ($data as $type => $packages) { - $this->output->writeln("" . strtoupper($type) . " [ " . count($packages) . " ]"); + $this->output->writeln('' . strtoupper($type) . ' [ ' . \count($packages) . ' ]'); $packages = $this->sort($packages); if (!empty($packages)) { @@ -134,7 +135,7 @@ class IndexCommand extends ConsoleCommand foreach ($packages as $slug => $package) { $row = [ 'Count' => $index++ + 1, - 'Name' => "" . Utils::truncate($package->name, 20, false, ' ', '...') . " ", + 'Name' => '' . Utils::truncate($package->name, 20, false, ' ', '...') . ' ', 'Slug' => $slug, 'Version'=> $this->version($package), 'Installed' => $this->installed($package) @@ -149,10 +150,10 @@ class IndexCommand extends ConsoleCommand } $this->output->writeln('You can either get more informations about a package by typing:'); - $this->output->writeln(' ' . $this->argv . ' info '); + $this->output->writeln(" {$this->argv} info "); $this->output->writeln(''); $this->output->writeln('Or you can install a package by typing:'); - $this->output->writeln(' ' . $this->argv . ' install '); + $this->output->writeln(" {$this->argv} install "); $this->output->writeln(''); } @@ -164,19 +165,19 @@ class IndexCommand extends ConsoleCommand private function version($package) { $list = $this->gpm->{'getUpdatable' . ucfirst($package->package_type)}(); - $package = isset($list[$package->slug]) ? $list[$package->slug] : $package; - $type = ucfirst(preg_replace("/s$/", '', $package->package_type)); + $package = $list[$package->slug] ?? $package; + $type = ucfirst(preg_replace('/s$/', '', $package->package_type)); $updatable = $this->gpm->{'is' . $type . 'Updatable'}($package->slug); $installed = $this->gpm->{'is' . $type . 'Installed'}($package->slug); $local = $this->gpm->{'getInstalled' . $type}($package->slug); if (!$installed || !$updatable) { $version = $installed ? $local->version : $package->version; - return "v" . $version . ""; + return "v{$version}"; } if ($updatable) { - return "v" . $package->version . " -> v" . $package->available . ""; + return "v{$package->version} -> v{$package->available}"; } return ''; @@ -190,8 +191,9 @@ class IndexCommand extends ConsoleCommand private function installed($package) { $package = isset($list[$package->slug]) ? $list[$package->slug] : $package; - $type = ucfirst(preg_replace("/s$/", '', $package->package_type)); - $installed = $this->gpm->{'is' . $type . 'Installed'}($package->slug); + $type = ucfirst(preg_replace('/s$/', '', $package->package_type)); + $method = 'is' . $type . 'Installed'; + $installed = $this->gpm->{$method}($package->slug); return !$installed ? 'not installed' : 'installed'; } @@ -218,26 +220,28 @@ class IndexCommand extends ConsoleCommand $this->options['desc'] ]; - if (count(array_filter($filter))) { + if (\count(array_filter($filter))) { foreach ($data as $type => $packages) { foreach ($packages as $slug => $package) { $filter = true; // Filtering by string if ($this->options['filter']) { - $filter = preg_grep('/(' . (implode('|', $this->options['filter'])) . ')/i', [$slug, $package->name]); + $filter = preg_grep('/(' . implode('|', $this->options['filter']) . ')/i', [$slug, $package->name]); } // Filtering updatables only - if ($this->options['installed-only'] && $filter) { - $method = ucfirst(preg_replace("/s$/", '', $package->package_type)); - $filter = $this->gpm->{'is' . $method . 'Installed'}($package->slug); + if ($filter && $this->options['installed-only']) { + $method = ucfirst(preg_replace('/s$/', '', $package->package_type)); + $function = 'is' . $method . 'Installed'; + $filter = $this->gpm->{$function}($package->slug); } // Filtering updatables only - if ($this->options['updates-only'] && $filter) { - $method = ucfirst(preg_replace("/s$/", '', $package->package_type)); - $filter = $this->gpm->{'is' . $method . 'Updatable'}($package->slug); + if ($filter && $this->options['updates-only']) { + $method = ucfirst(preg_replace('/s$/', '', $package->package_type)); + $function = 'is' . $method . 'Updatable'; + $filter = $this->gpm->{$function}($package->slug); } if (!$filter) { diff --git a/system/src/Grav/Console/Gpm/InfoCommand.php b/system/src/Grav/Console/Gpm/InfoCommand.php index 8c1d50e83..e73889464 100644 --- a/system/src/Grav/Console/Gpm/InfoCommand.php +++ b/system/src/Grav/Console/Gpm/InfoCommand.php @@ -1,4 +1,5 @@ setName("info") + ->setName('info') ->addOption( 'force', 'f', @@ -51,7 +52,7 @@ class InfoCommand extends ConsoleCommand InputArgument::REQUIRED, 'The package of which more informations are desired. Use the "index" command for a list of packages' ) - ->setDescription("Shows more informations about a package") + ->setDescription('Shows more informations about a package') ->setHelp('The info shows more informations about a package'); } @@ -69,19 +70,19 @@ class InfoCommand extends ConsoleCommand $foundPackage = $this->gpm->findPackage($this->input->getArgument('package')); if (!$foundPackage) { - $this->output->writeln("The package '" . $this->input->getArgument('package') . "' was not found in the Grav repository."); + $this->output->writeln("The package '{$this->input->getArgument('package')}' was not found in the Grav repository."); $this->output->writeln(''); - $this->output->writeln("You can list all the available packages by typing:"); - $this->output->writeln(" " . $this->argv . " index"); + $this->output->writeln('You can list all the available packages by typing:'); + $this->output->writeln(" {$this->argv} index"); $this->output->writeln(''); exit; } - $this->output->writeln("Found package '" . $this->input->getArgument('package') . "' under the '" . ucfirst($foundPackage->package_type) . "' section"); + $this->output->writeln("Found package '{$this->input->getArgument('package')}' under the '" . ucfirst($foundPackage->package_type) . "' section"); $this->output->writeln(''); - $this->output->writeln("" . $foundPackage->name . " [" . $foundPackage->slug . "]"); - $this->output->writeln(str_repeat('-', strlen($foundPackage->name) + strlen($foundPackage->slug) + 3)); - $this->output->writeln("" . strip_tags($foundPackage->description_plain) . ""); + $this->output->writeln("{$foundPackage->name} [{$foundPackage->slug}]"); + $this->output->writeln(str_repeat('-', \strlen($foundPackage->name) + \strlen($foundPackage->slug) + 3)); + $this->output->writeln('' . strip_tags($foundPackage->description_plain) . ''); $this->output->writeln(''); $packageURL = ''; @@ -89,8 +90,8 @@ class InfoCommand extends ConsoleCommand $packageURL = '<' . $foundPackage->author['url'] . '>'; } - $this->output->writeln("" . str_pad("Author", - 12) . ": " . $foundPackage->author['name'] . ' <' . $foundPackage->author['email'] . '> ' . $packageURL); + $this->output->writeln('' . str_pad('Author', + 12) . ': ' . $foundPackage->author['name'] . ' <' . $foundPackage->author['email'] . '> ' . $packageURL); foreach ([ 'version', @@ -105,21 +106,21 @@ class InfoCommand extends ConsoleCommand 'zipball_url', 'license' ] as $info) { - if (isset($foundPackage->$info)) { + if (isset($foundPackage->{$info})) { $name = ucfirst($info); - $data = $foundPackage->$info; + $data = $foundPackage->{$info}; - if ($info == 'zipball_url') { - $name = "Download"; + if ($info === 'zipball_url') { + $name = 'Download'; } - if ($info == 'date') { - $name = "Last Update"; + if ($info === 'date') { + $name = 'Last Update'; $data = date('D, j M Y, H:i:s, P ', strtotime('2014-09-16T00:07:16Z')); } $name = str_pad($name, 12); - $this->output->writeln("" . $name . ": " . $data); + $this->output->writeln("{$name}: {$data}"); } } @@ -131,48 +132,48 @@ class InfoCommand extends ConsoleCommand if ($installed && $updatable) { $local = $this->gpm->{'getInstalled'. $type}($foundPackage->slug); $this->output->writeln(''); - $this->output->writeln("Currently installed version: " . $local->version . ""); + $this->output->writeln("Currently installed version: {$local->version}"); $this->output->writeln(''); } // display changelog information $questionHelper = $this->getHelper('question'); - $question = new ConfirmationQuestion("Would you like to read the changelog? [y|N] ", + $question = new ConfirmationQuestion('Would you like to read the changelog? [y|N] ', false); $answer = $this->all_yes ? true : $questionHelper->ask($this->input, $this->output, $question); if ($answer) { $changelog = $foundPackage->changelog; - $this->output->writeln(""); + $this->output->writeln(''); foreach ($changelog as $version => $log) { $title = $version . ' [' . $log['date'] . ']'; $content = preg_replace_callback('/\d\.\s\[\]\(#(.*)\)/', function ($match) { - return "\n" . ucfirst($match[1]) . ":"; + return "\n" . ucfirst($match[1]) . ':'; }, $log['content']); - $this->output->writeln(''.$title.''); - $this->output->writeln(str_repeat('-', strlen($title))); + $this->output->writeln("{$title}"); + $this->output->writeln(str_repeat('-', \strlen($title))); $this->output->writeln($content); - $this->output->writeln(""); + $this->output->writeln(''); - $question = new ConfirmationQuestion("Press [ENTER] to continue or [q] to quit ", true); + $question = new ConfirmationQuestion('Press [ENTER] to continue or [q] to quit ', true); $answer = $this->all_yes ? false : $questionHelper->ask($this->input, $this->output, $question); if (!$answer) { break; } - $this->output->writeln(""); + $this->output->writeln(''); } } $this->output->writeln(''); if ($installed && $updatable) { - $this->output->writeln("You can update this package by typing:"); - $this->output->writeln(" " . $this->argv . " update " . $foundPackage->slug . ""); + $this->output->writeln('You can update this package by typing:'); + $this->output->writeln(" {$this->argv} update {$foundPackage->slug}"); } else { $this->output->writeln("You can install this package by typing:"); - $this->output->writeln(" " . $this->argv . " install " . $foundPackage->slug . ""); + $this->output->writeln(" {$this->argv} install {$foundPackage->slug}"); } $this->output->writeln(''); diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index 031142825..7c54a8560 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -1,4 +1,5 @@ setName("install") + ->setName('install') ->addOption( 'force', 'f', @@ -82,7 +83,7 @@ class InstallCommand extends ConsoleCommand InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Package(s) to install. Use "bin/gpm index" to list packages. Use "bin/gpm direct-install" to install a specific version' ) - ->setDescription("Performs the installation of plugins and themes") + ->setDescription('Performs the installation of plugins and themes') ->setHelp('The install command allows to install plugins and themes'); } @@ -117,28 +118,26 @@ class InstallCommand extends ConsoleCommand !Installer::isGravInstance($this->destination) || !Installer::isValidDestination($this->destination, [Installer::EXISTS, Installer::IS_LINK]) ) { - $this->output->writeln("ERROR: " . Installer::lastErrorMsg()); + $this->output->writeln('ERROR: ' . Installer::lastErrorMsg()); exit; } $this->output->writeln(''); if (!$this->data['total']) { - $this->output->writeln("Nothing to install."); + $this->output->writeln('Nothing to install.'); $this->output->writeln(''); exit; } - if (count($this->data['not_found'])) { - $this->output->writeln("These packages were not found on Grav: " . implode(', ', - array_keys($this->data['not_found'])) . ""); + if (\count($this->data['not_found'])) { + $this->output->writeln('These packages were not found on Grav: ' . implode(', ', + array_keys($this->data['not_found'])) . ''); } - unset($this->data['not_found']); - unset($this->data['total']); + unset($this->data['not_found'], $this->data['total']); - - if (isset($this->local_config)) { + if (null !== $this->local_config) { // Symlinks available, ask if Grav should use them $this->use_symlinks = false; $helper = $this->getHelper('question'); @@ -149,8 +148,6 @@ class InstallCommand extends ConsoleCommand if ($answer) { $this->use_symlinks = true; } - - } $this->output->writeln(''); @@ -160,22 +157,22 @@ class InstallCommand extends ConsoleCommand } catch (\Exception $e) { //Error out if there are incompatible packages requirements and tell which ones, and what to do //Error out if there is any error in parsing the dependencies and their versions, and tell which one is broken - $this->output->writeln("" . $e->getMessage() . ""); + $this->output->writeln("{$e->getMessage()}"); return false; } if ($dependencies) { try { - $this->installDependencies($dependencies, 'install', "The following dependencies need to be installed..."); - $this->installDependencies($dependencies, 'update', "The following dependencies need to be updated..."); + $this->installDependencies($dependencies, 'install', 'The following dependencies need to be installed...'); + $this->installDependencies($dependencies, 'update', 'The following dependencies need to be updated...'); $this->installDependencies($dependencies, 'ignore', "The following dependencies can be updated as there is a newer version, but it's not mandatory...", false); } catch (\Exception $e) { - $this->output->writeln("Installation aborted"); + $this->output->writeln('Installation aborted'); return false; } - $this->output->writeln("Dependencies are OK"); - $this->output->writeln(""); + $this->output->writeln('Dependencies are OK'); + $this->output->writeln(''); } @@ -183,7 +180,7 @@ class InstallCommand extends ConsoleCommand foreach ($this->data as $data) { foreach ($data as $package_name => $package) { if (array_key_exists($package_name, $dependencies)) { - $this->output->writeln("Package " . $package_name . " already installed as dependency"); + $this->output->writeln("Package {$package_name} already installed as dependency"); } else { $is_valid_destination = Installer::isValidDestination($this->destination . DS . $package->install_path); if ($is_valid_destination || Installer::lastErrorCode() == Installer::NOT_FOUND) { @@ -195,24 +192,24 @@ class InstallCommand extends ConsoleCommand $this->askConfirmationIfMajorVersionUpdated($package); $this->gpm->checkNoOtherPackageNeedsThisDependencyInALowerVersion($package->slug, $package->available, array_keys($data)); } catch (\Exception $e) { - $this->output->writeln("" . $e->getMessage() . ""); + $this->output->writeln("{$e->getMessage()}"); return false; } $helper = $this->getHelper('question'); - $question = new ConfirmationQuestion("The package $package_name is already installed, overwrite? [y|N] ", false); + $question = new ConfirmationQuestion("The package {$package_name} is already installed, overwrite? [y|N] ", false); $answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question); if ($answer) { $is_update = true; $this->processPackage($package, $is_update); } else { - $this->output->writeln("Package " . $package_name . " not overwritten"); + $this->output->writeln("Package {$package_name} not overwritten"); } } else { if (Installer::lastErrorCode() == Installer::IS_LINK) { - $this->output->writeln("Cannot overwrite existing symlink for $package_name"); - $this->output->writeln(""); + $this->output->writeln("Cannot overwrite existing symlink for {$package_name}"); + $this->output->writeln(''); } } } @@ -220,7 +217,7 @@ class InstallCommand extends ConsoleCommand } } - if (count($this->demo_processing) > 0) { + if (\count($this->demo_processing) > 0) { foreach ($this->demo_processing as $package) { $this->installDemoContent($package); } @@ -241,21 +238,21 @@ class InstallCommand extends ConsoleCommand { $helper = $this->getHelper('question'); $package_name = $package->name; - $new_version = $package->available ? $package->available : $this->gpm->getLatestVersionOfPackage($package->slug); + $new_version = $package->available ?: $this->gpm->getLatestVersionOfPackage($package->slug); $old_version = $package->version; $major_version_changed = explode('.', $new_version)[0] !== explode('.', $old_version)[0]; if ($major_version_changed) { if ($this->all_yes) { - $this->output->writeln("The package $package_name will be updated to a new major version $new_version, from $old_version"); + $this->output->writeln("The package {$package_name} will be updated to a new major version {$new_version}, from {$old_version}"); return; } - $question = new ConfirmationQuestion("The package $package_name will be updated to a new major version $new_version, from $old_version. Be sure to read what changed with the new major release. Continue? [y|N] ", false); + $question = new ConfirmationQuestion("The package {$package_name} will be updated to a new major version {$new_version}, from {$old_version}. Be sure to read what changed with the new major release. Continue? [y|N] ", false); if (!$helper->ask($this->input, $this->output, $question)) { - $this->output->writeln("Package " . $package_name . " not updated"); + $this->output->writeln("Package {$package_name} not updated"); exit; } } @@ -276,42 +273,42 @@ class InstallCommand extends ConsoleCommand public function installDependencies($dependencies, $type, $message, $required = true) { $packages = array_filter($dependencies, function ($action) use ($type) { return $action === $type; }); - if (count($packages) > 0) { + if (\count($packages) > 0) { $this->output->writeln($message); foreach ($packages as $dependencyName => $dependencyVersion) { - $this->output->writeln(" |- Package " . $dependencyName . ""); + $this->output->writeln(" |- Package {$dependencyName}"); } - $this->output->writeln(""); + $this->output->writeln(''); $helper = $this->getHelper('question'); - if ($type == 'install') { + if ($type === 'install') { $questionAction = 'Install'; } else { $questionAction = 'Update'; } - if (count($packages) == 1) { + if (\count($packages) === 1) { $questionArticle = 'this'; } else { $questionArticle = 'these'; } - if (count($packages) == 1) { + if (\count($packages) === 1) { $questionNoun = 'package'; } else { $questionNoun = 'packages'; } - $question = new ConfirmationQuestion("$questionAction $questionArticle $questionNoun? [Y|n] ", true); + $question = new ConfirmationQuestion("${questionAction} {$questionArticle} {$questionNoun}? [Y|n] ", true); $answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question); if ($answer) { foreach ($packages as $dependencyName => $dependencyVersion) { $package = $this->gpm->findPackage($dependencyName); - $this->processPackage($package, ($type == 'update') ? true : false); + $this->processPackage($package, $type === 'update'); } $this->output->writeln(''); } else { @@ -329,14 +326,14 @@ class InstallCommand extends ConsoleCommand private function processPackage($package, $is_update = false) { if (!$package) { - $this->output->writeln("Package not found on the GPM! "); + $this->output->writeln('Package not found on the GPM!'); $this->output->writeln(''); return; } $symlink = false; if ($this->use_symlinks) { - if ($this->getSymlinkSource($package) || !isset($package->version)) { + if (!isset($package->version) || $this->getSymlinkSource($package)) { $symlink = true; } } @@ -373,7 +370,7 @@ class InstallCommand extends ConsoleCommand $pages_dir = $dest_dir . DS . 'pages'; // Demo content exists, prompt to install it. - $this->output->writeln("Attention: " . $package->name . " contains demo content"); + $this->output->writeln("Attention: {$package->name} contains demo content"); $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Do you wish to install this demo content? [y|N] ', false); @@ -402,15 +399,15 @@ class InstallCommand extends ConsoleCommand // backup current pages folder if (file_exists($dest_dir)) { if (rename($pages_dir, $dest_dir . DS . $pages_backup)) { - $this->output->writeln(" |- Backing up pages... ok"); + $this->output->writeln(' |- Backing up pages... ok'); } else { - $this->output->writeln(" |- Backing up pages... failed"); + $this->output->writeln(' |- Backing up pages... failed'); } } } // Confirmation received, copy over the data - $this->output->writeln(" |- Installing demo content... ok "); + $this->output->writeln(' |- Installing demo content... ok '); Folder::rcopy($demo_dir, $dest_dir); $this->output->writeln(" '- Success! "); $this->output->writeln(''); @@ -475,13 +472,13 @@ class InstallCommand extends ConsoleCommand $to = $this->destination . DS . $package->install_path; $from = $this->getSymlinkSource($package); - $this->output->writeln("Preparing to Symlink " . $package->name . ""); - $this->output->write(" |- Checking source... "); + $this->output->writeln("Preparing to Symlink {$package->name}"); + $this->output->write(' |- Checking source... '); if (file_exists($from)) { - $this->output->writeln("ok"); + $this->output->writeln('ok'); - $this->output->write(" |- Checking destination... "); + $this->output->write(' |- Checking destination... '); $checks = $this->checkDestination($package); if (!$checks) { @@ -495,7 +492,7 @@ class InstallCommand extends ConsoleCommand symlink($from, $to); // extra white spaces to clear out the buffer properly - $this->output->writeln(" |- Symlinking package... ok "); + $this->output->writeln(' |- Symlinking package... ok '); $this->output->writeln(" '- Success! "); $this->output->writeln(''); } @@ -504,7 +501,7 @@ class InstallCommand extends ConsoleCommand return; } - $this->output->writeln("not found!"); + $this->output->writeln('not found!'); $this->output->writeln(" '- Installation failed or aborted."); } @@ -519,9 +516,9 @@ class InstallCommand extends ConsoleCommand $version = isset($package->available) ? $package->available : $package->version; $license = Licenses::get($package->slug); - $this->output->writeln("Preparing to install " . $package->name . " [v" . $version . "]"); + $this->output->writeln("Preparing to install {$package->name} [v{$version}]"); - $this->output->write(" |- Downloading package... 0%"); + $this->output->write(' |- Downloading package... 0%'); $this->file = $this->downloadPackage($package, $license); if (!$this->file) { @@ -531,14 +528,14 @@ class InstallCommand extends ConsoleCommand return false; } - $this->output->write(" |- Checking destination... "); + $this->output->write(' |- Checking destination... '); $checks = $this->checkDestination($package); if (!$checks) { $this->output->writeln(" '- Installation failed or aborted."); $this->output->writeln(''); } else { - $this->output->write(" |- Installing package... "); + $this->output->write(' |- Installing package... '); $installation = $this->installPackage($package, $is_update); if (!$installation) { $this->output->writeln(" '- Installation failed or aborted."); @@ -566,10 +563,10 @@ class InstallCommand extends ConsoleCommand $tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true); $this->tmp = $tmp_dir . '/Grav-' . uniqid(); $filename = $package->slug . basename($package->zipball_url); - $filename = preg_replace('/[\\\\\/:"*?&<>|]+/mi', '-', $filename); + $filename = preg_replace('/[\\\\\/:"*?&<>|]+/m', '-', $filename); $query = ''; - if ($package->premium) { + if (!empty($package->premium)) { $query = \json_encode(array_merge( $package->premium, [ @@ -588,7 +585,7 @@ class InstallCommand extends ConsoleCommand $error = str_replace("\n", "\n | '- ", $e->getMessage()); $this->output->write("\x0D"); // extra white spaces to clear out the buffer properly - $this->output->writeln(" |- Downloading package... error "); + $this->output->writeln(' |- Downloading package... error '); $this->output->writeln(" | '- " . $error); return false; @@ -597,7 +594,7 @@ class InstallCommand extends ConsoleCommand Folder::mkdir($this->tmp); $this->output->write("\x0D"); - $this->output->write(" |- Downloading package... 100%"); + $this->output->write(' |- Downloading package... 100%'); $this->output->writeln(''); file_put_contents($this->tmp . DS . $filename, $output); @@ -618,7 +615,7 @@ class InstallCommand extends ConsoleCommand if (Installer::lastErrorCode() == Installer::IS_LINK) { $this->output->write("\x0D"); - $this->output->writeln(" |- Checking destination... symbolic link"); + $this->output->writeln(' |- Checking destination... symbolic link'); if ($this->all_yes) { $this->output->writeln(" | '- Skipped automatically."); @@ -634,13 +631,13 @@ class InstallCommand extends ConsoleCommand $this->output->writeln(" | '- You decided to not delete the symlink automatically."); return false; - } else { - unlink($this->destination . DS . $package->install_path); } + + unlink($this->destination . DS . $package->install_path); } $this->output->write("\x0D"); - $this->output->writeln(" |- Checking destination... ok"); + $this->output->writeln(' |- Checking destination... ok'); return true; } @@ -657,14 +654,14 @@ class InstallCommand extends ConsoleCommand { $type = $package->package_type; - Installer::install($this->file, $this->destination, ['install_path' => $package->install_path, 'theme' => (($type == 'themes')), 'is_update' => $is_update]); + Installer::install($this->file, $this->destination, ['install_path' => $package->install_path, 'theme' => $type === 'themes', 'is_update' => $is_update]); $error_code = Installer::lastErrorCode(); Folder::delete($this->tmp); if ($error_code) { $this->output->write("\x0D"); // extra white spaces to clear out the buffer properly - $this->output->writeln(" |- Installing package... error "); + $this->output->writeln(' |- Installing package... error '); $this->output->writeln(" | '- " . Installer::lastErrorMsg()); return false; @@ -674,12 +671,12 @@ class InstallCommand extends ConsoleCommand if ($message) { $this->output->write("\x0D"); // extra white spaces to clear out the buffer properly - $this->output->writeln(" |- " . $message); + $this->output->writeln(" |- {$message}"); } $this->output->write("\x0D"); // extra white spaces to clear out the buffer properly - $this->output->writeln(" |- Installing package... ok "); + $this->output->writeln(' |- Installing package... ok '); return true; } @@ -690,7 +687,7 @@ class InstallCommand extends ConsoleCommand public function progress($progress) { $this->output->write("\x0D"); - $this->output->write(" |- Downloading package... " . str_pad($progress['percent'], 5, " ", + $this->output->write(' |- Downloading package... ' . str_pad($progress['percent'], 5, ' ', STR_PAD_LEFT) . '%'); } } diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php index d406a95b6..9d41bffd9 100644 --- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php +++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php @@ -1,4 +1,5 @@ setName("self-upgrade") + ->setName('self-upgrade') ->setAliases(['selfupgrade', 'selfupdate']) ->addOption( 'force', @@ -78,7 +79,7 @@ class SelfupgradeCommand extends ConsoleCommand InputOption::VALUE_NONE, 'Option to overwrite packages if they already exist' ) - ->setDescription("Detects and performs an update of Grav itself when available") + ->setDescription('Detects and performs an update of Grav itself when available') ->setHelp('The update command updates Grav itself when a new version is available'); } @@ -100,26 +101,26 @@ class SelfupgradeCommand extends ConsoleCommand $release = strftime('%c', strtotime($this->upgrader->getReleaseDate())); if (!$this->upgrader->meetsRequirements()) { - $this->output->writeln("ATTENTION:"); - $this->output->writeln(" Grav has increased the minimum PHP requirement."); - $this->output->writeln(" You are currently running PHP " . phpversion() . ", but PHP " . $this->upgrader->minPHPVersion() . " is required."); - $this->output->writeln(" Additional information: http://getgrav.org/blog/changing-php-requirements"); - $this->output->writeln(""); - $this->output->writeln("Selfupgrade aborted."); - $this->output->writeln(""); + $this->output->writeln('ATTENTION:'); + $this->output->writeln(' Grav has increased the minimum PHP requirement.'); + $this->output->writeln(' You are currently running PHP ' . phpversion() . ', but PHP ' . $this->upgrader->minPHPVersion() . ' is required.'); + $this->output->writeln(' Additional information: http://getgrav.org/blog/changing-php-requirements'); + $this->output->writeln(''); + $this->output->writeln('Selfupgrade aborted.'); + $this->output->writeln(''); exit; } if (!$this->overwrite && !$this->upgrader->isUpgradable()) { - $this->output->writeln("You are already running the latest version of Grav (v" . $local . ") released on " . $release); + $this->output->writeln("You are already running the latest version of Grav (v{$local}) released on {$release}"); exit; } Installer::isValidDestination(GRAV_ROOT . '/system'); if (Installer::IS_LINK === Installer::lastErrorCode()) { - $this->output->writeln("ATTENTION: Grav is symlinked, cannot upgrade, aborting..."); + $this->output->writeln('ATTENTION: Grav is symlinked, cannot upgrade, aborting...'); $this->output->writeln(''); - $this->output->writeln("You are currently running a symbolically linked Grav v" . $local . ". Latest available is v". $remote . "."); + $this->output->writeln("You are currently running a symbolically linked Grav v{$local}. Latest available is v{$remote}."); exit; } @@ -129,51 +130,51 @@ class SelfupgradeCommand extends ConsoleCommand $questionHelper = $this->getHelper('question'); - $this->output->writeln("Grav v$remote is now available [release date: $release]."); - $this->output->writeln("You are currently using v" . GRAV_VERSION . "."); + $this->output->writeln("Grav v{$remote} is now available [release date: {$release}]."); + $this->output->writeln('You are currently using v' . GRAV_VERSION . '.'); if (!$this->all_yes) { - $question = new ConfirmationQuestion("Would you like to read the changelog before proceeding? [y|N] ", + $question = new ConfirmationQuestion('Would you like to read the changelog before proceeding? [y|N] ', false); $answer = $questionHelper->ask($this->input, $this->output, $question); if ($answer) { $changelog = $this->upgrader->getChangelog(GRAV_VERSION); - $this->output->writeln(""); + $this->output->writeln(''); foreach ($changelog as $version => $log) { $title = $version . ' [' . $log['date'] . ']'; $content = preg_replace_callback('/\d\.\s\[\]\(#(.*)\)/', function ($match) { - return "\n" . ucfirst($match[1]) . ":"; + return "\n" . ucfirst($match[1]) . ':'; }, $log['content']); $this->output->writeln($title); - $this->output->writeln(str_repeat('-', strlen($title))); + $this->output->writeln(str_repeat('-', \strlen($title))); $this->output->writeln($content); - $this->output->writeln(""); + $this->output->writeln(''); } - $question = new ConfirmationQuestion("Press [ENTER] to continue.", true); + $question = new ConfirmationQuestion('Press [ENTER] to continue.', true); $questionHelper->ask($this->input, $this->output, $question); } - $question = new ConfirmationQuestion("Would you like to upgrade now? [y|N] ", false); + $question = new ConfirmationQuestion('Would you like to upgrade now? [y|N] ', false); $answer = $questionHelper->ask($this->input, $this->output, $question); if (!$answer) { - $this->output->writeln("Aborting..."); + $this->output->writeln('Aborting...'); exit; } } - $this->output->writeln(""); - $this->output->writeln("Preparing to upgrade to v$remote.."); + $this->output->writeln(''); + $this->output->writeln("Preparing to upgrade to v{$remote}.."); - $this->output->write(" |- Downloading upgrade [" . $this->formatBytes($update['size']) . "]... 0%"); + $this->output->write(" |- Downloading upgrade [{$this->formatBytes($update['size'])}]... 0%"); $this->file = $this->download($update); - $this->output->write(" |- Installing upgrade... "); + $this->output->write(' |- Installing upgrade... '); $installation = $this->upgrade(); if (!$installation) { @@ -202,7 +203,7 @@ class SelfupgradeCommand extends ConsoleCommand Folder::mkdir($this->tmp); $this->output->write("\x0D"); - $this->output->write(" |- Downloading upgrade [" . $this->formatBytes($package['size']) . "]... 100%"); + $this->output->write(" |- Downloading upgrade [{$this->formatBytes($package['size'])}]... 100%"); $this->output->writeln(''); file_put_contents($this->tmp . DS . $package['name'], $output); @@ -223,7 +224,7 @@ class SelfupgradeCommand extends ConsoleCommand if ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) { $this->output->write("\x0D"); // extra white spaces to clear out the buffer properly - $this->output->writeln(" |- Installing upgrade... error "); + $this->output->writeln(' |- Installing upgrade... error '); $this->output->writeln(" | '- " . Installer::lastErrorMsg()); return false; @@ -231,7 +232,7 @@ class SelfupgradeCommand extends ConsoleCommand $this->output->write("\x0D"); // extra white spaces to clear out the buffer properly - $this->output->writeln(" |- Installing upgrade... ok "); + $this->output->writeln(' |- Installing upgrade... ok '); return true; } @@ -242,8 +243,8 @@ class SelfupgradeCommand extends ConsoleCommand public function progress($progress) { $this->output->write("\x0D"); - $this->output->write(" |- Downloading upgrade [" . $this->formatBytes($progress["filesize"]) . "]... " . str_pad($progress['percent'], - 5, " ", STR_PAD_LEFT) . '%'); + $this->output->write(" |- Downloading upgrade [{$this->formatBytes($progress["filesize"]) }]... " . str_pad($progress['percent'], + 5, ' ', STR_PAD_LEFT) . '%'); } /** @@ -257,6 +258,6 @@ class SelfupgradeCommand extends ConsoleCommand $base = log($size) / log(1024); $suffixes = array('', 'k', 'M', 'G', 'T'); - return round(pow(1024, $base - floor($base)), $precision) . $suffixes[(int)floor($base)]; + return round(1024 ** ($base - floor($base)), $precision) . $suffixes[(int)floor($base)]; } } diff --git a/system/src/Grav/Console/Gpm/UninstallCommand.php b/system/src/Grav/Console/Gpm/UninstallCommand.php index 34b04ee4d..4cf4ec0e0 100644 --- a/system/src/Grav/Console/Gpm/UninstallCommand.php +++ b/system/src/Grav/Console/Gpm/UninstallCommand.php @@ -1,4 +1,5 @@ setName("uninstall") + ->setName('uninstall') ->addOption( 'all-yes', 'y', @@ -61,7 +62,7 @@ class UninstallCommand extends ConsoleCommand InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'The package(s) that are desired to be removed. Use the "index" command for a list of packages' ) - ->setDescription("Performs the uninstallation of plugins and themes") + ->setDescription('Performs the uninstallation of plugins and themes') ->setHelp('The uninstall command allows to uninstall plugins and themes'); } @@ -91,23 +92,22 @@ class UninstallCommand extends ConsoleCommand $this->output->writeln(''); if (!$this->data['total']) { - $this->output->writeln("Nothing to uninstall."); + $this->output->writeln('Nothing to uninstall.'); $this->output->writeln(''); exit; } if (count($this->data['not_found'])) { - $this->output->writeln("These packages were not found installed: " . implode(', ', - $this->data['not_found']) . ""); + $this->output->writeln('These packages were not found installed: ' . implode(', ', + $this->data['not_found']) . ''); } - unset($this->data['not_found']); - unset($this->data['total']); + unset($this->data['not_found'], $this->data['total']); foreach ($this->data as $slug => $package) { - $this->output->writeln("Preparing to uninstall " . $package->name . " [v" . $package->version . "]"); + $this->output->writeln("Preparing to uninstall {$package->name} [v{$package->version}]"); - $this->output->write(" |- Checking destination... "); + $this->output->write(' |- Checking destination... '); $checks = $this->checkDestination($slug, $package); if (!$checks) { @@ -147,12 +147,12 @@ class UninstallCommand extends ConsoleCommand if (count($dependent_packages) > ($is_dependency ? 1 : 0)) { $this->output->writeln(''); $this->output->writeln(''); - $this->output->writeln("Uninstallation failed."); + $this->output->writeln('Uninstallation failed.'); $this->output->writeln(''); - if (count($dependent_packages) > ($is_dependency ? 2 : 1)) { - $this->output->writeln("The installed packages " . implode(', ', $dependent_packages) . " depends on this package. Please remove those first."); + if (\count($dependent_packages) > ($is_dependency ? 2 : 1)) { + $this->output->writeln('The installed packages ' . implode(', ', $dependent_packages) . ' depends on this package. Please remove those first.'); } else { - $this->output->writeln("The installed package " . implode(', ', $dependent_packages) . " depends on this package. Please remove it first."); + $this->output->writeln('The installed package ' . implode(', ', $dependent_packages) . ' depends on this package. Please remove it first.'); } $this->output->writeln(''); @@ -165,12 +165,12 @@ class UninstallCommand extends ConsoleCommand if ($is_dependency) { foreach ($dependencies as $key => $dependency) { - if (in_array($dependency['name'], $this->dependencies)) { + if (\in_array($dependency['name'], $this->dependencies, true)) { unset($dependencies[$key]); } } } else { - if (count($dependencies) > 0) { + if (\count($dependencies) > 0) { $this->output->writeln(' `- Dependencies found...'); $this->output->writeln(''); } @@ -182,7 +182,7 @@ class UninstallCommand extends ConsoleCommand $this->dependencies[] = $dependency['name']; - if (is_array($dependency)) { + if (\is_array($dependency)) { $dependency = $dependency['name']; } if ($dependency === 'grav' || $dependency === 'php') { @@ -194,9 +194,9 @@ class UninstallCommand extends ConsoleCommand $dependency_exists = $this->packageExists($dependency, $dependencyPackage); if ($dependency_exists == Installer::EXISTS) { - $this->output->writeln("A dependency on " . $dependencyPackage->name . " [v" . $dependencyPackage->version . "] was found"); + $this->output->writeln("A dependency on {$dependencyPackage->name} [v{$dependencyPackage->version}] was found"); - $question = new ConfirmationQuestion(" |- Uninstall " . $dependencyPackage->name . "? [y|N] ", false); + $question = new ConfirmationQuestion(" |- Uninstall {$dependencyPackage->name}? [y|N] ", false); $answer = $this->all_yes ? true : $questionHelper->ask($this->input, $this->output, $question); if ($answer) { @@ -210,7 +210,7 @@ class UninstallCommand extends ConsoleCommand } $this->output->writeln(''); } else { - $this->output->writeln(" '- You decided not to uninstall " . $dependencyPackage->name . "."); + $this->output->writeln(" '- You decided not to uninstall {$dependencyPackage->name}."); $this->output->writeln(''); } } @@ -225,21 +225,21 @@ class UninstallCommand extends ConsoleCommand $errorCode = Installer::lastErrorCode(); if ($errorCode && $errorCode !== Installer::IS_LINK && $errorCode !== Installer::EXISTS) { - $this->output->writeln(" |- Uninstalling " . $package->name . " package... error "); - $this->output->writeln(" | '- " . Installer::lastErrorMsg().""); + $this->output->writeln(" |- Uninstalling {$package->name} package... error "); + $this->output->writeln(" | '- " . Installer::lastErrorMsg() . ''); return false; } $message = Installer::getMessage(); if ($message) { - $this->output->writeln(" |- " . $message); + $this->output->writeln(" |- {$message}"); } if (!$is_dependency && $this->dependencies) { - $this->output->writeln("Finishing up uninstalling " . $package->name . ""); + $this->output->writeln("Finishing up uninstalling {$package->name}"); } - $this->output->writeln(" |- Uninstalling " . $package->name . " package... ok "); + $this->output->writeln(" |- Uninstalling {$package->name} package... ok "); @@ -261,7 +261,7 @@ class UninstallCommand extends ConsoleCommand if ($exists == Installer::IS_LINK) { $this->output->write("\x0D"); - $this->output->writeln(" |- Checking destination... symbolic link"); + $this->output->writeln(' |- Checking destination... symbolic link'); if ($this->all_yes) { $this->output->writeln(" | '- Skipped automatically."); @@ -281,7 +281,7 @@ class UninstallCommand extends ConsoleCommand } $this->output->write("\x0D"); - $this->output->writeln(" |- Checking destination... ok"); + $this->output->writeln(' |- Checking destination... ok'); return true; } diff --git a/system/src/Grav/Console/Gpm/UpdateCommand.php b/system/src/Grav/Console/Gpm/UpdateCommand.php index 06913b169..9a9e077b2 100644 --- a/system/src/Grav/Console/Gpm/UpdateCommand.php +++ b/system/src/Grav/Console/Gpm/UpdateCommand.php @@ -1,4 +1,5 @@ setName("update") + ->setName('update') ->addOption( 'force', 'f', @@ -106,7 +107,7 @@ class UpdateCommand extends ConsoleCommand InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'The package or packages that is desired to update. By default all available updates will be applied.' ) - ->setDescription("Detects and performs an update of plugins and themes when available") + ->setDescription('Detects and performs an update of plugins and themes when available') ->setHelp('The update command updates plugins and themes when a new version is available'); } @@ -119,14 +120,14 @@ class UpdateCommand extends ConsoleCommand $local = $this->upgrader->getLocalVersion(); $remote = $this->upgrader->getRemoteVersion(); if ($local !== $remote) { - $this->output->writeln("WARNING: A new version of Grav is available. You should update Grav before updating plugins and themes. If you continue without updating Grav, some plugins or themes may stop working."); - $this->output->writeln(""); + $this->output->writeln('WARNING: A new version of Grav is available. You should update Grav before updating plugins and themes. If you continue without updating Grav, some plugins or themes may stop working.'); + $this->output->writeln(''); $questionHelper = $this->getHelper('question'); - $question = new ConfirmationQuestion("Continue with the update process? [Y|n] ", true); + $question = new ConfirmationQuestion('Continue with the update process? [Y|n] ', true); $answer = $questionHelper->ask($this->input, $this->output, $question); if (!$answer) { - $this->output->writeln("Update aborted. Exiting..."); + $this->output->writeln('Update aborted. Exiting...'); exit; } } @@ -141,7 +142,7 @@ class UpdateCommand extends ConsoleCommand $this->destination = realpath($this->input->getOption('destination')); if (!Installer::isGravInstance($this->destination)) { - $this->output->writeln("ERROR: " . Installer::lastErrorMsg()); + $this->output->writeln('ERROR: ' . Installer::lastErrorMsg()); exit; } if ($this->input->getOption('plugins') === false && $this->input->getOption('themes') === false) { @@ -153,27 +154,26 @@ class UpdateCommand extends ConsoleCommand if ($this->overwrite) { $this->data = $this->gpm->getInstallable($list_type); - $description = " can be overwritten"; + $description = ' can be overwritten'; } else { $this->data = $this->gpm->getUpdatable($list_type); - $description = " need updating"; + $description = ' need updating'; } $only_packages = array_map('strtolower', $this->input->getArgument('package')); if (!$this->overwrite && !$this->data['total']) { - $this->output->writeln("Nothing to update."); + $this->output->writeln('Nothing to update.'); exit; } - $this->output->write("Found " . $this->gpm->countInstalled() . " packages installed of which " . $this->data['total'] . "" . $description); + $this->output->write("Found {$this->gpm->countInstalled()} packages installed of which {$this->data['total']}{$description}"); $limit_to = $this->userInputPackages($only_packages); $this->output->writeln(''); - unset($this->data['total']); - unset($limit_to['total']); + unset($this->data['total'], $limit_to['total']); // updates review @@ -182,7 +182,7 @@ class UpdateCommand extends ConsoleCommand $index = 0; foreach ($this->data as $packages) { foreach ($packages as $slug => $package) { - if (count($only_packages) && !array_key_exists($slug, $limit_to)) { + if (!array_key_exists($slug, $limit_to) && \count($only_packages)) { continue; } @@ -192,11 +192,11 @@ class UpdateCommand extends ConsoleCommand $this->output->writeln( // index - str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . ". " . + str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . '. ' . // name - "" . str_pad($package->name, 15) . " " . + '' . str_pad($package->name, 15) . ' ' . // version - "[v" . $package->version . " -> v" . $package->available . "]" + "[v{$package->version} -> v{$package->available}]" ); $slugs[] = $slug; } @@ -204,13 +204,13 @@ class UpdateCommand extends ConsoleCommand if (!$this->all_yes) { // prompt to continue - $this->output->writeln(""); + $this->output->writeln(''); $questionHelper = $this->getHelper('question'); - $question = new ConfirmationQuestion("Continue with the update process? [Y|n] ", true); + $question = new ConfirmationQuestion('Continue with the update process? [Y|n] ', true); $answer = $questionHelper->ask($this->input, $this->output, $question); if (!$answer) { - $this->output->writeln("Update aborted. Exiting..."); + $this->output->writeln('Update aborted. Exiting...'); exit; } } @@ -228,7 +228,7 @@ class UpdateCommand extends ConsoleCommand $command_exec = $install_command->run($args, $this->output); if ($command_exec != 0) { - $this->output->writeln("Error: An error occurred while trying to install the packages"); + $this->output->writeln('Error: An error occurred while trying to install the packages'); exit; } } @@ -243,14 +243,14 @@ class UpdateCommand extends ConsoleCommand $found = ['total' => 0]; $ignore = []; - if (!count($only_packages)) { + if (!\count($only_packages)) { $this->output->writeln(''); } else { foreach ($only_packages as $only_package) { $find = $this->gpm->findPackage($only_package); if (!$find || (!$this->overwrite && !$this->gpm->isUpdatable($find->slug))) { - $name = isset($find->slug) ? $find->slug : $only_package; + $name = $find->slug ?? $only_package; $ignore[$name] = $name; } else { $found[$find->slug] = $find; @@ -264,18 +264,18 @@ class UpdateCommand extends ConsoleCommand $list = array_keys($list); if ($found['total'] !== $this->data['total']) { - $this->output->write(", only " . $found['total'] . " will be updated"); + $this->output->write(", only {$found['total']} will be updated"); } $this->output->writeln(''); - $this->output->writeln("Limiting updates for only " . implode(', ', - $list) . ""); + $this->output->writeln('Limiting updates for only ' . implode(', ', + $list) . ''); } - if (count($ignore)) { + if (\count($ignore)) { $this->output->writeln(''); - $this->output->writeln("Packages not found or not requiring updates: " . implode(', ', - $ignore) . ""); + $this->output->writeln('Packages not found or not requiring updates: ' . implode(', ', + $ignore) . ''); } } diff --git a/system/src/Grav/Console/Gpm/VersionCommand.php b/system/src/Grav/Console/Gpm/VersionCommand.php index eb7872ead..48b2a0e54 100644 --- a/system/src/Grav/Console/Gpm/VersionCommand.php +++ b/system/src/Grav/Console/Gpm/VersionCommand.php @@ -1,4 +1,5 @@ setName("version") + ->setName('version') ->addOption( 'force', 'f', @@ -40,7 +41,7 @@ class VersionCommand extends ConsoleCommand InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'The package or packages that is desired to know the version of. By default and if not specified this would be grav' ) - ->setDescription("Shows the version of an installed package. If available also shows pending updates.") + ->setDescription('Shows the version of an installed package. If available also shows pending updates.') ->setHelp('The version command displays the current version of a package installed and, if available, the available version of pending updates'); } @@ -64,13 +65,13 @@ class VersionCommand extends ConsoleCommand $version = null; $updatable = false; - if ($package == 'grav') { + if ($package === 'grav') { $name = 'Grav'; $version = GRAV_VERSION; $upgrader = new Upgrader(); if ($upgrader->isUpgradable()) { - $updatable = ' [upgradable: v' . $upgrader->getRemoteVersion() . ']'; + $updatable = " [upgradable: v{$upgrader->getRemoteVersion()}]"; } } else { @@ -99,17 +100,17 @@ class VersionCommand extends ConsoleCommand $name = $installed->name; if ($this->gpm->isUpdatable($package)) { - $updatable = ' [updatable: v' . $installed->available . ']'; + $updatable = " [updatable: v{$installed->available}]"; } } } $updatable = $updatable ?: ''; - if ($installed || $package == 'grav') { - $this->output->writeln('You are running ' . $name . ' v' . $version . '' . $updatable); + if ($installed || $package === 'grav') { + $this->output->writeln("You are running {$name} v{$version}{$updatable}"); } else { - $this->output->writeln('Package ' . $package . ' not found'); + $this->output->writeln("Package {$package} not found"); } } }