From a2a70e28eb55b84ffc3d56db1787da1eed864da9 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 27 Feb 2020 19:01:55 +0100 Subject: [PATCH] phpstan fixes and install bug --- Algorithm/Maze/MazeGenerator.php | 1 + Config/OptionsTrait.php | 43 +++++++++++++++++++++--- Math/Matrix/Matrix.php | 5 ++- Math/Stochastic/NaiveBayesClassifier.php | 5 ++- Module/ModuleManager.php | 4 +++ System/File/DirectoryInterface.php | 3 ++ Utils/RnG/Phone.php | 4 +-- 7 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Algorithm/Maze/MazeGenerator.php b/Algorithm/Maze/MazeGenerator.php index 53cb59871..93a653133 100644 --- a/Algorithm/Maze/MazeGenerator.php +++ b/Algorithm/Maze/MazeGenerator.php @@ -98,6 +98,7 @@ class MazeGenerator if ($pos === null) { $n = 0; + break; } } } diff --git a/Config/OptionsTrait.php b/Config/OptionsTrait.php index 6f6040609..5ac166591 100644 --- a/Config/OptionsTrait.php +++ b/Config/OptionsTrait.php @@ -36,7 +36,13 @@ trait OptionsTrait private array $options = []; /** - * {@inheritdoc} + * Is this key set. + * + * @param mixed $key Key to check for existence + * + * @return bool + * + * @since 1.0.0 */ public function exists($key) : bool { @@ -44,7 +50,13 @@ trait OptionsTrait } /** - * {@inheritdoc} + * Get option by key. + * + * @param mixed $key Unique option key + * + * @return mixed Option value + * + * @since 1.0.0 */ public function getOption($key) { @@ -52,7 +64,13 @@ trait OptionsTrait } /** - * {@inheritdoc} + * Get options by keys. + * + * @param mixed $key Unique option key + * + * @return array Option values + * + * @since 1.0.0 */ public function getOptions(array $key) { @@ -68,7 +86,15 @@ trait OptionsTrait } /** - * {@inheritdoc} + * Updating or adding settings. + * + * @param mixed $key Unique option key + * @param mixed $value Option value + * @param bool $overwrite Overwrite existing value + * + * @return bool + * + * @since 1.0.0 */ public function setOption($key, $value, bool $overwrite = true) : bool { @@ -82,7 +108,14 @@ trait OptionsTrait } /** - * {@inheritdoc} + * Updating or adding settings. + * + * @param array $pair Key value pair + * @param bool $overwrite Overwrite existing value + * + * @return bool + * + * @since 1.0.0 */ public function setOptions(array $pair, bool $overwrite = true) : bool { diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index d53db1642..d5851f9a9 100644 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -23,13 +23,16 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @phpstan-implements \ArrayAccess + * @phpstan-implements \Iterator */ class Matrix implements \ArrayAccess, \Iterator { /** * Matrix. * - * @var array + * @var array> * @since 1.0.0 */ protected array $matrix = []; diff --git a/Math/Stochastic/NaiveBayesClassifier.php b/Math/Stochastic/NaiveBayesClassifier.php index 419c19090..740bd3beb 100644 --- a/Math/Stochastic/NaiveBayesClassifier.php +++ b/Math/Stochastic/NaiveBayesClassifier.php @@ -141,7 +141,10 @@ final class NaiveBayesClassifier } if (\is_array($value)) { - /** @var string[] $value */ + /** + * @var string[] $value + * @var string $word + */ foreach ($value as $word) { if (isset($this->dict[$criteria][$attr]['data'][$word]) && $this->dict[$criteria][$attr]['data'][$word] >= $minimum diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index d20b83b2d..a5c82b948 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -665,6 +665,10 @@ final class ModuleManager */ public function installApplications(string $from) : void { + if (!\file_exists($this->modulePath . '/' . $from . '/Application')) { + return; + } + $dirs = \scandir($this->modulePath . '/' . $from . '/Application'); foreach ($dirs as $dir) { if ($dir === '.' || $dir === '..') { diff --git a/System/File/DirectoryInterface.php b/System/File/DirectoryInterface.php index 05ee04e9e..296d24b56 100644 --- a/System/File/DirectoryInterface.php +++ b/System/File/DirectoryInterface.php @@ -23,6 +23,9 @@ namespace phpOMS\System\File; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @phpstan-extends \ArrayAccess + * @phpstan-extends \Iterator */ interface DirectoryInterface extends ContainerInterface, \Iterator, \ArrayAccess { diff --git a/Utils/RnG/Phone.php b/Utils/RnG/Phone.php index 13dea1877..a2d36f9d5 100644 --- a/Utils/RnG/Phone.php +++ b/Utils/RnG/Phone.php @@ -63,8 +63,8 @@ class Phone $numberString = \str_replace( '$' . $i, StringUtils::generateString( - $size[$i - 1][0], - $size[$i - 1][1], + $size[$i - 1][0] ?? 0, + $size[$i - 1][1] ?? 0, '0123456789' ), $numberString