Test fixes

This commit is contained in:
Dennis Eichhorn 2017-10-14 20:37:14 +02:00
parent 1b8481ad06
commit e6dc9f4e05
8 changed files with 90 additions and 74 deletions

View File

@ -1197,14 +1197,14 @@ class FinanceFormulas
/**
* Rate of Inflation
*
* @param float $oldCPI Consumer price index old
* @param float $newCPI Consumer price index new
* @param float $oldCPI Consumer price index old
*
* @return float
*
* @since 1.0.0
*/
public static function getRateOfOnflation(float $oldCPI, float $newCPI) : float
public static function getRateOfOnflation(float $newCPI, float $oldCPI) : float
{
return $newCPI / $oldCPI - 1;
}
@ -1315,6 +1315,54 @@ class FinanceFormulas
return $P * $r * $t;
}
/**
* Simple Interest Rate
*
* @param float $I Interest
* @param float $P Principal
* @param int $t Time
*
* @return float
*
* @since 1.0.0
*/
public static function getSimpleInterestRate(float $I, float $P, int $t) : float
{
return $I / ($P * $t);
}
/**
* Simple Interest Principal
*
* @param float $I Interest
* @param float $r Rate
* @param int $t Time
*
* @return float
*
* @since 1.0.0
*/
public static function getSimpleInterestPrincipal(float $I, float $r, int $t) : float
{
return $I / ($r * $t);
}
/**
* Simple Interest Principal
*
* @param float $I Interest
* @param float $P Principal
* @param float $r Rate
*
* @return int
*
* @since 1.0.0
*/
public static function getSimpleInterestTime(float $I, float $P, float $r) : int
{
return (int) round($I / ($P * $r));
}
/**
* Relative market share by share
*

View File

@ -119,7 +119,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
*/
public function getDatabase() : string
{
return $this->dbdata['database'];
return $this->dbdata['database'] ?? '';
}
/**
@ -131,7 +131,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
*/
public function getHost() : string
{
return $this->dbdata['host'];
return $this->dbdata['host'] ?? '';
}
/**
@ -143,7 +143,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
*/
public function getPort() : int
{
return (int) $this->dbdata['port'];
return (int) $this->dbdata['port'] ?? 0;
}
/**

View File

@ -33,6 +33,7 @@ class ConnectionFactory
* Constructor.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
private function __construct()
{

View File

@ -189,12 +189,6 @@ class Builder extends BuilderAbstract
*/
public $raw = '';
protected $unionLimit = null;
protected $unionOffset = null;
protected $unionOrders = [];
/**
* Comparison OPERATORS.
*
@ -336,7 +330,7 @@ class Builder extends BuilderAbstract
*/
public function newQuery() : Builder
{
return new static($this->connection, $this->grammar);
return new static($this->connection, $this->isReadOnly);
}
/**
@ -376,7 +370,7 @@ class Builder extends BuilderAbstract
}
$this->type = QueryType::RAW;
$this->raw = $raw;
$this->raw = rtrim($raw, ';');
return $this;
}
@ -799,15 +793,6 @@ class Builder extends BuilderAbstract
return $this->select('COUNT(' . $table . ')');
}
/**
* Check if exists.
*
* @since 1.0.0
*/
public function exists()
{
}
/**
* Select minimum.
*
@ -964,6 +949,10 @@ class Builder extends BuilderAbstract
*/
public function update(...$tables) : Builder
{
if($this->isReadOnly) {
throw new \Exception();
}
$this->type = QueryType::UPDATE;
foreach ($tables as $key => $table) {
@ -979,6 +968,10 @@ class Builder extends BuilderAbstract
public function delete() : Builder
{
if($this->isReadOnly) {
throw new \Exception();
}
$this->type = QueryType::DELETE;
return $this;

View File

@ -333,7 +333,7 @@ class Grammar extends GrammarAbstract
return '(' . rtrim($values, ', ') . ')';
} elseif ($value instanceof \DateTime) {
return $this->valueQuotes . $value->format('Y-m-d h:m:s') . $this->valueQuotes;
return $this->valueQuotes . $value->format('Y-m-d H:i:s') . $this->valueQuotes;
} elseif (is_null($value)) {
return 'NULL';
} elseif (is_bool($value)) {

View File

@ -42,7 +42,7 @@ class FileLogger implements LoggerInterface
* @var array
* @since 1.0.0
*/
private $timings = [];
private static $timings = [];
/**
* Instance.
@ -174,16 +174,22 @@ class FileLogger implements LoggerInterface
*
* @param string $id the ID by which this time measurement gets identified
*
* @return void
* @return bool
*
* @since 1.0.0
*/
public function startTimeLog($id = '') /* : void */
public static function startTimeLog($id = '') : bool
{
if(isset(self::$timings[$id])) {
return false;
}
$mtime = explode(' ', microtime());
$mtime = $mtime[1] + $mtime[0];
$this->timings[$id] = ['start' => $mtime];
self::$timings[$id] = ['start' => $mtime];
return true;
}
/**
@ -195,29 +201,15 @@ class FileLogger implements LoggerInterface
*
* @since 1.0.0
*/
public function endTimeLog($id = '') : int
public static function endTimeLog($id = '') : float
{
$mtime = explode(' ', microtime());
$mtime = $mtime[1] + $mtime[0];
$this->timings[$id]['end'] = $mtime;
$this->timings[$id]['time'] = $mtime - $this->timings[$id]['start'];
self::$timings[$id]['end'] = $mtime;
self::$timings[$id]['time'] = $mtime - self::$timings[$id]['start'];
return $this->timings[$id]['time'];
}
/**
* Sorts timings descending.
*
* @param array [float] &$timings the timing array to sort
*
* @return void
*
* @since 1.0.0
*/
public function timingSort(&$timings) /* : void */
{
uasort($timings, [$this, 'orderSort']);
return self::$timings[$id]['time'];
}
/**
@ -261,25 +253,6 @@ class FileLogger implements LoggerInterface
return strtr($message, $replace);
}
/**
* Sorts all timings descending.
*
* @param array $a
* @param array $b
*
* @return int
*
* @since 1.0.0
*/
private function orderSort($a, $b) : int
{
if ($a['time'] == $b['time']) {
return 0;
}
return ($a['time'] > $b['time']) ? -1 : 1;
}
/**
* Write to file.
*

View File

@ -227,7 +227,7 @@ class Functions
*/
public static function isOdd($a) : bool
{
return $a & 1;
return (bool) ($a & 1);
}
/**
@ -241,7 +241,7 @@ class Functions
*/
public static function isEven($a) : bool
{
return !($a & 1);
return !((bool) ($a & 1));
}
/**
@ -254,7 +254,7 @@ class Functions
* @param mixed $length Circle size
* @param mixed $start Start value
*
* @return int
* @return int Lowest value is 0 and highest value is length - 1
*
* @since 1.0.0
*/

View File

@ -16,6 +16,7 @@ declare(strict_types=1);
namespace phpOMS\System\File\Local;
use phpOMS\System\File\ContainerInterface;
use phpOMS\System\File\StorageAbstract;
use phpOMS\System\File\PathException;
/**
* Filesystem class.
@ -184,7 +185,7 @@ class LocalStorage extends StorageAbstract
public static function put(string $path, string $content, int $mode = 0) : bool
{
if(is_dir($path)) {
throw new \Exception();
throw new PathException($path);
}
return File::put($path, $content, $mode);
@ -196,7 +197,7 @@ class LocalStorage extends StorageAbstract
public static function get(string $path) : string
{
if(is_dir($path)) {
throw new \Exception();
throw new PathException($path);
}
return File::get($path);
@ -208,7 +209,7 @@ class LocalStorage extends StorageAbstract
public static function list(string $path, string $filter = '*') : array
{
if(is_file($path)) {
throw new \Exception();
throw new PathException($path);
}
return Directory::list($path, $filter);
@ -228,7 +229,7 @@ class LocalStorage extends StorageAbstract
public static function set(string $path, string $content) : bool
{
if(is_dir($path)) {
throw new \Exception();
throw new PathException($path);
}
return File::set($path, $content);
@ -240,7 +241,7 @@ class LocalStorage extends StorageAbstract
public static function append(string $path, string $content) : bool
{
if(is_dir($path)) {
throw new \Exception();
throw new PathException($path);
}
return File::append($path, $content);
@ -252,7 +253,7 @@ class LocalStorage extends StorageAbstract
public static function prepend(string $path, string $content) : bool
{
if(is_dir($path)) {
throw new \Exception();
throw new PathException($path);
}
return File::prepend($path, $content);
@ -264,7 +265,7 @@ class LocalStorage extends StorageAbstract
public static function extension(string $path) : string
{
if(is_dir($path)) {
throw new \Exception();
throw new PathException($path);
}
return File::extension($path);