From b0b6c1dd17cf58b731a2a69133f66465101c7627 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 13 Mar 2019 15:21:09 +0200 Subject: [PATCH] Fixed some more phpstan level 2 issues --- composer.json | 1 + system/src/Grav/Common/Assets.php | 2 +- system/src/Grav/Common/Assets/BaseAsset.php | 1 - .../Assets/Traits/LegacyAssetsTrait.php | 21 +++++++++----- .../Assets/Traits/TestingAssetsTrait.php | 10 +++---- system/src/Grav/Common/Cache.php | 6 ++-- system/src/Grav/Common/Data/Validation.php | 2 +- system/src/Grav/Common/Debugger.php | 9 +++--- system/src/Grav/Common/Errors/Errors.php | 2 +- .../Grav/Common/Errors/SimplePageHandler.php | 2 +- system/src/Grav/Common/Filesystem/Folder.php | 8 ++--- .../RecursiveDirectoryFilterIterator.php | 10 +++++-- .../RecursiveFolderFilterIterator.php | 2 +- system/src/Grav/Common/GPM/GPM.php | 29 ++++++++++--------- tests/phpstan/phpstan.neon | 6 ++-- 15 files changed, 61 insertions(+), 50 deletions(-) diff --git a/composer.json b/composer.json index 1dcac5d06..da3c4f783 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,7 @@ "victorjonsson/markdowndocs": "dev-master" }, "suggest": { + "ext-zend-opcache": "Recommended for better performance", "ext-intl": "Recommended for multi-language sites", "ext-memcache": "Needed to support Memcache servers", "ext-memcached": "Needed to support Memcached servers", diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index a3634a5d7..152a97f56 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -123,7 +123,7 @@ class Assets extends PropertyObject * It automatically detects the asset type (JavaScript, CSS or collection). * You may add more than one asset passing an array as argument. * - * @param $asset + * @param array|string $asset * @return $this */ public function add($asset) diff --git a/system/src/Grav/Common/Assets/BaseAsset.php b/system/src/Grav/Common/Assets/BaseAsset.php index 6dedbee4c..7bb179dde 100644 --- a/system/src/Grav/Common/Assets/BaseAsset.php +++ b/system/src/Grav/Common/Assets/BaseAsset.php @@ -153,7 +153,6 @@ abstract class BaseAsset extends PropertyObject * Build local links including grav asset shortcodes * * @param string $asset the asset string reference - * @param bool $absolute build absolute asset link * * @return string the final link url to the asset */ diff --git a/system/src/Grav/Common/Assets/Traits/LegacyAssetsTrait.php b/system/src/Grav/Common/Assets/Traits/LegacyAssetsTrait.php index 2e97f0c47..ccf9da298 100644 --- a/system/src/Grav/Common/Assets/Traits/LegacyAssetsTrait.php +++ b/system/src/Grav/Common/Assets/Traits/LegacyAssetsTrait.php @@ -14,6 +14,11 @@ use Grav\Common\Assets; trait LegacyAssetsTrait { + /** + * @param array $args + * @param string $type + * @return array + */ protected function unifyLegacyArguments($args, $type = Assets::CSS_TYPE) { // First argument is always the asset @@ -77,10 +82,10 @@ trait LegacyAssetsTrait /** * Convenience wrapper for async loading of JavaScript * - * @param $asset - * @param int $priority - * @param bool $pipeline - * @param string $group name of the group + * @param string|array $asset + * @param int $priority + * @param bool $pipeline + * @param string $group name of the group * * @return \Grav\Common\Assets * @deprecated Please use dynamic method with ['loading' => 'async']. @@ -95,10 +100,10 @@ trait LegacyAssetsTrait /** * Convenience wrapper for deferred loading of JavaScript * - * @param $asset - * @param int $priority - * @param bool $pipeline - * @param string $group name of the group + * @param string|array $asset + * @param int $priority + * @param bool $pipeline + * @param string $group name of the group * * @return \Grav\Common\Assets * @deprecated Please use dynamic method with ['loading' => 'defer']. diff --git a/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php b/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php index d1b3d97e3..04ad70944 100644 --- a/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php +++ b/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php @@ -16,7 +16,7 @@ trait TestingAssetsTrait /** * Determines if an asset exists as a collection, CSS or JS reference * - * @param $asset + * @param string $asset * * @return bool */ @@ -38,7 +38,7 @@ trait TestingAssetsTrait /** * Set the array of collections explicitly * - * @param $collections + * @param array $collections * * @return $this */ @@ -90,7 +90,7 @@ trait TestingAssetsTrait /** * Set the whole array of CSS assets * - * @param $css + * @param array $css * * @return $this */ @@ -104,7 +104,7 @@ trait TestingAssetsTrait /** * Set the whole array of JS assets * - * @param $js + * @param array $js * * @return $this */ @@ -219,7 +219,7 @@ trait TestingAssetsTrait /** * Explicitly set's a timestamp for assets * - * @param $value + * @param string|int $value */ public function setTimestamp($value) { diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index c97696324..c86990c61 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -167,7 +167,7 @@ class Cache extends Getters /** * Public accessor to set the enabled state of the cache * - * @param $enabled + * @param bool|int $enabled */ public function setEnabled($enabled) { @@ -561,7 +561,7 @@ class Cache extends Getters /** * is this driver a volatile driver in that it resides in PHP process memory * - * @param $setting + * @param string $setting * @return bool */ public function isVolatileDriver($setting) @@ -588,7 +588,7 @@ class Cache extends Getters /** * Static function to call as a scheduled Job to clear Grav cache * - * @param $type + * @param string $type */ public static function clearJob($type) { diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index 9b065cc04..969ad8135 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -18,7 +18,7 @@ class Validation /** * Validate value against a blueprint field definition. * - * @param $value + * @param mixed $value * @param array $field * @return array */ diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index cf5cde45c..ef1e096b2 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -10,6 +10,7 @@ namespace Grav\Common; use DebugBar\DataCollector\ConfigCollector; +use DebugBar\DataCollector\DataCollectorInterface; use DebugBar\DataCollector\ExceptionsCollector; use DebugBar\DataCollector\MemoryCollector; use DebugBar\DataCollector\MessagesCollector; @@ -181,7 +182,7 @@ class Debugger /** * Adds a data collector * - * @param $collector + * @param DataCollectorInterface $collector * * @return $this * @throws \DebugBar\DebugBarException @@ -196,9 +197,9 @@ class Debugger /** * Returns a data collector * - * @param $collector + * @param DataCollectorInterface $collector * - * @return \DebugBar\DataCollector\DataCollectorInterface + * @return DataCollectorInterface * @throws \DebugBar\DebugBarException */ public function getCollector($collector) @@ -297,7 +298,7 @@ class Debugger /** * Dump variables into the Messages tab of the Debug Bar * - * @param $message + * @param mixed $message * @param string $label * @param bool $isString * diff --git a/system/src/Grav/Common/Errors/Errors.php b/system/src/Grav/Common/Errors/Errors.php index a77cbc42d..dbc955ed0 100644 --- a/system/src/Grav/Common/Errors/Errors.php +++ b/system/src/Grav/Common/Errors/Errors.php @@ -62,7 +62,7 @@ class Errors } catch (\Exception $e) { echo $e; } - }, 'log'); + }); } $whoops->register(); diff --git a/system/src/Grav/Common/Errors/SimplePageHandler.php b/system/src/Grav/Common/Errors/SimplePageHandler.php index f6a23e665..311d72244 100644 --- a/system/src/Grav/Common/Errors/SimplePageHandler.php +++ b/system/src/Grav/Common/Errors/SimplePageHandler.php @@ -59,7 +59,7 @@ class SimplePageHandler extends Handler } /** - * @param $resource + * @param string $resource * * @return string * @throws \RuntimeException diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php index 14d6beb75..f17410c49 100644 --- a/system/src/Grav/Common/Filesystem/Folder.php +++ b/system/src/Grav/Common/Filesystem/Folder.php @@ -49,7 +49,7 @@ abstract class Folder /** * Recursively find the last modified time under given path by file. * - * @param string $path + * @param string $path * @param string $extensions which files to search for specifically * * @return int @@ -87,7 +87,7 @@ abstract class Folder /** * Recursively md5 hash all files in a path * - * @param $path + * @param string $path * @return string */ public static function hashAllFiles($path) @@ -437,8 +437,8 @@ abstract class Folder /** * Recursive copy of one directory to another * - * @param $src - * @param $dest + * @param string $src + * @param string $dest * * @return bool * @throws \RuntimeException diff --git a/system/src/Grav/Common/Filesystem/RecursiveDirectoryFilterIterator.php b/system/src/Grav/Common/Filesystem/RecursiveDirectoryFilterIterator.php index e14e347f8..c662fc466 100644 --- a/system/src/Grav/Common/Filesystem/RecursiveDirectoryFilterIterator.php +++ b/system/src/Grav/Common/Filesystem/RecursiveDirectoryFilterIterator.php @@ -39,7 +39,7 @@ class RecursiveDirectoryFilterIterator extends \RecursiveFilterIterator */ public function accept() { - /** @var $file \SplFileInfo */ + /** @var \SplFileInfo $file */ $file = $this->current(); $filename = $file->getFilename(); $relative_filename = str_replace($this::$root . '/', '', $file->getPathname()); @@ -57,7 +57,11 @@ class RecursiveDirectoryFilterIterator extends \RecursiveFilterIterator return false; } - public function getChildren() { - return new self($this->getInnerIterator()->getChildren(), $this::$root, $this::$ignore_folders, $this::$ignore_files); + public function getChildren() + { + /** @var RecursiveDirectoryFilterIterator $iterator */ + $iterator = $this->getInnerIterator(); + + return new self($iterator->getChildren(), $this::$root, $this::$ignore_folders, $this::$ignore_files); } } diff --git a/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php b/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php index 3da995b12..eb493db6a 100644 --- a/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php +++ b/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php @@ -39,7 +39,7 @@ class RecursiveFolderFilterIterator extends \RecursiveFilterIterator */ public function accept() { - /** @var $current \SplFileInfo */ + /** @var \SplFileInfo $current */ $current = $this->current(); return $current->isDir() && !in_array($current->getFilename(), $this::$ignore_folders, true); diff --git a/system/src/Grav/Common/GPM/GPM.php b/system/src/Grav/Common/GPM/GPM.php index 28813d471..528f1268d 100644 --- a/system/src/Grav/Common/GPM/GPM.php +++ b/system/src/Grav/Common/GPM/GPM.php @@ -37,7 +37,7 @@ class GPM extends Iterator /** * Internal cache - * @var + * @var array */ protected $cache; @@ -55,6 +55,7 @@ class GPM extends Iterator public function __construct($refresh = false, $callback = null) { parent::__construct(); + $this->cache = []; $this->installed = new Local\Packages(); try { $this->repository = new Remote\Packages($refresh, $callback); @@ -263,7 +264,7 @@ class GPM extends Iterator /** * Get the latest release of a package from the GPM * - * @param $package_name + * @param string $package_name * * @return string|null */ @@ -352,7 +353,7 @@ class GPM extends Iterator /** * Get the release type of a package (stable / testing) * - * @param $package_name + * @param string $package_name * * @return string|null */ @@ -375,7 +376,7 @@ class GPM extends Iterator /** * Returns true if the package latest release is stable * - * @param $package_name + * @param string $package_name * * @return boolean */ @@ -387,7 +388,7 @@ class GPM extends Iterator /** * Returns true if the package latest release is testing * - * @param $package_name + * @param string $package_name * * @return boolean */ @@ -504,8 +505,8 @@ class GPM extends Iterator /** * Download the zip package via the URL * - * @param $package_file - * @param $tmp + * @param string $package_file + * @param string $tmp * @return null|string */ public static function downloadPackage($package_file, $tmp) @@ -531,8 +532,8 @@ class GPM extends Iterator /** * Copy the local zip package to tmp * - * @param $package_file - * @param $tmp + * @param string $package_file + * @param string $tmp * @return null|string */ public static function copyPackage($package_file, $tmp) @@ -552,7 +553,7 @@ class GPM extends Iterator /** * Try to guess the package type from the source files * - * @param $source + * @param string $source * @return bool|string */ public static function getPackageType($source) @@ -597,7 +598,7 @@ class GPM extends Iterator /** * Try to guess the package name from the source files * - * @param $source + * @param string $source * @return bool|string */ public static function getPackageName($source) @@ -637,8 +638,8 @@ class GPM extends Iterator /** * Get the install path for a name and a particular type of package * - * @param $type - * @param $name + * @param string $type + * @param string $name * @return string */ public static function getInstallPath($type, $name) @@ -807,7 +808,7 @@ class GPM extends Iterator /** * Check the passed packages list can be updated * - * @param $packages_names_list + * @param array $packages_names_list * * @throws \Exception */ diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index 1580f1e6c..f6883aa13 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -26,23 +26,23 @@ parameters: - '#PHPDoc tag \@throws with type Psr\\SimpleCache\\(CacheException|InvalidArgumentException) is not subtype of Throwable#' # Those errors are about plugins (need to find a better solution) - - message: '#Call to static method sendEmail\(\) on an unknown class Grav\\Plugin\\Email\\Utils.#' path: 'system/src/Grav/Common/Scheduler/Job.php' # Can be ignored, after fopen there's always an $http_response_header locally available - - message: '#Variable \$http_response_header in isset\(\) always exists and is not nullable.#' path: 'system/src/Grav/Common/GPM/Response.php' # Those errors can be ignored (they depends on installed extensions) - - message: '#Instantiated class (Memcache|Memcached|Redis|RedisException) not found#' path: 'system/src/Grav/Common/Cache.php' + - + message: '#on an unknown class (Memcache|Memcached|Redis|RedisException)#' + path: 'system/src/Grav/Common/Cache.php' - message: '#on an unknown class Collator#' path: 'system/src/Grav/Common/Page/Pages.php' \ No newline at end of file