From 2215fa2ea7d8a1194a7f3ec65aa34a2f2add01b9 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 4 Dec 2017 17:17:17 +0100 Subject: [PATCH] Minor bug fixes docblocks, return type casting --- Business/Finance/FinanceFormulas.php | 6 +-- .../Forecasting/ClassicalDecomposition.php | 2 +- Business/Finance/StockBonds.php | 2 +- DataStorage/Cache/CacheFactory.php | 4 -- DataStorage/Cache/CachePool.php | 1 - DataStorage/Database/DataMapperAbstract.php | 12 +++--- DataStorage/Database/Query/Builder.php | 8 +++- DataStorage/Database/Schema/Builder.php | 1 - Math/Functions/Functions.php | 4 +- Math/Geometry/Shape/D2/Polygon.php | 6 ++- Math/Geometry/Shape/D3/Sphere.php | 2 +- .../Exception/InvalidDimensionException.php | 4 +- Math/Number/Integer.php | 2 +- Math/Statistic/Average.php | 2 +- .../Distribution/BinomialDistribution.php | 2 +- .../Distribution/ChiSquaredDistribution.php | 4 +- .../Distribution/ExponentialDistribution.php | 2 +- .../Distribution/GeometricDistribution.php | 2 +- .../Distribution/NormalDistribution.php | 4 +- .../Distribution/PoissonDistribution.php | 6 +-- Socket/Packets/Header.php | 8 ++-- System/File/Ftp/Directory.php | 2 +- System/File/Ftp/File.php | 4 +- System/File/StorageAbstract.php | 40 ------------------- Utils/JobQueue/JobQueue.php | 2 + Utils/StringCompare.php | 2 +- Utils/TaskSchedule/CronJob.php | 3 -- Utils/TaskSchedule/TaskScheduler.php | 2 - 28 files changed, 48 insertions(+), 91 deletions(-) diff --git a/Business/Finance/FinanceFormulas.php b/Business/Finance/FinanceFormulas.php index be48d1451..5837e63c0 100644 --- a/Business/Finance/FinanceFormulas.php +++ b/Business/Finance/FinanceFormulas.php @@ -44,7 +44,7 @@ class FinanceFormulas */ public static function getAnnualPercentageYield(float $r, int $n) : float { - return pow(1 + $r / $n, $n) - 1; + return (float) pow(1 + $r / $n, $n) - 1; } /** @@ -61,7 +61,7 @@ class FinanceFormulas */ public static function getStateAnnualInterestRateOfAPY(float $apy, int $n) : float { - return (pow($apy + 1, 1 / $n) - 1) * $n; + return (float) (pow($apy + 1, 1 / $n) - 1) * $n; } /** @@ -910,7 +910,7 @@ class FinanceFormulas */ public static function getFutureValueFactor(float $r, int $n) : float { - return pow(1 + $r, $n); + return (float) pow(1 + $r, $n); } /** diff --git a/Business/Finance/Forecasting/ClassicalDecomposition.php b/Business/Finance/Forecasting/ClassicalDecomposition.php index ef02ee010..e55592ab6 100644 --- a/Business/Finance/Forecasting/ClassicalDecomposition.php +++ b/Business/Finance/Forecasting/ClassicalDecomposition.php @@ -174,7 +174,7 @@ class ClassicalDecomposition */ public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int { - return ($dataSize - $trendCycleComponents) / 2; + return (int) (($dataSize - $trendCycleComponents) / 2); } /** diff --git a/Business/Finance/StockBonds.php b/Business/Finance/StockBonds.php index 4b12b2558..7abe07e7c 100644 --- a/Business/Finance/StockBonds.php +++ b/Business/Finance/StockBonds.php @@ -368,7 +368,7 @@ class StockBonds */ public static function getZeroCouponBondEffectiveYield(float $F, float $PV, int $n) : float { - return pow($F / $PV, 1 / $n) - 1; + return (float) pow($F / $PV, 1 / $n) - 1; } } diff --git a/DataStorage/Cache/CacheFactory.php b/DataStorage/Cache/CacheFactory.php index eb0e8a872..56b2cf5d2 100644 --- a/DataStorage/Cache/CacheFactory.php +++ b/DataStorage/Cache/CacheFactory.php @@ -15,10 +15,6 @@ declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; -use phpOMS\DataStorage\Cache\CacheInterface; -use phpOMS\DataStorage\Cache\FileCache; - - /** * Database connection factory. * diff --git a/DataStorage/Cache/CachePool.php b/DataStorage/Cache/CachePool.php index d69b4a7fd..9fa2d99f5 100644 --- a/DataStorage/Cache/CachePool.php +++ b/DataStorage/Cache/CachePool.php @@ -17,7 +17,6 @@ namespace phpOMS\DataStorage\Cache; use phpOMS\Config\OptionsInterface; use phpOMS\Config\OptionsTrait; -use phpOMS\DataStorage\Cache\CacheFactory; /** diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index b37df27e3..db441325e 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -687,10 +687,6 @@ class DataMapperAbstract implements DataMapperInterface private static function createHasOne(\ReflectionClass $reflectionClass, $obj) { throw new \Exception(); - - foreach (static::$hasOne as $propertyName => $rel) { - - } } /** @@ -970,7 +966,6 @@ class DataMapperAbstract implements DataMapperInterface * * Deletes old entries and creates new ones * - * @param string $propertyName Property name to initialize * @param array $objsIds Object ids to insert * @param mixed $objId Model to reference * @@ -1709,6 +1704,7 @@ class DataMapperAbstract implements DataMapperInterface * Populate data. * * @param array $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * @@ -1716,12 +1712,12 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - public static function populateBelongsToArray(array &$obj) /* : void */ + public static function populateBelongsToArray(array &$obj, int $depth = null) /* : void */ { foreach (static::$belongsTo as $member => $one) { /** @var string $mapper */ $mapper = static::$belongsTo[$member]['mapper']; - $obj[$member] = self::getInitialized($mapper, $obj[$member]) ?? $mapper::get($obj[$member]); + $obj[$member] = self::getInitialized($mapper, $obj[$member]) ?? $mapper::get($obj[$member], RelationType::ALL, null, $depth); } } @@ -1818,6 +1814,7 @@ class DataMapperAbstract implements DataMapperInterface * @param mixed $primaryKey Key * @param int $relations Load relations * @param mixed $fill Object to fill + * @param int $depth Relation depth * * @return mixed * @@ -2060,6 +2057,7 @@ class DataMapperAbstract implements DataMapperInterface * Get object. * * @param int $relations Load relations + * @param int $depth Relation depth * @param string $lang Language * * @return array diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index aa521c90a..10002cec8 100644 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -801,9 +801,13 @@ class Builder extends BuilderAbstract /** * Count results. * + * @param string $table Table to count the result set + * + * @return Builder + * * @since 1.0.0 */ - public function count(string $table = '*') + public function count(string $table = '*') : Builder { // todo: don't do this as string, create new object new Count(); this can get handled by the grammar parser WAY better return $this->select('COUNT(' . $table . ')'); @@ -1161,7 +1165,7 @@ class Builder extends BuilderAbstract } elseif ($column instanceof \Closure) { return $column(); } elseif ($column instanceof \Serializable) { - return $column; + return $column->serialize(); } throw new \Exception(); diff --git a/DataStorage/Database/Schema/Builder.php b/DataStorage/Database/Schema/Builder.php index c70e7e515..02c0680e4 100644 --- a/DataStorage/Database/Schema/Builder.php +++ b/DataStorage/Database/Schema/Builder.php @@ -17,7 +17,6 @@ namespace phpOMS\DataStorage\Database\Schema; use phpOMS\DataStorage\Database\BuilderAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; -use phpOMS\DataStorage\Database\Query; /** * Database query builder. diff --git a/Math/Functions/Functions.php b/Math/Functions/Functions.php index a4bee2b30..4ca054327 100644 --- a/Math/Functions/Functions.php +++ b/Math/Functions/Functions.php @@ -107,7 +107,7 @@ class Functions $fact2 *= $d; } - return $fact / $fact2; + return (int) ($fact / $fact2); } /** @@ -260,6 +260,6 @@ class Functions */ public static function getRelativeDegree(int $value, int $length, int $start = 0) : int { - return abs(self::mod($value - $start, $length)); + return (int) abs(self::mod($value - $start, $length)); } } diff --git a/Math/Geometry/Shape/D2/Polygon.php b/Math/Geometry/Shape/D2/Polygon.php index 45ed1ca25..cb88eda28 100644 --- a/Math/Geometry/Shape/D2/Polygon.php +++ b/Math/Geometry/Shape/D2/Polygon.php @@ -47,6 +47,10 @@ class Polygon implements D2ShapeInterface /** * Constructor. * + * @param array[] $coord 2 Dimensional coordinate array where the indices are x and y + * + * @example Polygon([['x' => 1, 'y' => 2], ['x' => ...], ...]) + * * @since 1.0.0 */ public function __construct(array $coord) @@ -182,7 +186,7 @@ class Polygon implements D2ShapeInterface */ public function getSurface() : float { - return abs($this->getSignedSurface()); + return (float) abs($this->getSignedSurface()); } /** diff --git a/Math/Geometry/Shape/D3/Sphere.php b/Math/Geometry/Shape/D3/Sphere.php index a3b65326a..9b63c0df4 100644 --- a/Math/Geometry/Shape/D3/Sphere.php +++ b/Math/Geometry/Shape/D3/Sphere.php @@ -118,7 +118,7 @@ class Sphere implements D3ShapeInterface */ public static function getRadiusByVolume(float $v) : float { - return pow($v * 3 / (4 * pi()), 1 / 3); + return (float) pow($v * 3 / (4 * pi()), 1 / 3); } /** diff --git a/Math/Matrix/Exception/InvalidDimensionException.php b/Math/Matrix/Exception/InvalidDimensionException.php index d18fc398a..de1d44abd 100644 --- a/Math/Matrix/Exception/InvalidDimensionException.php +++ b/Math/Matrix/Exception/InvalidDimensionException.php @@ -29,13 +29,13 @@ class InvalidDimensionException extends \UnexpectedValueException /** * Constructor. * - * @param string $message Exception message + * @param mixed $message Exception message * @param int $code Exception code * @param \Exception $previous Previous exception * * @since 1.0.0 */ - public function __construct(string $message, int $code = 0, \Exception $previous = null) + public function __construct($message, int $code = 0, \Exception $previous = null) { parent::__construct('Dimension "' . $message . '" is not valid.', $code, $previous); } diff --git a/Math/Number/Integer.php b/Math/Number/Integer.php index f3d456987..652f9478a 100644 --- a/Math/Number/Integer.php +++ b/Math/Number/Integer.php @@ -129,7 +129,7 @@ class Integer } } - return $m; + return (int) $m; } /** diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php index 1a1c7f0b6..14d0a8b54 100644 --- a/Math/Statistic/Average.php +++ b/Math/Statistic/Average.php @@ -243,7 +243,7 @@ class Average throw new ZeroDevisionException(); } - return pow(array_product($values), 1 / $count); + return (float) pow(array_product($values), 1 / $count); } /** diff --git a/Math/Stochastic/Distribution/BinomialDistribution.php b/Math/Stochastic/Distribution/BinomialDistribution.php index a9d8f96b7..e94375ca8 100644 --- a/Math/Stochastic/Distribution/BinomialDistribution.php +++ b/Math/Stochastic/Distribution/BinomialDistribution.php @@ -67,7 +67,7 @@ class BinomialDistribution */ public static function getMgf(int $n, float $t, float $p) : float { - return pow(1 - $p + $p * exp($t), $n); + return (float) pow(1 - $p + $p * exp($t), $n); } /** diff --git a/Math/Stochastic/Distribution/ChiSquaredDistribution.php b/Math/Stochastic/Distribution/ChiSquaredDistribution.php index a4cb25e5e..3d593fb98 100644 --- a/Math/Stochastic/Distribution/ChiSquaredDistribution.php +++ b/Math/Stochastic/Distribution/ChiSquaredDistribution.php @@ -159,7 +159,7 @@ class ChiSquaredDistribution throw new \Exception('Out of bounds'); } - return 1 / (pow(2, $df / 2) * (Functions::getGammaInteger((int) $df / 2))) * pow($x, $df / 2 - 1) * exp(-$x / 2); + return 1 / (pow(2, $df / 2) * (Functions::getGammaInteger((int) ($df / 2)))) * pow($x, $df / 2 - 1) * exp(-$x / 2); } /** @@ -236,7 +236,7 @@ class ChiSquaredDistribution throw new \Exception('Out of bounds'); } - return pow(1 - 2 * $t, -$df / 2); + return (float) pow(1 - 2 * $t, -$df / 2); } /** diff --git a/Math/Stochastic/Distribution/ExponentialDistribution.php b/Math/Stochastic/Distribution/ExponentialDistribution.php index 8eb1f2b8d..e08499a41 100644 --- a/Math/Stochastic/Distribution/ExponentialDistribution.php +++ b/Math/Stochastic/Distribution/ExponentialDistribution.php @@ -107,7 +107,7 @@ class ExponentialDistribution */ public static function getVariance(float $lambda) : float { - return pow($lambda, -2); + return (float) pow($lambda, -2); } /** diff --git a/Math/Stochastic/Distribution/GeometricDistribution.php b/Math/Stochastic/Distribution/GeometricDistribution.php index c0d05fad6..df796544d 100644 --- a/Math/Stochastic/Distribution/GeometricDistribution.php +++ b/Math/Stochastic/Distribution/GeometricDistribution.php @@ -38,7 +38,7 @@ class GeometricDistribution */ public static function getPmf(float $p, int $k) : float { - return pow(1 - $p, $k - 1) * $p; + return (float) pow(1 - $p, $k - 1) * $p; } /** diff --git a/Math/Stochastic/Distribution/NormalDistribution.php b/Math/Stochastic/Distribution/NormalDistribution.php index ec538c902..813b053b8 100644 --- a/Math/Stochastic/Distribution/NormalDistribution.php +++ b/Math/Stochastic/Distribution/NormalDistribution.php @@ -132,11 +132,11 @@ class NormalDistribution * * @param float $sig * - * @return float + * @return array * * @since 1.0.0 */ - public static function getFisherInformation(float $sig) : float + public static function getFisherInformation(float $sig) : array { return [[1 / $sig ** 2, 0], [0, 1 / (2 * $sig ** 4)]]; } diff --git a/Math/Stochastic/Distribution/PoissonDistribution.php b/Math/Stochastic/Distribution/PoissonDistribution.php index f00d059ab..110c762fa 100644 --- a/Math/Stochastic/Distribution/PoissonDistribution.php +++ b/Math/Stochastic/Distribution/PoissonDistribution.php @@ -148,7 +148,7 @@ class PoissonDistribution */ public static function getSkewness(float $lambda) : float { - return pow($lambda, -1 / 2); + return (float) pow($lambda, -1 / 2); } /** @@ -162,7 +162,7 @@ class PoissonDistribution */ public static function getFisherInformation(float $lambda) : float { - return pow($lambda, -1); + return (float) pow($lambda, -1); } /** @@ -176,7 +176,7 @@ class PoissonDistribution */ public static function getExKurtosis(float $lambda) : float { - return pow($lambda, -1); + return (float) pow($lambda, -1); } public static function getRandom() diff --git a/Socket/Packets/Header.php b/Socket/Packets/Header.php index 53cdd93d9..d55baf888 100644 --- a/Socket/Packets/Header.php +++ b/Socket/Packets/Header.php @@ -103,9 +103,9 @@ class Header implements \Serializable * * @since 1.0.0 */ - public function getType() + public function getType() : int { - return $this->type; + return (int) $this->type; } /** @@ -115,7 +115,7 @@ class Header implements \Serializable * * @since 1.0.0 */ - public function setType($type) /* : void */ + public function setType(int $type) /* : void */ { $this->type = $type; } @@ -125,7 +125,7 @@ class Header implements \Serializable * * @since 1.0.0 */ - public function getSubtype() + public function getSubtype() : int { return $this->subtype; } diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 651fd6525..de2d637a6 100644 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -175,7 +175,7 @@ class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} */ - public static function create(string $path, string $permission = '0755', bool $recursive = false) : bool + public static function create(string $path, int $permission = 0755, bool $recursive = false) : bool { } diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php index 4585ae447..a1d3303eb 100644 --- a/System/File/Ftp/File.php +++ b/System/File/Ftp/File.php @@ -91,7 +91,7 @@ class File extends FileAbstract implements FileInterface return false; } - $exists = self::ftpExists($con, $http); + $exists = self::ftpExists($con, $http->getPath()); if ( (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) @@ -128,7 +128,7 @@ class File extends FileAbstract implements FileInterface { $temp = fopen('php://temp', 'r+'); $http = new Http($path); - + $content = ''; $con = self::ftpConnect($http); if (ftp_chdir($con, File::dirpath($path)) && ftp_fget($con, $temp, $path, FTP_BINARY, 0)) { diff --git a/System/File/StorageAbstract.php b/System/File/StorageAbstract.php index 7dffda6a0..5f111640c 100644 --- a/System/File/StorageAbstract.php +++ b/System/File/StorageAbstract.php @@ -109,11 +109,6 @@ abstract class StorageAbstract return static::getClassType($path)::parent($path); } - /** - * {@inheritdoc} - */ - abstract public static function create(string $path) : bool; - /** * {@inheritdoc} */ @@ -201,39 +196,4 @@ abstract class StorageAbstract { return static::getClassType($path)::sanitize($path, $replace); } - - /** - * {@inheritdoc} - */ - abstract public static function list(string $path, string $filter = '*') : array; - - /** - * {@inheritdoc} - */ - abstract public static function put(string $path, string $content, int $mode = 0) : bool; - - /** - * {@inheritdoc} - */ - abstract public static function get(string $path) : string; - - /** - * {@inheritdoc} - */ - abstract public static function set(string $path, string $content) : bool; - - /** - * {@inheritdoc} - */ - abstract public static function append(string $path, string $content) : bool; - - /** - * {@inheritdoc} - */ - abstract public static function prepend(string $path, string $content) : bool; - - /** - * {@inheritdoc} - */ - abstract public static function extension(string $path) : string; } diff --git a/Utils/JobQueue/JobQueue.php b/Utils/JobQueue/JobQueue.php index 3a71a4080..3a64f40e5 100644 --- a/Utils/JobQueue/JobQueue.php +++ b/Utils/JobQueue/JobQueue.php @@ -82,6 +82,8 @@ class JobQueue } sleep(1); + + return -1; } private function runAsDeamon() diff --git a/Utils/StringCompare.php b/Utils/StringCompare.php index bd2e90098..51e5286f4 100644 --- a/Utils/StringCompare.php +++ b/Utils/StringCompare.php @@ -152,7 +152,7 @@ class StringCompare */ public static function valueLength(string $s1, string $s2) : int { - return abs(strlen($s1) - strlen($s2)); + return (int) abs(strlen($s1) - strlen($s2)); } /** diff --git a/Utils/TaskSchedule/CronJob.php b/Utils/TaskSchedule/CronJob.php index 7eac33b92..b84546ab5 100644 --- a/Utils/TaskSchedule/CronJob.php +++ b/Utils/TaskSchedule/CronJob.php @@ -15,9 +15,6 @@ declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; -use phpOMS\Validation\Base\DateTime; - - /** * CronJob class. * diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php index 652ebfc39..ba4c05727 100644 --- a/Utils/TaskSchedule/TaskScheduler.php +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -15,8 +15,6 @@ declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; -use phpOMS\Validation\Base\DateTime; - /** * Task scheduler class. *