mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-08 21:28:40 +00:00
Test fixes
This commit is contained in:
parent
1b8481ad06
commit
e6dc9f4e05
|
|
@ -1197,14 +1197,14 @@ class FinanceFormulas
|
||||||
/**
|
/**
|
||||||
* Rate of Inflation
|
* Rate of Inflation
|
||||||
*
|
*
|
||||||
* @param float $oldCPI Consumer price index old
|
|
||||||
* @param float $newCPI Consumer price index new
|
* @param float $newCPI Consumer price index new
|
||||||
|
* @param float $oldCPI Consumer price index old
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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;
|
return $newCPI / $oldCPI - 1;
|
||||||
}
|
}
|
||||||
|
|
@ -1315,6 +1315,54 @@ class FinanceFormulas
|
||||||
return $P * $r * $t;
|
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
|
* Relative market share by share
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
||||||
*/
|
*/
|
||||||
public function getDatabase() : string
|
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
|
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
|
public function getPort() : int
|
||||||
{
|
{
|
||||||
return (int) $this->dbdata['port'];
|
return (int) $this->dbdata['port'] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class ConnectionFactory
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -189,12 +189,6 @@ class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public $raw = '';
|
public $raw = '';
|
||||||
|
|
||||||
protected $unionLimit = null;
|
|
||||||
|
|
||||||
protected $unionOffset = null;
|
|
||||||
|
|
||||||
protected $unionOrders = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comparison OPERATORS.
|
* Comparison OPERATORS.
|
||||||
*
|
*
|
||||||
|
|
@ -336,7 +330,7 @@ class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function newQuery() : Builder
|
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->type = QueryType::RAW;
|
||||||
$this->raw = $raw;
|
$this->raw = rtrim($raw, ';');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -799,15 +793,6 @@ class Builder extends BuilderAbstract
|
||||||
return $this->select('COUNT(' . $table . ')');
|
return $this->select('COUNT(' . $table . ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if exists.
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function exists()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select minimum.
|
* Select minimum.
|
||||||
*
|
*
|
||||||
|
|
@ -964,6 +949,10 @@ class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function update(...$tables) : Builder
|
public function update(...$tables) : Builder
|
||||||
{
|
{
|
||||||
|
if($this->isReadOnly) {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
|
||||||
$this->type = QueryType::UPDATE;
|
$this->type = QueryType::UPDATE;
|
||||||
|
|
||||||
foreach ($tables as $key => $table) {
|
foreach ($tables as $key => $table) {
|
||||||
|
|
@ -979,6 +968,10 @@ class Builder extends BuilderAbstract
|
||||||
|
|
||||||
public function delete() : Builder
|
public function delete() : Builder
|
||||||
{
|
{
|
||||||
|
if($this->isReadOnly) {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
|
||||||
$this->type = QueryType::DELETE;
|
$this->type = QueryType::DELETE;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ class Grammar extends GrammarAbstract
|
||||||
|
|
||||||
return '(' . rtrim($values, ', ') . ')';
|
return '(' . rtrim($values, ', ') . ')';
|
||||||
} elseif ($value instanceof \DateTime) {
|
} 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)) {
|
} elseif (is_null($value)) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
} elseif (is_bool($value)) {
|
} elseif (is_bool($value)) {
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class FileLogger implements LoggerInterface
|
||||||
* @var array
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $timings = [];
|
private static $timings = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance.
|
* Instance.
|
||||||
|
|
@ -174,16 +174,22 @@ class FileLogger implements LoggerInterface
|
||||||
*
|
*
|
||||||
* @param string $id the ID by which this time measurement gets identified
|
* @param string $id the ID by which this time measurement gets identified
|
||||||
*
|
*
|
||||||
* @return void
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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 = explode(' ', microtime());
|
||||||
$mtime = $mtime[1] + $mtime[0];
|
$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
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function endTimeLog($id = '') : int
|
public static function endTimeLog($id = '') : float
|
||||||
{
|
{
|
||||||
$mtime = explode(' ', microtime());
|
$mtime = explode(' ', microtime());
|
||||||
$mtime = $mtime[1] + $mtime[0];
|
$mtime = $mtime[1] + $mtime[0];
|
||||||
|
|
||||||
$this->timings[$id]['end'] = $mtime;
|
self::$timings[$id]['end'] = $mtime;
|
||||||
$this->timings[$id]['time'] = $mtime - $this->timings[$id]['start'];
|
self::$timings[$id]['time'] = $mtime - self::$timings[$id]['start'];
|
||||||
|
|
||||||
return $this->timings[$id]['time'];
|
return self::$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']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -261,25 +253,6 @@ class FileLogger implements LoggerInterface
|
||||||
return strtr($message, $replace);
|
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.
|
* Write to file.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ class Functions
|
||||||
*/
|
*/
|
||||||
public static function isOdd($a) : bool
|
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
|
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 $length Circle size
|
||||||
* @param mixed $start Start value
|
* @param mixed $start Start value
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int Lowest value is 0 and highest value is length - 1
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\System\File\Local;
|
namespace phpOMS\System\File\Local;
|
||||||
use phpOMS\System\File\ContainerInterface;
|
use phpOMS\System\File\ContainerInterface;
|
||||||
use phpOMS\System\File\StorageAbstract;
|
use phpOMS\System\File\StorageAbstract;
|
||||||
|
use phpOMS\System\File\PathException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filesystem class.
|
* Filesystem class.
|
||||||
|
|
@ -184,7 +185,7 @@ class LocalStorage extends StorageAbstract
|
||||||
public static function put(string $path, string $content, int $mode = 0) : bool
|
public static function put(string $path, string $content, int $mode = 0) : bool
|
||||||
{
|
{
|
||||||
if(is_dir($path)) {
|
if(is_dir($path)) {
|
||||||
throw new \Exception();
|
throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return File::put($path, $content, $mode);
|
return File::put($path, $content, $mode);
|
||||||
|
|
@ -196,7 +197,7 @@ class LocalStorage extends StorageAbstract
|
||||||
public static function get(string $path) : string
|
public static function get(string $path) : string
|
||||||
{
|
{
|
||||||
if(is_dir($path)) {
|
if(is_dir($path)) {
|
||||||
throw new \Exception();
|
throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return File::get($path);
|
return File::get($path);
|
||||||
|
|
@ -208,7 +209,7 @@ class LocalStorage extends StorageAbstract
|
||||||
public static function list(string $path, string $filter = '*') : array
|
public static function list(string $path, string $filter = '*') : array
|
||||||
{
|
{
|
||||||
if(is_file($path)) {
|
if(is_file($path)) {
|
||||||
throw new \Exception();
|
throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Directory::list($path, $filter);
|
return Directory::list($path, $filter);
|
||||||
|
|
@ -228,7 +229,7 @@ class LocalStorage extends StorageAbstract
|
||||||
public static function set(string $path, string $content) : bool
|
public static function set(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
if(is_dir($path)) {
|
if(is_dir($path)) {
|
||||||
throw new \Exception();
|
throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return File::set($path, $content);
|
return File::set($path, $content);
|
||||||
|
|
@ -240,7 +241,7 @@ class LocalStorage extends StorageAbstract
|
||||||
public static function append(string $path, string $content) : bool
|
public static function append(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
if(is_dir($path)) {
|
if(is_dir($path)) {
|
||||||
throw new \Exception();
|
throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return File::append($path, $content);
|
return File::append($path, $content);
|
||||||
|
|
@ -252,7 +253,7 @@ class LocalStorage extends StorageAbstract
|
||||||
public static function prepend(string $path, string $content) : bool
|
public static function prepend(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
if(is_dir($path)) {
|
if(is_dir($path)) {
|
||||||
throw new \Exception();
|
throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return File::prepend($path, $content);
|
return File::prepend($path, $content);
|
||||||
|
|
@ -264,7 +265,7 @@ class LocalStorage extends StorageAbstract
|
||||||
public static function extension(string $path) : string
|
public static function extension(string $path) : string
|
||||||
{
|
{
|
||||||
if(is_dir($path)) {
|
if(is_dir($path)) {
|
||||||
throw new \Exception();
|
throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return File::extension($path);
|
return File::extension($path);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user