From 48f2552311acc825a5f0ce0c514e188e3683b9d2 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 7 Feb 2019 00:05:38 +0100 Subject: [PATCH] phpcs+phpstan fixes --- DataStorage/Database/DataMapperAbstract.php | 2 +- Localization/Localization.php | 7 +- Localization/NullLocalization.php | 2 +- Math/Differential/FiniteDifference.php | 100 ------------------ Math/Parser/Evaluator.php | 3 +- Math/Statistic/MeasureOfDispersion.php | 1 + Module/InstallerAbstract.php | 28 ++--- Module/UninstallerAbstract.php | 10 +- System/File/Local/Directory.php | 3 +- Utils/StringUtils.php | 4 + Views/View.php | 4 +- Views/ViewAbstract.php | 3 +- .../Database/DataMapperAbstractTest.php | 2 - .../Database/TestModel/BaseModelMapper.php | 2 +- .../Differential/FiniteDifferenceTest.php | 23 ---- 15 files changed, 42 insertions(+), 152 deletions(-) delete mode 100644 Math/Differential/FiniteDifference.php delete mode 100644 tests/Math/Differential/FiniteDifferenceTest.php diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 277a06efe..b9997fcd3 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -92,7 +92,7 @@ class DataMapperAbstract implements DataMapperInterface */ /** * Has many relation. * - * @var array> + * @var array> * @since 1.0.0 */ protected static $hasMany = []; diff --git a/Localization/Localization.php b/Localization/Localization.php index d7b94a6ae..9a6b9373a 100644 --- a/Localization/Localization.php +++ b/Localization/Localization.php @@ -26,7 +26,7 @@ use phpOMS\Utils\Converter\TemperatureType; * @link http://website.orange-management.de * @since 1.0.0 */ -final class Localization +class Localization { /** @@ -36,6 +36,7 @@ final class Localization * @since 1.0.0 */ private $country = ISO3166TwoEnum::_USA; + /** * Timezone. * @@ -43,6 +44,7 @@ final class Localization * @since 1.0.0 */ private $timezone = 'America/New_York'; + /** * Language ISO code. * @@ -50,6 +52,7 @@ final class Localization * @since 1.0.0 */ private $language = ISO639x1Enum::_EN; + /** * Currency. * @@ -57,6 +60,7 @@ final class Localization * @since 1.0.0 */ private $currency = ISO4217Enum::_USD; + /** * Number format. * @@ -64,6 +68,7 @@ final class Localization * @since 1.0.0 */ private $decimal = '.'; + /** * Number format. * diff --git a/Localization/NullLocalization.php b/Localization/NullLocalization.php index f00ac1f3d..b533dab38 100644 --- a/Localization/NullLocalization.php +++ b/Localization/NullLocalization.php @@ -22,7 +22,7 @@ namespace phpOMS\Localization; * @link http://website.orange-management.de * @since 1.0.0 */ -final class NullLocalizations +final class NullLocalization extends Localization { } diff --git a/Math/Differential/FiniteDifference.php b/Math/Differential/FiniteDifference.php deleted file mode 100644 index 21bfc5cff..000000000 --- a/Math/Differential/FiniteDifference.php +++ /dev/null @@ -1,100 +0,0 @@ - 99]) - * - * @param string $formula Formula to differentiate - * @param array $variable Variable to differentiate (name value assiziation) - * - * @return float - * - * @since 1.0.0 - */ - public static function getNewtonDifferenceQuotient(string $formula, array $variable) : float - { - return (Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variable['x']])) / self::EPSILON; - } - - /** - * Differentiate by using the symmetric difference quotient. - * - * Example: ('2*x^3-4x', ['x' => 99]) - * - * @param string $formula Formula to differentiate - * @param array $variable Variable to differentiate (name value assiziation) - * - * @return float - * - * @since 1.0.0 - */ - public static function getSymmetricDifferenceQuotient(string $formula, array $variable) : float - { - return (Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON])) / (2 * self::EPSILON); - } - - /** - * Differentiate by using the five point stencil. - * - * Example: ('2*x^3-4x', ['x' => 99], 3) - * - * @param string $formula Formula to differentiate - * @param array $variable Variable to differentiate (name value assiziation) - * @param int $derivative Derivative (4th = highest) - * - * @return float - * - * @throws \Exception - * - * @since 1.0.0 - */ - public static function getFivePointStencil(string $formula, array $variable, int $derivative = 1) : float - { - if ($derivative === 1) { - return (-Evaluator::evaluate($formula, ['x' => $variable['x'] + 2 * self::EPSILON]) + 8 * Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) - 8 * Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON]) + Evaluator::evaluate($formula, ['x' => $variable['x'] - 2 * self::EPSILON])) / (12 * self::EPSILON); - } elseif ($derivative === 2) { - return (-Evaluator::evaluate($formula, ['x' => $variable['x'] + 2 * self::EPSILON]) + 16 * Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) - 30 * Evaluator::evaluate($formula, ['x' => $variable['x']]) + 16 * Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variable['x'] - 2 * self::EPSILON])) / (12 * self::EPSILON ** 2); - } elseif ($derivative === 3) { - return (Evaluator::evaluate($formula, ['x' => $variable['x'] + 2 * self::EPSILON]) - 2 * Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) + 2 * Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON]) - Evaluator::evaluate($formula, ['x' => $variable['x'] - 2 * self::EPSILON])) / (2 * self::EPSILON ** 3); - } elseif ($derivative === 4) { - return (Evaluator::evaluate($formula, ['x' => $variable['x'] + 2 * self::EPSILON]) - 4 * Evaluator::evaluate($formula, ['x' => $variable['x'] + self::EPSILON]) + 6 * Evaluator::evaluate($formula, ['x' => $variable['x']]) - 4 * Evaluator::evaluate($formula, ['x' => $variable['x'] - self::EPSILON]) + Evaluator::evaluate($formula, ['x' => $variable['x'] - 2 * self::EPSILON])) / (self::EPSILON ** 4); - } - - throw new \Exception('Derivative too high'); - } -} diff --git a/Math/Parser/Evaluator.php b/Math/Parser/Evaluator.php index 016fc0a67..cbebce0ee 100644 --- a/Math/Parser/Evaluator.php +++ b/Math/Parser/Evaluator.php @@ -89,7 +89,7 @@ class Evaluator * * @param string $equation Equation to convert * - * @return array + * @return array * * @since 1.0.0 */ @@ -147,6 +147,7 @@ class Evaluator $output[] = \array_pop($stack); } + /** @var array $output */ return $output; } } diff --git a/Math/Statistic/MeasureOfDispersion.php b/Math/Statistic/MeasureOfDispersion.php index c4e5c2f1e..2f9b0cc4c 100644 --- a/Math/Statistic/MeasureOfDispersion.php +++ b/Math/Statistic/MeasureOfDispersion.php @@ -242,6 +242,7 @@ final class MeasureOfDispersion /** @var int $count */ $Q1 = Average::median(\array_slice($x, 0, $count)); + /** @var int $count */ $Q3 = Average::median(\array_slice($x, -$count, $count)); return $Q3 - $Q1; diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index f5ac535b0..f4774ddaf 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -105,7 +105,7 @@ abstract class InstallerAbstract * @since 1.0.0 */ private static function createTables(DatabasePool $dbPool, InfoManager $info) : void - { + { $path = \dirname($info->getPath()) . '/Admin/Install/db.json'; if (!\file_exists($path)) { @@ -118,10 +118,10 @@ abstract class InstallerAbstract } $definitions = \json_decode($content, true); - foreach ($definitions as $definition) { - self::createTable($definition, $dbPool); - } - } + foreach ($definitions as $definition) { + self::createTable($definition, $dbPool); + } + } /** * Create table module. @@ -133,22 +133,22 @@ abstract class InstallerAbstract * * @since 1.0.0 */ - private static function createTable(array $definition, DatabasePool $dbPool) : void - { - $builder = new SchemaBuilder($dbPool->get('schema')); - $builder->prefix($dbPool->get('schema')->prefix); - $builder->createTable($definition['name'] ?? ''); + private static function createTable(array $definition, DatabasePool $dbPool) : void + { + $builder = new SchemaBuilder($dbPool->get('schema')); + $builder->prefix($dbPool->get('schema')->prefix); + $builder->createTable($definition['name'] ?? ''); - foreach ($definition['fields'] as $name => $def) { - $builder->field( + foreach ($definition['fields'] as $name => $def) { + $builder->field( $name, $def['type'], $def['default'] ?? null, $def['null'] ?? true, $def['primary'] ?? false, $def['autoincrement'] ?? false, $def['foreignTable'] ?? null, $def['foreignKey'] ?? null ); } - $builder->execute(); - } + $builder->execute(); + } /** * Activate after install. diff --git a/Module/UninstallerAbstract.php b/Module/UninstallerAbstract.php index f2f0d3941..353153b87 100644 --- a/Module/UninstallerAbstract.php +++ b/Module/UninstallerAbstract.php @@ -54,7 +54,7 @@ abstract class UninstallerAbstract * @since 1.0.0 */ public static function dropTables(DatabasePool $dbPool, InfoManager $info) : void - { + { $path = \dirname($info->getPath()) . '/Admin/Install/db.json'; if (!\file_exists($path)) { @@ -69,12 +69,12 @@ abstract class UninstallerAbstract $definitions = \json_decode($content, true); $builder = new SchemaBuilder($dbPool->get('schema')); - $builder->prefix($dbPool->get('schema')->prefix); + $builder->prefix($dbPool->get('schema')->prefix); - foreach ($definitions as $definition) { - $builder->dropTable($definition['table'] ?? ''); + foreach ($definitions as $definition) { + $builder->dropTable($definition['table'] ?? ''); } $builder->execute(); - } + } } diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index c2d577bba..870c12aa6 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -71,7 +71,7 @@ final class Directory extends FileAbstract implements DirectoryInterface * @param string $path Path * @param string $filter Filter * - * @return array + * @return array * * @since 1.0.0 */ @@ -95,6 +95,7 @@ final class Directory extends FileAbstract implements DirectoryInterface $list[] = \str_replace('\\', '/', $iterator->getSubPathname()); } + /** @var array $list */ return $list; } diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index d7c8406f3..087760ae0 100644 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace phpOMS\Utils; +use phpOMS\Contract\RenderableInterface; + /** * String utils class. * @@ -418,6 +420,8 @@ final class StringUtils return null; } elseif ($element instanceof \DateTime) { return $element->format('Y-m-d H:i:s'); + } elseif ($element instanceof RenderableInterface) { + return $element->render(); } else { return $element->__toString(); } diff --git a/Views/View.php b/Views/View.php index 8c6bce780..bd6b9b2d5 100644 --- a/Views/View.php +++ b/Views/View.php @@ -197,7 +197,9 @@ class View extends ViewAbstract $module = $module ?? $this->module; $theme = $theme ?? $this->theme; - + + /** @var string $module */ + /** @var string $theme */ return $this->app->l11nManager->getText($this->l11n->getLanguage(), $module, $theme, $translation); } diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index 384bbc72a..96ca3c436 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace phpOMS\Views; +use phpOMS\Contract\RenderableInterface; use phpOMS\System\File\PathException; /** @@ -24,7 +25,7 @@ use phpOMS\System\File\PathException; * @link http://website.orange-management.de * @since 1.0.0 */ -abstract class ViewAbstract implements \Serializable +abstract class ViewAbstract implements RenderableInterface { /** diff --git a/tests/DataStorage/Database/DataMapperAbstractTest.php b/tests/DataStorage/Database/DataMapperAbstractTest.php index 489cec177..28d855f4d 100644 --- a/tests/DataStorage/Database/DataMapperAbstractTest.php +++ b/tests/DataStorage/Database/DataMapperAbstractTest.php @@ -10,10 +10,8 @@ * @version 1.0.0 * @link http://website.orange-management.de */ - namespace phpOMS\tests\DataStorage\Database; - use phpOMS\tests\DataStorage\Database\TestModel\BaseModel; use phpOMS\tests\DataStorage\Database\TestModel\BaseModelMapper; use phpOMS\tests\DataStorage\Database\TestModel\ManyToManyDirectModelMapper; diff --git a/tests/DataStorage/Database/TestModel/BaseModelMapper.php b/tests/DataStorage/Database/TestModel/BaseModelMapper.php index 7c00b0b82..20dd5286d 100644 --- a/tests/DataStorage/Database/TestModel/BaseModelMapper.php +++ b/tests/DataStorage/Database/TestModel/BaseModelMapper.php @@ -59,7 +59,7 @@ class BaseModelMapper extends DataMapperAbstract ]; /** * Has many relation. * - * @var array> + * @var array> * @since 1.0.0 */ protected static $hasMany = [ diff --git a/tests/Math/Differential/FiniteDifferenceTest.php b/tests/Math/Differential/FiniteDifferenceTest.php deleted file mode 100644 index 99a72f4a7..000000000 --- a/tests/Math/Differential/FiniteDifferenceTest.php +++ /dev/null @@ -1,23 +0,0 @@ -