Fixed some phpstan level 2 issues in Grav\Console

This commit is contained in:
Matias Griese
2019-03-13 19:46:06 +02:00
parent af3d5e9683
commit fde69ade6b
23 changed files with 126 additions and 282 deletions

View File

@@ -89,7 +89,7 @@
},
"scripts": {
"post-create-project-cmd": "bin/grav install",
"phpstan": "vendor/bin/phpstan analyse -l 1 -c ./tests/phpstan/phpstan.neon system/src --memory-limit=256M",
"phpstan": "vendor/bin/phpstan analyse -l 2 -c ./tests/phpstan/phpstan.neon system/src --memory-limit=256M",
"test": "vendor/bin/codecept run unit",
"test-windows": "vendor\\bin\\codecept run unit"
},

View File

@@ -38,6 +38,11 @@ use Psr\Http\Message\ServerRequestInterface;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\Event\EventDispatcher;
/**
* Grav container is the heart of Grav.
*
* @package Grav\Common
*/
class Grav extends Container
{
/**

View File

@@ -25,9 +25,6 @@ class BackupCommand extends ConsoleCommand
/** @var ProgressBar $progress */
protected $progress;
/**
*
*/
protected function configure()
{
$this
@@ -44,9 +41,6 @@ class BackupCommand extends ConsoleCommand
$this->source = getcwd();
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->progress = new ProgressBar($this->output);
@@ -96,7 +90,7 @@ class BackupCommand extends ConsoleCommand
}
/**
* @param $args
* @param array $args
*/
public function outputProgress($args)
{

View File

@@ -15,9 +15,6 @@ use Symfony\Component\Console\Input\InputOption;
class CacheCommand extends ConsoleCommand
{
/**
*
*/
protected function configure()
{
$this
@@ -34,9 +31,6 @@ class CacheCommand extends ConsoleCommand
->setHelp('The <info>cache</info> command allows you to interact with Grav cache');
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->cleanPaths();

View File

@@ -23,9 +23,7 @@ class CleanCommand extends Command
/* @var OutputInterface $output */
protected $output;
/**
* @var array
*/
/** @var array */
protected $paths_to_remove = [
'codeception.yml',
'tests/',
@@ -250,9 +248,6 @@ class CleanCommand extends Command
'vendor/willdurand/negotiation/tests',
];
/**
*
*/
protected function configure()
{
$this
@@ -264,8 +259,6 @@ class CleanCommand extends Command
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@@ -14,26 +14,6 @@ use Symfony\Component\Console\Input\InputOption;
class ComposerCommand extends ConsoleCommand
{
/**
* @var
*/
protected $config;
/**
* @var
*/
protected $local_config;
/**
* @var
*/
protected $destination;
/**
* @var
*/
protected $user_path;
/**
*
*/
protected function configure()
{
$this
@@ -54,9 +34,6 @@ class ComposerCommand extends ConsoleCommand
->setHelp('The <info>composer</info> command updates the composer vendor dependencies needed by Grav');
}
/**
* @return int|null|void
*/
protected function serve()
{
$action = $this->input->getOption('install') ? 'install' : ($this->input->getOption('update') ? 'update' : 'install');

View File

@@ -16,26 +16,18 @@ use Symfony\Component\Console\Input\InputOption;
class InstallCommand extends ConsoleCommand
{
/**
* @var
*/
/** @var array */
protected $config;
/**
* @var
*/
/** @var array */
protected $local_config;
/**
* @var
*/
/** @var string */
protected $destination;
/**
* @var
*/
/** @var string */
protected $user_path;
/**
*
*/
protected function configure()
{
$this
@@ -55,9 +47,6 @@ class InstallCommand extends ConsoleCommand
->setHelp('The <info>install</info> command installs the dependencies needed by Grav. Optionally can create symbolic links');
}
/**
* @return int|null|void
*/
protected function serve()
{
$dependencies_file = '.dependencies';

View File

@@ -9,7 +9,6 @@
namespace Grav\Console\Cli;
use Grav\Common\Grav;
use Grav\Common\Helpers\LogViewer;
use Grav\Common\Utils;
@@ -39,9 +38,6 @@ class LogViewerCommand extends ConsoleCommand
->setHelp("Display the last few entries of Grav log");
}
/**
* @return int|null|void
*/
protected function serve()
{
$grav = Grav::instance();

View File

@@ -16,9 +16,6 @@ use Symfony\Component\Console\Input\InputOption;
class NewProjectCommand extends ConsoleCommand
{
/**
*
*/
protected function configure()
{
$this
@@ -39,9 +36,6 @@ class NewProjectCommand extends ConsoleCommand
->setHelp("The <info>new-project</info> command is a combination of the `setup` and `install` commands.\nCreates a new Grav instance and performs the installation of all the required dependencies.");
}
/**
* @return int|null|void
*/
protected function serve()
{
$sandboxCommand = $this->getApplication()->find('sandbox');
@@ -61,6 +55,5 @@ class NewProjectCommand extends ConsoleCommand
$sandboxCommand->run($sandboxArguments, $this->output);
$installCommand->run($installArguments, $this->output);
}
}

View File

@@ -16,9 +16,7 @@ use Symfony\Component\Console\Input\InputOption;
class SandboxCommand extends ConsoleCommand
{
/**
* @var array
*/
/** @var array */
protected $directories = [
'/assets',
'/backup',
@@ -34,9 +32,7 @@ class SandboxCommand extends ConsoleCommand
'/user/themes',
];
/**
* @var array
*/
/** @var array */
protected $files = [
'/.dependencies',
'/.htaccess',
@@ -44,9 +40,7 @@ class SandboxCommand extends ConsoleCommand
'/user/config/system.yaml',
];
/**
* @var array
*/
/** @var array */
protected $mappings = [
'/.gitignore' => '/.gitignore',
'/.editorconfig' => '/.editorconfig',
@@ -62,18 +56,12 @@ class SandboxCommand extends ConsoleCommand
'/webserver-configs' => '/webserver-configs',
];
/**
* @var string
*/
/** @var string */
protected $default_file = "---\ntitle: HomePage\n---\n# HomePage\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porttitor eu felis sed ornare. Sed a mauris venenatis, pulvinar velit vel, dictum enim. Phasellus ac rutrum velit. Nunc lorem purus, hendrerit sit amet augue aliquet, iaculis ultricies nisl. Suspendisse tincidunt euismod risus, quis feugiat arcu tincidunt eget. Nulla eros mi, commodo vel ipsum vel, aliquet congue odio. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque velit orci, laoreet at adipiscing eu, interdum quis nibh. Nunc a accumsan purus.";
protected $source;
protected $destination;
/**
*
*/
protected function configure()
{
$this
@@ -94,9 +82,6 @@ class SandboxCommand extends ConsoleCommand
$this->source = getcwd();
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->destination = $this->input->getArgument('destination');
@@ -123,9 +108,6 @@ class SandboxCommand extends ConsoleCommand
$this->perms();
}
/**
*
*/
private function createDirectories()
{
$this->output->writeln('');
@@ -149,9 +131,6 @@ class SandboxCommand extends ConsoleCommand
}
}
/**
*
*/
private function copy()
{
$this->output->writeln('');
@@ -171,9 +150,6 @@ class SandboxCommand extends ConsoleCommand
}
}
/**
*
*/
private function symlink()
{
$this->output->writeln('');
@@ -199,9 +175,6 @@ class SandboxCommand extends ConsoleCommand
}
}
/**
*
*/
private function initFiles()
{
$this->check();
@@ -231,9 +204,6 @@ class SandboxCommand extends ConsoleCommand
}
}
/**
*
*/
private function pages()
{
$this->output->writeln('');
@@ -251,9 +221,6 @@ class SandboxCommand extends ConsoleCommand
}
}
/**
*
*/
private function perms()
{
$this->output->writeln('');
@@ -271,9 +238,6 @@ class SandboxCommand extends ConsoleCommand
$this->output->writeln("");
}
/**
*
*/
private function check()
{
$success = true;

View File

@@ -47,9 +47,6 @@ class SchedulerCommand extends ConsoleCommand
->setHelp("Running without any options will force the Scheduler to run through it's jobs and process them");
}
/**
* @return int|null|void
*/
protected function serve()
{
// error_reporting(1);

View File

@@ -22,9 +22,6 @@ class SecurityCommand extends ConsoleCommand
protected $source;
/**
*
*/
protected function configure()
{
$this
@@ -35,9 +32,6 @@ class SecurityCommand extends ConsoleCommand
$this->source = getcwd();
}
/**
* @return int|null|void
*/
protected function serve()
{
/** @var Grav $grav */
@@ -87,7 +81,7 @@ class SecurityCommand extends ConsoleCommand
}
/**
* @param $args
* @param array $args
*/
public function outputProgress($args)
{

View File

@@ -22,9 +22,6 @@ use Symfony\Component\Console\Output\OutputInterface;
trait ConsoleTrait
{
/**
* @var
*/
protected $argv;
/* @var InputInterface $output */
@@ -62,7 +59,7 @@ trait ConsoleTrait
}
/**
* @param $path
* @param string $path
*/
public function isGravInstance($path)
{

View File

@@ -22,12 +22,12 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
class DirectInstallCommand extends ConsoleCommand
{
/** @var string */
protected $all_yes;
/** @var string */
protected $destination;
/**
*
*/
protected function configure()
{
$this

View File

@@ -9,7 +9,9 @@
namespace Grav\Console\Gpm;
use Grav\Common\GPM\Remote\Package;
use Grav\Common\GPM\GPM;
use Grav\Common\GPM\Remote\Packages;
use Grav\Common\Utils;
use Grav\Console\ConsoleCommand;
use League\CLImate\CLImate;
@@ -17,28 +19,18 @@ use Symfony\Component\Console\Input\InputOption;
class IndexCommand extends ConsoleCommand
{
/**
* @var
*/
/** @var array */
protected $data;
/**
* @var
*/
/** @var GPM */
protected $gpm;
/**
* @var
*/
/** @var array */
protected $options;
/**
* @var array
*/
/** @var array */
protected $sortKeys = ['name', 'slug', 'author', 'date'];
/**
*
*/
protected function configure()
{
$this
@@ -97,9 +89,6 @@ class IndexCommand extends ConsoleCommand
;
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->options = $this->input->getOptions();
@@ -158,7 +147,7 @@ class IndexCommand extends ConsoleCommand
}
/**
* @param $package
* @param Package $package
*
* @return string
*/
@@ -184,7 +173,7 @@ class IndexCommand extends ConsoleCommand
}
/**
* @param $package
* @param Package $package
*
* @return string
*/
@@ -199,7 +188,7 @@ class IndexCommand extends ConsoleCommand
}
/**
* @param $data
* @param array $data
*
* @return mixed
*/
@@ -255,7 +244,7 @@ class IndexCommand extends ConsoleCommand
}
/**
* @param $packages
* @param Packages $packages
*/
public function sort($packages)
{

View File

@@ -17,15 +17,13 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
class InfoCommand extends ConsoleCommand
{
/**
* @var
*/
/** @var array */
protected $data;
/**
* @var
*/
/** @var GPM */
protected $gpm;
/** @var string */
protected $all_yes;
/**

View File

@@ -14,7 +14,7 @@ use Grav\Common\GPM\GPM;
use Grav\Common\GPM\Installer;
use Grav\Common\GPM\Licenses;
use Grav\Common\GPM\Response;
use Grav\Common\GPM\Remote\Package as Package;
use Grav\Common\GPM\Remote\Package;
use Grav\Common\Grav;
use Grav\Common\Utils;
use Grav\Console\ConsoleCommand;
@@ -26,22 +26,22 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
class InstallCommand extends ConsoleCommand
{
/** @var */
/** @var array */
protected $data;
/** @var GPM */
protected $gpm;
/** @var */
/** @var string */
protected $destination;
/** @var */
/** @var string */
protected $file;
/** @var */
/** @var string */
protected $tmp;
/** @var */
/** @var array */
protected $local_config;
/** @var bool */
@@ -50,11 +50,9 @@ class InstallCommand extends ConsoleCommand
/** @var array */
protected $demo_processing = [];
/** @var string */
protected $all_yes;
/**
*
*/
protected function configure()
{
$this
@@ -90,9 +88,9 @@ class InstallCommand extends ConsoleCommand
/**
* Allows to set the GPM object, used for testing the class
*
* @param $gpm
* @param GPM $gpm
*/
public function setGpm($gpm)
public function setGpm(GPM $gpm)
{
$this->gpm = $gpm;
}
@@ -232,7 +230,7 @@ class InstallCommand extends ConsoleCommand
/**
* If the package is updated from an older major release, show warning and ask confirmation
*
* @param $package
* @param Package $package
*/
public function askConfirmationIfMajorVersionUpdated($package)
{
@@ -320,8 +318,8 @@ class InstallCommand extends ConsoleCommand
}
/**
* @param $package
* @param bool $is_update True if the package is an update
* @param Package $package
* @param bool $is_update True if the package is an update
*/
private function processPackage($package, $is_update = false)
{
@@ -346,7 +344,7 @@ class InstallCommand extends ConsoleCommand
/**
* Add package to the queue to process the demo content, if demo content exists
*
* @param $package
* @param Package $package
*/
private function processDemo($package)
{
@@ -359,7 +357,7 @@ class InstallCommand extends ConsoleCommand
/**
* Prompt to install the demo content of a package
*
* @param $package
* @param Package $package
*/
private function installDemoContent($package)
{
@@ -415,7 +413,7 @@ class InstallCommand extends ConsoleCommand
}
/**
* @param $package
* @param Package $package
*
* @return array|bool
*/
@@ -433,7 +431,7 @@ class InstallCommand extends ConsoleCommand
}
/**
* @param $package
* @param Package $package
*
* @return bool|string
*/
@@ -462,7 +460,7 @@ class InstallCommand extends ConsoleCommand
}
/**
* @param $package
* @param Package $package
*/
private function processSymlink($package)
{
@@ -506,8 +504,8 @@ class InstallCommand extends ConsoleCommand
}
/**
* @param $package
* @param bool $is_update
* @param Package $package
* @param bool $is_update
*
* @return bool
*/
@@ -603,7 +601,7 @@ class InstallCommand extends ConsoleCommand
}
/**
* @param $package
* @param Package $package
*
* @return bool
*/
@@ -682,7 +680,7 @@ class InstallCommand extends ConsoleCommand
}
/**
* @param $progress
* @param array $progress
*/
public function progress($progress)
{

View File

@@ -12,6 +12,7 @@ namespace Grav\Console\Gpm;
use Grav\Common\Cache;
use Grav\Common\Filesystem\Folder;
use Grav\Common\GPM\Installer;
use Grav\Common\GPM\Remote\Package;
use Grav\Common\GPM\Response;
use Grav\Common\GPM\Upgrader;
use Grav\Common\Grav;
@@ -22,41 +23,29 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
class SelfupgradeCommand extends ConsoleCommand
{
/**
* @var
*/
/** @var array */
protected $data;
/**
* @var
*/
protected $extensions;
/**
* @var
*/
protected $updatable;
/**
* @var
*/
/** @var string */
protected $file;
/**
* @var array
*/
/** @var array */
protected $types = ['plugins', 'themes'];
/**
* @var
*/
/** @var string */
private $tmp;
/**
* @var
*/
private $upgrader;
/** @var string */
protected $all_yes;
protected $overwrite;
/**
*
*/
protected function configure()
{
$this
@@ -84,9 +73,6 @@ class SelfupgradeCommand extends ConsoleCommand
->setHelp('The <info>update</info> command updates Grav itself when a new version is available');
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->upgrader = new Upgrader($this->input->getOption('force'));
@@ -191,7 +177,7 @@ class SelfupgradeCommand extends ConsoleCommand
}
/**
* @param $package
* @param Package $package
*
* @return string
*/
@@ -248,7 +234,7 @@ class SelfupgradeCommand extends ConsoleCommand
}
/**
* @param $progress
* @param array $progress
*/
public function progress($progress)
{
@@ -258,7 +244,7 @@ class SelfupgradeCommand extends ConsoleCommand
}
/**
* @param $size
* @param int|float $size
* @param int $precision
*
* @return string

View File

@@ -11,6 +11,7 @@ namespace Grav\Console\Gpm;
use Grav\Common\GPM\GPM;
use Grav\Common\GPM\Installer;
use Grav\Common\GPM\Remote\Package;
use Grav\Common\Grav;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
@@ -19,34 +20,27 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
class UninstallCommand extends ConsoleCommand
{
/**
* @var
*/
/** @var array */
protected $data;
/** @var GPM */
protected $gpm;
/**
* @var
*/
/** @var string */
protected $destination;
/**
* @var
*/
/** @var string */
protected $file;
/**
* @var
*/
/** @var string */
protected $tmp;
protected $dependencies= [];
/** @var array */
protected $dependencies = [];
/** @var string */
protected $all_yes;
/**
*
*/
protected function configure()
{
$this
@@ -66,9 +60,6 @@ class UninstallCommand extends ConsoleCommand
->setHelp('The <info>uninstall</info> command allows to uninstall plugins and themes');
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->gpm = new GPM();
@@ -78,16 +69,18 @@ class UninstallCommand extends ConsoleCommand
$packages = array_map('strtolower', $this->input->getArgument('package'));
$this->data = ['total' => 0, 'not_found' => []];
$total = 0;
foreach ($packages as $package) {
$plugin = $this->gpm->getInstalledPlugin($package);
$theme = $this->gpm->getInstalledTheme($package);
if ($plugin || $theme) {
$this->data[strtolower($package)] = $plugin ?: $theme;
$this->data['total']++;
$total++;
} else {
$this->data['not_found'][] = $package;
}
}
$this->data['total'] = $total;
$this->output->writeln('');
@@ -131,8 +124,8 @@ class UninstallCommand extends ConsoleCommand
/**
* @param $slug
* @param $package
* @param string $slug
* @param Package $package
*
* @return bool
*/
@@ -247,8 +240,8 @@ class UninstallCommand extends ConsoleCommand
}
/**
* @param $slug
* @param $package
* @param string $slug
* @param Package $package
*
* @return bool
*/
@@ -289,8 +282,8 @@ class UninstallCommand extends ConsoleCommand
/**
* Check if package exists
*
* @param $slug
* @param $package
* @param string $slug
* @param Package $package
* @return int
*/
private function packageExists($slug, $package)

View File

@@ -20,47 +20,33 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
class UpdateCommand extends ConsoleCommand
{
/**
* @var
*/
/** @var array */
protected $data;
/**
* @var
*/
protected $extensions;
/**
* @var
*/
protected $updatable;
/**
* @var
*/
/** @var string */
protected $destination;
/**
* @var
*/
/** @var string */
protected $file;
/**
* @var array
*/
/** @var array */
protected $types = ['plugins', 'themes'];
/**
* @var GPM $gpm
*/
/** @var GPM */
protected $gpm;
/** @var string */
protected $all_yes;
protected $overwrite;
/**
* @var Upgrader
*/
/** @var Upgrader */
protected $upgrader;
/**
*
*/
protected function configure()
{
$this
@@ -111,9 +97,6 @@ class UpdateCommand extends ConsoleCommand
->setHelp('The <info>update</info> command updates plugins and themes when a new version is available');
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->upgrader = new Upgrader($this->input->getOption('force'));
@@ -234,7 +217,7 @@ class UpdateCommand extends ConsoleCommand
}
/**
* @param $only_packages
* @param array $only_packages
*
* @return array
*/

View File

@@ -18,14 +18,9 @@ use Symfony\Component\Console\Input\InputOption;
class VersionCommand extends ConsoleCommand
{
/**
* @var GPM
*/
/** @var GPM */
protected $gpm;
/**
*
*/
protected function configure()
{
$this

View File

@@ -65,7 +65,7 @@ trait UriDecorationTrait
public function withScheme($scheme): UriInterface
{
/** @var UriInterface $new */
/** @var UriInterface|UriDecorationTrait $new */
$new = clone $this;
$new->uri = $this->uri->withScheme($scheme);
@@ -74,7 +74,7 @@ trait UriDecorationTrait
public function withUserInfo($user, $password = null): UriInterface
{
/** @var UriInterface $new */
/** @var UriInterface|UriDecorationTrait $new */
$new = clone $this;
$new->uri = $this->uri->withUserInfo($user, $password);
@@ -83,7 +83,7 @@ trait UriDecorationTrait
public function withHost($host): UriInterface
{
/** @var UriInterface $new */
/** @var UriInterface|UriDecorationTrait $new */
$new = clone $this;
$new->uri = $this->uri->withHost($host);
@@ -92,7 +92,7 @@ trait UriDecorationTrait
public function withPort($port): UriInterface
{
/** @var UriInterface $new */
/** @var UriInterface|UriDecorationTrait $new */
$new = clone $this;
$new->uri = $this->uri->withPort($port);
@@ -101,7 +101,7 @@ trait UriDecorationTrait
public function withPath($path): UriInterface
{
/** @var UriInterface $new */
/** @var UriInterface|UriDecorationTrait $new */
$new = clone $this;
$new->uri = $this->uri->withPath($path);
@@ -110,7 +110,7 @@ trait UriDecorationTrait
public function withQuery($query): UriInterface
{
/** @var UriInterface $new */
/** @var UriInterface|UriDecorationTrait $new */
$new = clone $this;
$new->uri = $this->uri->withQuery($query);
@@ -119,7 +119,7 @@ trait UriDecorationTrait
public function withFragment($fragment): UriInterface
{
/** @var UriInterface $new */
/** @var UriInterface|UriDecorationTrait $new */
$new = clone $this;
$new->uri = $this->uri->withFragment($fragment);

View File

@@ -8,6 +8,15 @@ parameters:
excludes_analyse:
- system/src/Grav/Common/Errors/Resources/layout.html.php
reportUnmatchedIgnoredErrors: false
universalObjectCratesClasses:
- Grav\Common\Config\Config
- Grav\Common\Config\Languages
- Grav\Common\Config\Setup
- Grav\Common\Data\Data
- Grav\Common\GPM\Common\Package
- Grav\Common\GPM\Local\Package
- Grav\Common\GPM\Remote\Package
- Grav\Common\Session
ignoreErrors:
# Errors that needs some more thinking (design...)