Minor bug fixes

docblocks, return type casting
This commit is contained in:
Dennis Eichhorn 2017-12-04 17:17:17 +01:00
parent 65be63862f
commit 2215fa2ea7
28 changed files with 48 additions and 91 deletions

View File

@ -44,7 +44,7 @@ class FinanceFormulas
*/ */
public static function getAnnualPercentageYield(float $r, int $n) : float 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 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 public static function getFutureValueFactor(float $r, int $n) : float
{ {
return pow(1 + $r, $n); return (float) pow(1 + $r, $n);
} }
/** /**

View File

@ -174,7 +174,7 @@ class ClassicalDecomposition
*/ */
public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int
{ {
return ($dataSize - $trendCycleComponents) / 2; return (int) (($dataSize - $trendCycleComponents) / 2);
} }
/** /**

View File

@ -368,7 +368,7 @@ class StockBonds
*/ */
public static function getZeroCouponBondEffectiveYield(float $F, float $PV, int $n) : float 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;
} }
} }

View File

@ -15,10 +15,6 @@ declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache; namespace phpOMS\DataStorage\Cache;
use phpOMS\DataStorage\Cache\CacheInterface;
use phpOMS\DataStorage\Cache\FileCache;
/** /**
* Database connection factory. * Database connection factory.
* *

View File

@ -17,7 +17,6 @@ namespace phpOMS\DataStorage\Cache;
use phpOMS\Config\OptionsInterface; use phpOMS\Config\OptionsInterface;
use phpOMS\Config\OptionsTrait; use phpOMS\Config\OptionsTrait;
use phpOMS\DataStorage\Cache\CacheFactory;
/** /**

View File

@ -687,10 +687,6 @@ class DataMapperAbstract implements DataMapperInterface
private static function createHasOne(\ReflectionClass $reflectionClass, $obj) private static function createHasOne(\ReflectionClass $reflectionClass, $obj)
{ {
throw new \Exception(); throw new \Exception();
foreach (static::$hasOne as $propertyName => $rel) {
}
} }
/** /**
@ -970,7 +966,6 @@ class DataMapperAbstract implements DataMapperInterface
* *
* Deletes old entries and creates new ones * Deletes old entries and creates new ones
* *
* @param string $propertyName Property name to initialize
* @param array $objsIds Object ids to insert * @param array $objsIds Object ids to insert
* @param mixed $objId Model to reference * @param mixed $objId Model to reference
* *
@ -1709,6 +1704,7 @@ class DataMapperAbstract implements DataMapperInterface
* Populate data. * Populate data.
* *
* @param array $obj Object to add the relations to * @param array $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
@ -1716,12 +1712,12 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @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) { foreach (static::$belongsTo as $member => $one) {
/** @var string $mapper */ /** @var string $mapper */
$mapper = static::$belongsTo[$member]['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 mixed $primaryKey Key
* @param int $relations Load relations * @param int $relations Load relations
* @param mixed $fill Object to fill * @param mixed $fill Object to fill
* @param int $depth Relation depth
* *
* @return mixed * @return mixed
* *
@ -2060,6 +2057,7 @@ class DataMapperAbstract implements DataMapperInterface
* Get object. * Get object.
* *
* @param int $relations Load relations * @param int $relations Load relations
* @param int $depth Relation depth
* @param string $lang Language * @param string $lang Language
* *
* @return array * @return array

View File

@ -801,9 +801,13 @@ class Builder extends BuilderAbstract
/** /**
* Count results. * Count results.
* *
* @param string $table Table to count the result set
*
* @return Builder
*
* @since 1.0.0 * @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 // 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 . ')'); return $this->select('COUNT(' . $table . ')');
@ -1161,7 +1165,7 @@ class Builder extends BuilderAbstract
} elseif ($column instanceof \Closure) { } elseif ($column instanceof \Closure) {
return $column(); return $column();
} elseif ($column instanceof \Serializable) { } elseif ($column instanceof \Serializable) {
return $column; return $column->serialize();
} }
throw new \Exception(); throw new \Exception();

View File

@ -17,7 +17,6 @@ namespace phpOMS\DataStorage\Database\Schema;
use phpOMS\DataStorage\Database\BuilderAbstract; use phpOMS\DataStorage\Database\BuilderAbstract;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Query;
/** /**
* Database query builder. * Database query builder.

View File

@ -107,7 +107,7 @@ class Functions
$fact2 *= $d; $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 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));
} }
} }

View File

@ -47,6 +47,10 @@ class Polygon implements D2ShapeInterface
/** /**
* Constructor. * 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 * @since 1.0.0
*/ */
public function __construct(array $coord) public function __construct(array $coord)
@ -182,7 +186,7 @@ class Polygon implements D2ShapeInterface
*/ */
public function getSurface() : float public function getSurface() : float
{ {
return abs($this->getSignedSurface()); return (float) abs($this->getSignedSurface());
} }
/** /**

View File

@ -118,7 +118,7 @@ class Sphere implements D3ShapeInterface
*/ */
public static function getRadiusByVolume(float $v) : float public static function getRadiusByVolume(float $v) : float
{ {
return pow($v * 3 / (4 * pi()), 1 / 3); return (float) pow($v * 3 / (4 * pi()), 1 / 3);
} }
/** /**

View File

@ -29,13 +29,13 @@ class InvalidDimensionException extends \UnexpectedValueException
/** /**
* Constructor. * Constructor.
* *
* @param string $message Exception message * @param mixed $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception $previous Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @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); parent::__construct('Dimension "' . $message . '" is not valid.', $code, $previous);
} }

View File

@ -129,7 +129,7 @@ class Integer
} }
} }
return $m; return (int) $m;
} }
/** /**

View File

@ -243,7 +243,7 @@ class Average
throw new ZeroDevisionException(); throw new ZeroDevisionException();
} }
return pow(array_product($values), 1 / $count); return (float) pow(array_product($values), 1 / $count);
} }
/** /**

View File

@ -67,7 +67,7 @@ class BinomialDistribution
*/ */
public static function getMgf(int $n, float $t, float $p) : float 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);
} }
/** /**

View File

@ -159,7 +159,7 @@ class ChiSquaredDistribution
throw new \Exception('Out of bounds'); 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'); throw new \Exception('Out of bounds');
} }
return pow(1 - 2 * $t, -$df / 2); return (float) pow(1 - 2 * $t, -$df / 2);
} }
/** /**

View File

@ -107,7 +107,7 @@ class ExponentialDistribution
*/ */
public static function getVariance(float $lambda) : float public static function getVariance(float $lambda) : float
{ {
return pow($lambda, -2); return (float) pow($lambda, -2);
} }
/** /**

View File

@ -38,7 +38,7 @@ class GeometricDistribution
*/ */
public static function getPmf(float $p, int $k) : float public static function getPmf(float $p, int $k) : float
{ {
return pow(1 - $p, $k - 1) * $p; return (float) pow(1 - $p, $k - 1) * $p;
} }
/** /**

View File

@ -132,11 +132,11 @@ class NormalDistribution
* *
* @param float $sig * @param float $sig
* *
* @return float * @return array
* *
* @since 1.0.0 * @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)]]; return [[1 / $sig ** 2, 0], [0, 1 / (2 * $sig ** 4)]];
} }

View File

@ -148,7 +148,7 @@ class PoissonDistribution
*/ */
public static function getSkewness(float $lambda) : float 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 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 public static function getExKurtosis(float $lambda) : float
{ {
return pow($lambda, -1); return (float) pow($lambda, -1);
} }
public static function getRandom() public static function getRandom()

