From 91eb1f261f29e937e1bbdb4697fbde2a72f34bce Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 27 Oct 2017 17:24:33 +0200 Subject: [PATCH] Fix scrutinizer tips --- Account/Account.php | 8 ++++---- Account/Group.php | 2 +- Account/PermissionAbstract.php | 2 +- AutoloadException.php | 2 +- DataStorage/Cache/CachePool.php | 2 +- .../Database/Connection/ConnectionAbstract.php | 6 +++--- .../InvalidConnectionConfigException.php | 2 +- .../Exception/InvalidMapperException.php | 2 +- .../Schema/Exception/TableException.php | 2 +- DataStorage/LockException.php | 2 +- Math/Exception/ZeroDevisionException.php | 2 +- Math/Functions/Functions.php | 8 ++++---- .../Exception/InvalidDimensionException.php | 2 +- Math/Statistic/Average.php | 4 ++-- Message/RequestAbstract.php | 2 +- Module/Exception/InvalidModuleException.php | 2 +- Module/Exception/InvalidThemeException.php | 2 +- Module/ModuleAbstract.php | 2 +- Module/PackageManager.php | 8 ++++---- Router/Router.php | 2 +- Stdlib/Base/Exception/InvalidEnumName.php | 2 +- Stdlib/Base/Exception/InvalidEnumValue.php | 2 +- Stdlib/Map/MultiMap.php | 18 +++++++++--------- System/File/PathException.php | 2 +- System/File/PermissionException.php | 2 +- System/SystemUtils.php | 5 ++++- Uri/InvalidUriException.php | 2 +- Utils/IO/Json/InvalidJsonException.php | 2 +- Views/ViewAbstract.php | 2 +- 29 files changed, 52 insertions(+), 49 deletions(-) diff --git a/Account/Account.php b/Account/Account.php index 78007ad1d..fed37a1ec 100644 --- a/Account/Account.php +++ b/Account/Account.php @@ -136,7 +136,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Account type. * - * @var AccountType|int + * @var int * @since 1.0.0 */ protected $type = AccountType::USER; @@ -144,7 +144,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Account status. * - * @var AccountStatus|int + * @var int * @since 1.0.0 */ protected $status = AccountStatus::INACTIVE; @@ -624,8 +624,8 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Json serialize. - * - * @return string + * + * @return array * * @since 1.0.0 */ diff --git a/Account/Group.php b/Account/Group.php index 0de9477b6..f70189590 100644 --- a/Account/Group.php +++ b/Account/Group.php @@ -208,7 +208,7 @@ class Group implements ArrayableInterface, \JsonSerializable /** * Json serialize. * - * @return string + * @return array * * @since 1.0.0 */ diff --git a/Account/PermissionAbstract.php b/Account/PermissionAbstract.php index 86b6000a0..d8eb1cfe8 100644 --- a/Account/PermissionAbstract.php +++ b/Account/PermissionAbstract.php @@ -340,7 +340,7 @@ class PermissionAbstract * * @param int $permission Permission * - * @return void + * @return bool * * @since 1.0.0 */ diff --git a/AutoloadException.php b/AutoloadException.php index efcf7fbc4..9ba07218f 100644 --- a/AutoloadException.php +++ b/AutoloadException.php @@ -31,7 +31,7 @@ class AutoloadException extends \RuntimeException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/DataStorage/Cache/CachePool.php b/DataStorage/Cache/CachePool.php index 0bd5f637a..b5d31470d 100644 --- a/DataStorage/Cache/CachePool.php +++ b/DataStorage/Cache/CachePool.php @@ -39,7 +39,7 @@ class CachePool implements OptionsInterface /** * MemCache instance. * - * @var \phpOMS\DataStorage\Cache\CacheInterface + * @var \phpOMS\DataStorage\Cache\CacheInterface[] * @since 1.0.0 */ private $pool = null; diff --git a/DataStorage/Database/Connection/ConnectionAbstract.php b/DataStorage/Database/Connection/ConnectionAbstract.php index bc2deed05..1dfec1ff2 100644 --- a/DataStorage/Database/Connection/ConnectionAbstract.php +++ b/DataStorage/Database/Connection/ConnectionAbstract.php @@ -65,15 +65,15 @@ abstract class ConnectionAbstract implements ConnectionInterface /** * Database type. * - * @var \phpOMS\DataStorage\Database\DatabaseType + * @var string * @since 1.0.0 */ - protected $type = null; + protected $type = 'undefined'; /** * Database status. * - * @var DatabaseStatus + * @var int * @since 1.0.0 */ protected $status = DatabaseStatus::CLOSED; diff --git a/DataStorage/Database/Exception/InvalidConnectionConfigException.php b/DataStorage/Database/Exception/InvalidConnectionConfigException.php index 6ffa36cdc..1acdb5fc5 100644 --- a/DataStorage/Database/Exception/InvalidConnectionConfigException.php +++ b/DataStorage/Database/Exception/InvalidConnectionConfigException.php @@ -31,7 +31,7 @@ class InvalidConnectionConfigException extends \InvalidArgumentException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/DataStorage/Database/Exception/InvalidMapperException.php b/DataStorage/Database/Exception/InvalidMapperException.php index 3672dff47..9cc312591 100644 --- a/DataStorage/Database/Exception/InvalidMapperException.php +++ b/DataStorage/Database/Exception/InvalidMapperException.php @@ -31,7 +31,7 @@ class InvalidMapperException extends \RuntimeException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/DataStorage/Database/Schema/Exception/TableException.php b/DataStorage/Database/Schema/Exception/TableException.php index d2d4b5cc3..0c0516a2c 100644 --- a/DataStorage/Database/Schema/Exception/TableException.php +++ b/DataStorage/Database/Schema/Exception/TableException.php @@ -31,7 +31,7 @@ class TableException extends \PDOException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/DataStorage/LockException.php b/DataStorage/LockException.php index 6e9c9cd3b..3cfd4f3e3 100644 --- a/DataStorage/LockException.php +++ b/DataStorage/LockException.php @@ -31,7 +31,7 @@ class LockException extends \RuntimeException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Math/Exception/ZeroDevisionException.php b/Math/Exception/ZeroDevisionException.php index a60f099f5..50c86a992 100644 --- a/Math/Exception/ZeroDevisionException.php +++ b/Math/Exception/ZeroDevisionException.php @@ -31,7 +31,7 @@ class ZeroDevisionException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Math/Functions/Functions.php b/Math/Functions/Functions.php index 5b2020850..a0a48edb9 100644 --- a/Math/Functions/Functions.php +++ b/Math/Functions/Functions.php @@ -250,15 +250,15 @@ class Functions * @example The relative fiscal month (August) in a company where the fiscal year starts in July. * @example 2 = getRelativeDegree(8, 12, 7); * - * @param mixed $value Value to get degree - * @param mixed $length Circle size - * @param mixed $start Start value + * @param int $value Value to get degree + * @param int $length Circle size + * @param int $start Start value * * @return int Lowest value is 0 and highest value is length - 1 * * @since 1.0.0 */ - public static function getRelativeDegree($value, $length, $start = 0) : int + public static function getRelativeDegree(int $value, int $length, int $start = 0) : int { return abs(self::mod($value - $start, $length)); } diff --git a/Math/Matrix/Exception/InvalidDimensionException.php b/Math/Matrix/Exception/InvalidDimensionException.php index b397fe94e..41ca8136c 100644 --- a/Math/Matrix/Exception/InvalidDimensionException.php +++ b/Math/Matrix/Exception/InvalidDimensionException.php @@ -31,7 +31,7 @@ class InvalidDimensionException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php index 4438725b9..af5351759 100644 --- a/Math/Statistic/Average.php +++ b/Math/Statistic/Average.php @@ -185,12 +185,12 @@ class Average * * @since 1.0.0 */ - public static function mode($values) + public static function mode(array $values) { $count = array_count_values($values); $best = max($count); - return array_keys($count, $best); + return (float) (array_keys($count, $best)[0] ?? 0.0); } /** diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 4b1036ed4..9a3c920e8 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -74,7 +74,7 @@ abstract class RequestAbstract implements MessageInterface /** * Request type. * - * @var \phpOMS\Message\RequestSource + * @var int * @since 1.0.0 */ protected $source = RequestSource::UNDEFINED; diff --git a/Module/Exception/InvalidModuleException.php b/Module/Exception/InvalidModuleException.php index 7dcf5bfb5..c72d6d7a7 100644 --- a/Module/Exception/InvalidModuleException.php +++ b/Module/Exception/InvalidModuleException.php @@ -31,7 +31,7 @@ class InvalidModuleException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Module/Exception/InvalidThemeException.php b/Module/Exception/InvalidThemeException.php index 8beb5257b..66558b7db 100644 --- a/Module/Exception/InvalidThemeException.php +++ b/Module/Exception/InvalidThemeException.php @@ -31,7 +31,7 @@ class InvalidThemeException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index dc24dc954..c35ca7df9 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -76,7 +76,7 @@ abstract class ModuleAbstract /** * Dependencies. * - * @var string + * @var string[] * @since 1.0.0 */ protected static $dependencies = []; diff --git a/Module/PackageManager.php b/Module/PackageManager.php index b1a3a79e1..e678b36d5 100644 --- a/Module/PackageManager.php +++ b/Module/PackageManager.php @@ -70,7 +70,7 @@ class PackageManager * Constructor. * * @param string $path Package source path e.g. path after download. - * @param string basePath Path of the application + * @param string $basePath Path of the application * * @since 1.0.0 */ @@ -85,11 +85,11 @@ class PackageManager * * @param string $path Temporary extract path * - * @return bool - * + * @return void + * * @since 1.0.0 */ - public function extract(string $path) : bool + public function extract(string $path) /* : void */ { $this->extractPath = $path; Zip::unpack($this->path, $this->extractPath); diff --git a/Router/Router.php b/Router/Router.php index d86e6aaf5..4d47301d2 100644 --- a/Router/Router.php +++ b/Router/Router.php @@ -96,7 +96,7 @@ class Router * @param string|RequestAbstract $request Request to route * @param int $verb Route verb * - * @return string[] + * @return array[] * * @throws \InvalidArgumentException * diff --git a/Stdlib/Base/Exception/InvalidEnumName.php b/Stdlib/Base/Exception/InvalidEnumName.php index a18deabdc..9d114b39b 100644 --- a/Stdlib/Base/Exception/InvalidEnumName.php +++ b/Stdlib/Base/Exception/InvalidEnumName.php @@ -34,7 +34,7 @@ class InvalidEnumName extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Stdlib/Base/Exception/InvalidEnumValue.php b/Stdlib/Base/Exception/InvalidEnumValue.php index 24162373e..446ae23ac 100644 --- a/Stdlib/Base/Exception/InvalidEnumValue.php +++ b/Stdlib/Base/Exception/InvalidEnumValue.php @@ -34,7 +34,7 @@ class InvalidEnumValue extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Stdlib/Map/MultiMap.php b/Stdlib/Map/MultiMap.php index 5e769ea72..489864ad2 100644 --- a/Stdlib/Map/MultiMap.php +++ b/Stdlib/Map/MultiMap.php @@ -92,7 +92,7 @@ class MultiMap implements \Countable $inserted = false; if ($this->keyType !== KeyType::SINGLE) { - $keys = [implode($keys, ':')]; + $keys = [implode(':', $keys)]; } foreach ($keys as $key) { @@ -186,14 +186,14 @@ class MultiMap implements \Countable $keys = Permutation::permut($key); foreach ($keys as $key => $value) { - $key = implode($value, ':'); + $key = implode(':', $value); if (isset($this->keys[$key])) { return $this->values[$this->keys[$key]]; } } } else { - $key = implode($key, ':'); + $key = implode(':', $key); } } @@ -235,12 +235,12 @@ class MultiMap implements \Countable $permutation = Permutation::permut($key); foreach ($permutation as $permut) { - if ($this->set(implode($permut, ':'), $value)) { + if ($this->set(implode(':', $permut), $value)) { return true; } } } else { - return $this->set(implode($key, ':'), $value); + return $this->set(implode(':', $key), $value); } return false; @@ -302,12 +302,12 @@ class MultiMap implements \Countable $removed = false; foreach ($keys as $key => $value) { - $removed |= $this->remove(implode($value, ':')); + $removed |= $this->remove(implode(':', $value)); } return $removed; } else { - return $this->remove(implode($key, ':')); + return $this->remove(implode(':', $key)); } } @@ -403,12 +403,12 @@ class MultiMap implements \Countable $removed = false; foreach ($keys as $key => $value) { - $removed |= $this->removeKey(implode($value, ':')); + $removed |= $this->removeKey(implode(':', $value)); } return $removed; } else { - return $this->removeKey(implode($key, ':')); + return $this->removeKey(implode(':', $key)); } } diff --git a/System/File/PathException.php b/System/File/PathException.php index 292965548..d99b422f0 100644 --- a/System/File/PathException.php +++ b/System/File/PathException.php @@ -31,7 +31,7 @@ class PathException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/System/File/PermissionException.php b/System/File/PermissionException.php index 786c06787..b59dbf67e 100644 --- a/System/File/PermissionException.php +++ b/System/File/PermissionException.php @@ -31,7 +31,7 @@ class PermissionException extends \RuntimeException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/System/SystemUtils.php b/System/SystemUtils.php index b81675d6a..0ebfed499 100644 --- a/System/SystemUtils.php +++ b/System/SystemUtils.php @@ -46,10 +46,12 @@ class SystemUtils */ public static function getRAM() : int { - $mem = null; + $mem = 0; if (stristr(PHP_OS, 'WIN')) { exec('wmic memorychip get capacity', $mem); + + /** @var array $mem */ $mem = array_sum($mem) / 1024; } elseif (stristr(PHP_OS, 'LINUX')) { $fh = fopen('/proc/meminfo', 'r'); @@ -62,6 +64,7 @@ class SystemUtils break; } } + fclose($fh); } diff --git a/Uri/InvalidUriException.php b/Uri/InvalidUriException.php index b3c759e02..43ba42ca5 100644 --- a/Uri/InvalidUriException.php +++ b/Uri/InvalidUriException.php @@ -31,7 +31,7 @@ class InvalidUriException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Utils/IO/Json/InvalidJsonException.php b/Utils/IO/Json/InvalidJsonException.php index 6b7c5689e..5367845b2 100644 --- a/Utils/IO/Json/InvalidJsonException.php +++ b/Utils/IO/Json/InvalidJsonException.php @@ -31,7 +31,7 @@ class InvalidJsonException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index 5f444f2df..c235f92cf 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -182,7 +182,7 @@ abstract class ViewAbstract implements \Serializable public function serialize() { if (empty($this->template)) { - return $this->toArray(); + return json_encode($this->toArray()); } return $this->render();