phpcs+phpstan fixes

This commit is contained in:
Dennis Eichhorn 2019-02-07 00:05:38 +01:00
parent 0d55e17842
commit 48f2552311
15 changed files with 42 additions and 152 deletions

View File

@ -92,7 +92,7 @@ class DataMapperAbstract implements DataMapperInterface
*/ /**
* Has many relation.
*
* @var array<string, array<string, string>>
* @var array<string, array<string, null|string>>
* @since 1.0.0
*/
protected static $hasMany = [];

View File

@ -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.
*

View File

@ -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
{
}

View File

@ -1,100 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package phpOMS\Math\Differential
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types=1);
namespace phpOMS\Math\Differential;
use phpOMS\Math\Parser\Evaluator;
/**
* Chi square distribution.
*
* @package phpOMS\Math\Differential
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class FiniteDifference
{
/**
* Epsilon.
*
* @var float
* @since 1.0.0
*/
public const EPSILON = 0.00001;
/**
* Differentiate by using the Newton difference quotient.
*
* Example: ('2*x^3-4x', ['x' => 99])
*
* @param string $formula Formula to differentiate
* @param array<string, float|int> $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<string, float|int> $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<string, float|int> $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');
}
}

View File

@ -89,7 +89,7 @@ class Evaluator
*
* @param string $equation Equation to convert
*
* @return array<string>
* @return array<int, string>
*
* @since 1.0.0
*/
@ -147,6 +147,7 @@ class Evaluator
$output[] = \array_pop($stack);
}
/** @var array<int, string> $output */
return $output;
}
}

View File

@ -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;

View File

@ -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.

View File

@ -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();
}
}
}

View File

@ -71,7 +71,7 @@ final class Directory extends FileAbstract implements DirectoryInterface
* @param string $path Path
* @param string $filter Filter
*
* @return array<string>
* @return array<int, string>
*
* @since 1.0.0
*/
@ -95,6 +95,7 @@ final class Directory extends FileAbstract implements DirectoryInterface
$list[] = \str_replace('\\', '/', $iterator->getSubPathname());
}
/** @var array<int, string> $list */
return $list;
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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
{
/**

View File

@ -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;

View File

@ -59,7 +59,7 @@ class BaseModelMapper extends DataMapperAbstract
]; /**
* Has many relation.
*
* @var array<string, array<string, string>>
* @var array<string, array<string, null|string>>
* @since 1.0.0
*/
protected static $hasMany = [

View File

@ -1,23 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.2
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\Math\Differential;
class FiniteDifferenceTest extends \PHPUnit\Framework\TestCase
{
public function testPlaceholder() : void
{
self::markTestIncomplete();
}
}