View File

@ -103,9 +103,9 @@ class Header implements \Serializable
* *
* @since 1.0.0 * @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 * @since 1.0.0
*/ */
public function setType($type) /* : void */ public function setType(int $type) /* : void */
{ {
$this->type = $type; $this->type = $type;
} }
@ -125,7 +125,7 @@ class Header implements \Serializable
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getSubtype() public function getSubtype() : int
{ {
return $this->subtype; return $this->subtype;
} }

View File

@ -175,7 +175,7 @@ class Directory extends FileAbstract implements DirectoryInterface
/** /**
* {@inheritdoc} * {@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
{ {
} }

View File

@ -91,7 +91,7 @@ class File extends FileAbstract implements FileInterface
return false; return false;
} }
$exists = self::ftpExists($con, $http); $exists = self::ftpExists($con, $http->getPath());
if ( if (
(($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists)
@ -128,7 +128,7 @@ class File extends FileAbstract implements FileInterface
{ {
$temp = fopen('php://temp', 'r+'); $temp = fopen('php://temp', 'r+');
$http = new Http($path); $http = new Http($path);
$content = '';
$con = self::ftpConnect($http); $con = self::ftpConnect($http);
if (ftp_chdir($con, File::dirpath($path)) && ftp_fget($con, $temp, $path, FTP_BINARY, 0)) { if (ftp_chdir($con, File::dirpath($path)) && ftp_fget($con, $temp, $path, FTP_BINARY, 0)) {

View File

@ -109,11 +109,6 @@ abstract class StorageAbstract
return static::getClassType($path)::parent($path); return static::getClassType($path)::parent($path);
} }
/**
* {@inheritdoc}
*/
abstract public static function create(string $path) : bool;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -201,39 +196,4 @@ abstract class StorageAbstract
{ {
return static::getClassType($path)::sanitize($path, $replace); 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;
} }

View File

@ -82,6 +82,8 @@ class JobQueue
} }
sleep(1); sleep(1);
return -1;
} }
private function runAsDeamon() private function runAsDeamon()

View File

@ -152,7 +152,7 @@ class StringCompare
*/ */
public static function valueLength(string $s1, string $s2) : int public static function valueLength(string $s1, string $s2) : int
{ {
return abs(strlen($s1) - strlen($s2)); return (int) abs(strlen($s1) - strlen($s2));
} }
/** /**

View File

@ -15,9 +15,6 @@ declare(strict_types = 1);
namespace phpOMS\Utils\TaskSchedule; namespace phpOMS\Utils\TaskSchedule;
use phpOMS\Validation\Base\DateTime;
/** /**
* CronJob class. * CronJob class.
* *

View File

@ -15,8 +15,6 @@ declare(strict_types = 1);
namespace phpOMS\Utils\TaskSchedule; namespace phpOMS\Utils\TaskSchedule;
use phpOMS\Validation\Base\DateTime;
/** /**
* Task scheduler class. * Task scheduler class.
* *