Merge branch 'develop' of https://github.com/Orange-Management/phpOMS into develop

This commit is contained in:
Dennis Eichhorn 2017-10-30 10:59:38 +01:00
commit 877e56c5cd
505 changed files with 1720 additions and 1692 deletions

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;
@ -136,7 +136,7 @@ class Account implements ArrayableInterface, \JsonSerializable
/**
* Account type.
*
* @var AccountType|int
* @var int
* @since 1.0.0
*/
protected $type = AccountType::USER;
@ -144,7 +144,7 @@ class Account implements ArrayableInterface, \JsonSerializable
/**
* Account status.
*
* @var AccountStatus|int
* @var int
* @since 1.0.0
*/
protected $status = AccountStatus::INACTIVE;
@ -324,8 +324,8 @@ class Account implements ArrayableInterface, \JsonSerializable
{
$app = isset($app) ? strtolower($app) : $app;
foreach($this->permissions as $p) {
if(($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit))
foreach ($this->permissions as $p) {
if (($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit))
&& ($p->getApp() === $app || $p->getApp() === null || !isset($app))
&& ($p->getModule() === $module || $p->getModule() === null || !isset($module))
&& ($p->getType() === $type || $p->getType() === null || !isset($type))
@ -560,7 +560,7 @@ class Account implements ArrayableInterface, \JsonSerializable
*/
public function generatePassword(string $password) /* : void */
{
$this->password = password_hash($password, PASSWORD_DEFAULT);
$this->password = \password_hash($password, \PASSWORD_DEFAULT);
}
/**
@ -624,8 +624,8 @@ class Account implements ArrayableInterface, \JsonSerializable
/**
* Json serialize.
*
* @return string
*
* @return array
*
* @since 1.0.0
*/

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;
@ -28,8 +28,8 @@ use phpOMS\Stdlib\Base\Enum;
*/
abstract class AccountStatus extends Enum
{
/* public */ const ACTIVE = 1;
/* public */ const INACTIVE = 2;
/* public */ const TIMEOUT = 3;
/* public */ const BANNED = 4;
/* public */ const ACTIVE = 1;
/* public */ const INACTIVE = 2;
/* public */ const TIMEOUT = 3;
/* public */ const BANNED = 4;
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;
@ -28,6 +28,6 @@ use phpOMS\Stdlib\Base\Enum;
*/
abstract class AccountType extends Enum
{
/* public */ const USER = 0;
/* public */ const GROUP = 1;
/* public */ const USER = 0;
/* public */ const GROUP = 1;
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;
@ -208,7 +208,7 @@ class Group implements ArrayableInterface, \JsonSerializable
/**
* Json serialize.
*
* @return string
* @return array
*
* @since 1.0.0
*/

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;
@ -28,7 +28,7 @@ use phpOMS\Stdlib\Base\Enum;
*/
abstract class GroupStatus extends Enum
{
/* public */ const ACTIVE = 1;
/* public */ const INACTIVE = 2;
/* public */ const HIDDEN = 4;
/* public */ const ACTIVE = 1;
/* public */ const INACTIVE = 2;
/* public */ const HIDDEN = 4;
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;
@ -340,7 +340,7 @@ class PermissionAbstract
*
* @param int $permission Permission
*
* @return void
* @return bool
*
* @since 1.0.0
*/

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Account;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Algorithm;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Algorithm\Knappsack;
use phpOMS\Algorithm\AlgorithmType;
@ -44,7 +44,7 @@ class Backpack
public function addPopulationItem(ItemInterface $item) : bool
{
if(isset($this->population[$item->getId()])) {
if (isset($this->population[$item->getId()])) {
return false;
}
@ -75,7 +75,7 @@ class Backpack
public function pack(int $type)
{
switch($type) {
switch ($type) {
case AlgorithmType::BRUTEFORCE:
return $this->bruteforce();
default:

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Algorithm\Knappsack;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS;
@ -145,7 +145,7 @@ class ApplicationAbstract
*/
public function __set($name, $value)
{
if(!empty($this->$name)) {
if (!empty($this->$name)) {
return;
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Asset;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Asset;
@ -28,7 +28,7 @@ use phpOMS\Stdlib\Base\Enum;
*/
abstract class AssetType extends Enum
{
/* public */ const CSS = 0;
/* public */ const JS = 1;
/* public */ const JSLATE = 2;
/* public */ const CSS = 0;
/* public */ const JS = 1;
/* public */ const JSLATE = 2;
}

View File

@ -11,11 +11,10 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Auth;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Session\SessionInterface;
/**

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Auth;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS;
@ -31,7 +31,7 @@ class AutoloadException extends \RuntimeException
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
* @param \Exception $previous Previous exception
*
* @since 1.0.0
*/

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS;
@ -47,7 +47,7 @@ class Autoloader
$class = ltrim($class, '\\');
$class = str_replace(['_', '\\'], '/', $class);
if(!file_exists($path = __DIR__ . '/../' . $class . '.php')) {
if (!file_exists($path = __DIR__ . '/../' . $class . '.php')) {
return;
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance;
@ -29,7 +29,7 @@ class Depreciation
public static function getArithmeticProgressivDepreciationRate(float $start, int $duration) : float
{
return $start / ($duration * ($duration+1) / 2);
return $start / ($duration * ($duration + 1) / 2);
}
public static function getArithmeticProgressivDepreciationInT(float $start, int $duration, int $t) : float
@ -44,7 +44,7 @@ class Depreciation
public static function getGeometicProgressivDepreciationRate(float $start, float $residual, int $duration) : float
{
return (1-pow($residual / $start, 1 / $duration));
return (1 - pow($residual / $start, 1 / $duration));
}
public static function getGeometicDegressivDepreciationInT(float $start, float $residual, int $duration, int $t) : float

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance;
@ -754,6 +754,20 @@ class FinanceFormulas
return log(2) / log(1 + $r);
}
/**
* Get rate to dobule
*
* @param float $t Time in which to double investment
*
* @return float
*
* @since 1.0.0
*/
public static function getDoublingRate(float $t) : float
{
return exp(log(2) / $t) - 1;
}
/**
* Doubling Time - Continuous Compounding
*

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class AR

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class ARCH

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class ARFIMA

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
use phpOMS\Math\Statistic\Average;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class ARMA

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing;
@ -35,7 +35,7 @@ class ExponentialSmoothing
public function __construct(array $data)
{
$this->data = $data;
$this->data = $data;
}
public function getRMSE() : float
@ -67,48 +67,48 @@ class ExponentialSmoothing
{
$this->rmse = PHP_INT_MAX;
if($trendType === TrendType::ALL || $seasonalType === SeasonalType::ALL) {
if ($trendType === TrendType::ALL || $seasonalType === SeasonalType::ALL) {
$trends = [$trendType];
if($trendType === TrendType::ALL) {
if ($trendType === TrendType::ALL) {
$trends = [TrendType::NONE, TrendType::ADDITIVE, TrendType::MULTIPLICATIVE];
}
$seasonals = [$seasonalType];
if($seasonalType === SeasonalType::ALL) {
if ($seasonalType === SeasonalType::ALL) {
$seasonals = [SeasonalType::NONE, SeasonalType::ADDITIVE, SeasonalType::MULTIPLICATIVE];
}
$forecast = [];
$bestError = PHP_INT_MAX;
foreach($trends as $trend) {
foreach($seasonals as $seasonal) {
foreach ($trends as $trend) {
foreach ($seasonals as $seasonal) {
$tempForecast = $this->getForecast($future, $trend, $seasonal, $cycle, $damping);
if ($this->rmse < $bestError) {
$bestError = $this->rmse;
$forecast = $tempForecast;
$forecast = $tempForecast;
}
}
}
return $forecast;
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::NONE) {
} elseif ($trendType === TrendType::NONE && $seasonalType === SeasonalType::NONE) {
return $this->getNoneNone($future);
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::ADDITIVE) {
} elseif ($trendType === TrendType::NONE && $seasonalType === SeasonalType::ADDITIVE) {
return $this->getNoneAdditive($future, $cycle);
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
} elseif ($trendType === TrendType::NONE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
return $this->getNoneMultiplicative($future, $cycle);
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::NONE) {
} elseif ($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::NONE) {
return $this->getAdditiveNone($future, $damping);
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::ADDITIVE) {
} elseif ($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::ADDITIVE) {
return $this->getAdditiveAdditive($future, $cycle, $damping);
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
} elseif ($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
return $this->getAdditiveMultiplicative($future, $cycle, $damping);
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::NONE) {
} elseif ($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::NONE) {
return $this->getMultiplicativeNone($future, $damping);
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::ADDITIVE) {
} elseif ($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::ADDITIVE) {
return $this->getMultiplicativeAdditive($future, $cycle, $damping);
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
} elseif ($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
return $this->getMultiplicativeMultiplicative($future, $cycle, $damping);
}
@ -117,12 +117,12 @@ class ExponentialSmoothing
private function dampingSum(float $damping, int $length) : float
{
if(abs($damping - 1) < 0.001) {
if (abs($damping - 1) < 0.001) {
return $length;
}
$sum = 0;
for($i = 0; $i < $length; $i++) {
for ($i = 0; $i < $length; $i++) {
$sum += pow($damping, $i);
}
@ -137,14 +137,14 @@ class ExponentialSmoothing
$alpha = 0.00;
while ($alpha < 1) {
$error = [];
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * $level[$i-1];
for ($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) + (1 - $alpha) * $level[$i - 1];
$tempForecast[$i] = $level[$i];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
@ -172,27 +172,27 @@ class ExponentialSmoothing
$forecast = [];
$seasonal = [];
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i-1] - $level[0];
for ($i = 1; $i < $cycle + 1; $i++) {
$seasonal[$i] = $this->data[$i - 1] - $level[0];
}
$alpha = 0.00;
while ($alpha < 1) {
$gamma = 0.00;
while($gamma < 1) {
while ($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
for ($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i - 1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * $level[$i-1];
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) - $seasonal[$i]) + (1 - $alpha) * $level[$i - 1];
$seasonal[$i + $cycle] = $gamma_ * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) - $level[$i - 1]) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] + $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$tempForecast[$i] = $level[$i] + $seasonal[$i + $hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
@ -223,7 +223,7 @@ class ExponentialSmoothing
$forecast = [];
$seasonal = [];
for($i = 1; $i < $cycle+1; $i++) {
for ($i = 1; $i < $cycle + 1; $i++) {
$seasonal[$i] = $this->data[$i] / $level[0];
}
@ -231,19 +231,19 @@ class ExponentialSmoothing
while ($alpha < 1) {
$gamma = 0.00;
while($gamma < 1) {
while ($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
for ($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i - 1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $seasonal[$i]) + (1 - $alpha) * $level[$i-1];
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) / $seasonal[$i]) + (1 - $alpha) * $level[$i - 1];
$seasonal[$i + $cycle] = $gamma_ * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) / $level[$i - 1]) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] + $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$tempForecast[$i] = $level[$i] + $seasonal[$i + $hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
@ -278,16 +278,16 @@ class ExponentialSmoothing
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
$error = [];
while ($beta < 1) {
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
for ($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) + (1 - $alpha) * ($level[$i - 1] + $damping * $trend[$i - 1]);
$trend[$i] = $beta * ($level[$i] - $level[$i - 1]) + (1 - $beta) * $damping * $trend[$i - 1];
$tempForecast[$i] = $level[$i] + $this->dampingSum($damping, $i) * $trend[$i];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
@ -320,37 +320,37 @@ class ExponentialSmoothing
$seasonal = [];
$sum = 0;
for($i = 1; $i < $cycle+1; $i++) {
for ($i = 1; $i < $cycle + 1; $i++) {
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
}
$trend[0] *= $sum;
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i-1] - $level[0];
for ($i = 1; $i < $cycle + 1; $i++) {
$seasonal[$i] = $this->data[$i - 1] - $level[0];
}
$alpha = 0.00;
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
while ($beta < 1) {
$gamma = 0.00;
while($gamma < 1) {
while ($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
for ($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i - 1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) - $seasonal[$i]) + (1 - $alpha) * ($level[$i - 1] + $damping * $trend[$i - 1]);
$trend[$i] = $beta * ($level[$i] - $level[$i - 1]) + (1 - $beta) * $damping * $trend[$i - 1];
$seasonal[$i + $cycle] = $gamma_ * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) - $level[$i - 1]) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] + $this->dampingSum($damping, $i) * $trend[$i] + $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$tempForecast[$i] = $level[$i] + $this->dampingSum($damping, $i) * $trend[$i] + $seasonal[$i + $hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
@ -387,13 +387,13 @@ class ExponentialSmoothing
$gamma_ = $gamma * (1 - $alpha);
$sum = 0;
for($i = 1; $i < $cycle+1; $i++) {
for ($i = 1; $i < $cycle + 1; $i++) {
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
}
$trend[0] *= $sum;
for($i = 1; $i < $cycle+1; $i++) {
for ($i = 1; $i < $cycle + 1; $i++) {
$seasonal[$i] = $this->data[$i] / $level[0];
}
@ -401,23 +401,23 @@ class ExponentialSmoothing
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
while ($beta < 1) {
$gamma = 0.00;
while($gamma < 1) {
while ($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
for ($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i - 1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $seasonal[$i]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
$seasonal[$i+$cycle] = $gamma_*($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / ($level[$i-1] + $damping * $trend[$i-1]) + (1 - $gamma_) * $seasonal[$i];
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) / $seasonal[$i]) + (1 - $alpha) * ($level[$i - 1] + $damping * $trend[$i - 1]);
$trend[$i] = $beta * ($level[$i] - $level[$i - 1]) + (1 - $beta) * $damping * $trend[$i - 1];
$seasonal[$i + $cycle] = $gamma_ * ($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) / ($level[$i - 1] + $damping * $trend[$i - 1]) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[] = ($level[$i] + $this->dampingSum($damping, $i) * $trend[$i-1]) * $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$tempForecast[] = ($level[$i] + $this->dampingSum($damping, $i) * $trend[$i - 1]) * $seasonal[$i + $hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
@ -455,16 +455,16 @@ class ExponentialSmoothing
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
$error = [];
while ($beta < 1) {
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * $level[$i-1] * pow($trend[$i-1], $damping);
$trend[$i] = $beta * ($level[$i] / $level[$i-1]) + (1 - $beta) * pow($trend[$i-1], $damping);
for ($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) + (1 - $alpha) * $level[$i - 1] * pow($trend[$i - 1], $damping);
$trend[$i] = $beta * ($level[$i] / $level[$i - 1]) + (1 - $beta) * pow($trend[$i - 1], $damping);
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i));
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
@ -496,37 +496,37 @@ class ExponentialSmoothing
$seasonal = [];
$sum = 0;
for($i = 1; $i < $cycle+1; $i++) {
for ($i = 1; $i < $cycle + 1; $i++) {
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
}
$trend[0] *= $sum;
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i-1] - $level[0];
for ($i = 1; $i < $cycle + 1; $i++) {
$seasonal[$i] = $this->data[$i - 1] - $level[0];
}
$alpha = 0.00;
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
while ($beta < 1) {
$gamma = 0.00;
while($gamma < 1) {
while ($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
for ($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i - 1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * $level[$i-1] * pow($trend[$i-1], $damping);
$trend[$i] = $beta * ($level[$i] / $level[$i-1]) + (1 - $beta) * pow($trend[$i-1], $damping);
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1] * pow($trend[$i-1], $damping)) + (1 - $gamma_) * $seasonal[$i];
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) - $seasonal[$i]) + (1 - $alpha) * $level[$i - 1] * pow($trend[$i - 1], $damping);
$trend[$i] = $beta * ($level[$i] / $level[$i - 1]) + (1 - $beta) * pow($trend[$i - 1], $damping);
$seasonal[$i + $cycle] = $gamma_ * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) - $level[$i - 1] * pow($trend[$i - 1], $damping)) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i)) + $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i)) + $seasonal[$i + $hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
@ -562,13 +562,13 @@ class ExponentialSmoothing
$seasonal = [];
$sum = 0;
for($i = 1; $i < $cycle+1; $i++) {
for ($i = 1; $i < $cycle + 1; $i++) {
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
}
$trend[0] *= $sum;
for($i = 1; $i < $cycle+1; $i++) {
for ($i = 1; $i < $cycle + 1; $i++) {
$seasonal[$i] = $this->data[$i] / $level[0];
}
@ -576,23 +576,23 @@ class ExponentialSmoothing
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
while ($beta < 1) {
$gamma = 0.00;
while($gamma < 1) {
while ($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
for ($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i - 1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $seasonal[$i]) + (1 - $alpha) * $level[$i-1] * pow($trend[$i-1], $damping);
$trend[$i] = $beta * ($level[$i] / $level[$i-1]) + (1 - $beta) * pow($trend[$i-1], $damping);
$seasonal[$i+$cycle] = $gamma_*($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / ($level[$i-1] * pow($trend[$i-1], $damping)) + (1 - $gamma_) * $seasonal[$i];
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) / $seasonal[$i]) + (1 - $alpha) * $level[$i - 1] * pow($trend[$i - 1], $damping);
$trend[$i] = $beta * ($level[$i] / $level[$i - 1]) + (1 - $beta) * pow($trend[$i - 1], $damping);
$seasonal[$i + $cycle] = $gamma_ * ($i < $dataLength - $future ? $this->data[$i - 1] : $tempForecast[$i - 1]) / ($level[$i - 1] * pow($trend[$i - 1], $damping)) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i)) * $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i)) * $seasonal[$i + $hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class GARCH

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class MA

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class NAR

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class NMA

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;
class SARIMA

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Marketing;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Marketing;
@ -72,10 +72,10 @@ class NetPromoterScore {
$passives = 0;
$detractors = 0;
foreach($this->scores as $score) {
if($score > 8) {
foreach ($this->scores as $score) {
if ($score > 8) {
$promoters++;
} elseif($score > 6) {
} elseif ($score > 6) {
$passives++;
} else {
$detractors++;
@ -99,8 +99,8 @@ class NetPromoterScore {
public function countDetractors() : int
{
$count = 0;
foreach($this->scores as $score) {
if($score < 7) {
foreach ($this->scores as $score) {
if ($score < 7) {
$count++;
}
}
@ -120,8 +120,8 @@ class NetPromoterScore {
public function countPassives() : int
{
$count = 0;
foreach($this->scores as $score) {
if($score > 6 && $score < 9) {
foreach ($this->scores as $score) {
if ($score > 6 && $score < 9) {
$count++;
}
}
@ -141,8 +141,8 @@ class NetPromoterScore {
public function countPromoters() : int
{
$count = 0;
foreach($this->scores as $score) {
if($score > 8) {
foreach ($this->scores as $score) {
if ($score > 8) {
$count++;
}
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Programming;
@ -42,17 +42,16 @@ class Metrics {
*/
public static function abcScore(int $a, int $b, int $c) : int
{
return (int) sqrt($a*$a+$b*$b+$c*$c);
return (int) sqrt($a * $a + $b * $b + $c * $c);
}
/**
* Calculate the C.R.A.P score
*
* @latex r = \sqrt{a^{2} + b^{2} + c^{2}}
* @latex r = com^{2} \times (1 - cov)^{3} + com
*
* @param int $a Assignments
* @param int $b Branches
* @param int $c Conditionals
* @param int $complexity Complexity
* @param int $coverage Coverage
*
* @return int
*

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Sales;
@ -44,8 +44,8 @@ class MarketShareEstimation {
public static function getRankFromMarketShare(int $participants, float $marketShare, float $modifier = 1.0) : int
{
$sum = 0.0;
for($i = 0; $i < $participants; $i++) {
$sum += 1 / pow($i+1, $modifier);
for ($i = 0; $i < $participants; $i++) {
$sum += 1 / pow($i + 1, $modifier);
}
return (int) round(pow(1 / ($marketShare * $sum), 1 / $modifier));
@ -67,8 +67,8 @@ class MarketShareEstimation {
public static function getMarketShareFromRank(int $participants, int $rank, float $modifier = 1.0) : float
{
$sum = 0.0;
for($i = 0; $i < $participants; $i++) {
$sum += 1 / pow($i+1, $modifier);
for ($i = 0; $i < $participants; $i++) {
$sum += 1 / pow($i + 1, $modifier);
}
return (1 / pow($rank, $modifier)) / $sum;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Config;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Config;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Config;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Console;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Contract;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Contract;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;
@ -39,7 +39,7 @@ class CachePool implements OptionsInterface
/**
* MemCache instance.
*
* @var \phpOMS\DataStorage\Cache\CacheInterface
* @var \phpOMS\DataStorage\Cache\CacheInterface[]
* @since 1.0.0
*/
private $pool = null;
@ -106,11 +106,11 @@ class CachePool implements OptionsInterface
*/
public function get(string $key = '') /* : ?CacheInterface */
{
if((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) {
if ((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) {
return null;
}
if(empty($key)) {
if (empty($key)) {
return reset($this->pool);
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;
@ -108,7 +108,7 @@ class FileCache implements CacheInterface
*/
public function setStatus(int $status) /* : void */
{
if(!CacheStatus::isValidValue($status)) {
if (!CacheStatus::isValidValue($status)) {
throw new InvalidEnumValue($status);
}
@ -142,7 +142,7 @@ class FileCache implements CacheInterface
*/
public function set($key, $value, int $expire = -1) /* : void */
{
if($this->status !== CacheStatus::ACTIVE) {
if ($this->status !== CacheStatus::ACTIVE) {
return false;
}
@ -159,7 +159,7 @@ class FileCache implements CacheInterface
*/
public function add($key, $value, int $expire = -1) : bool
{
if($this->status !== CacheStatus::ACTIVE) {
if ($this->status !== CacheStatus::ACTIVE) {
return false;
}
@ -262,9 +262,9 @@ class FileCache implements CacheInterface
private function getExpire(string $raw) : int
{
$expireStart = strpos($raw, self::DELIM);
$expireEnd = strpos($raw, self::DELIM, $expireStart+1);
$expireEnd = strpos($raw, self::DELIM, $expireStart + 1);
return (int) substr($raw, $expireStart+1, $expireEnd - ($expireStart+1));
return (int) substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
}
/**
@ -272,14 +272,14 @@ class FileCache implements CacheInterface
*/
public function get($key, int $expire = -1)
{
if($this->status !== CacheStatus::ACTIVE) {
if ($this->status !== CacheStatus::ACTIVE) {
return null;
}
$name = File::sanitize($key, self::SANITIZE);
$path = $this->cachePath . '/' . trim($name, '/') . '.cache';
if(!File::exists($path)) {
if (!File::exists($path)) {
return null;
}
@ -294,8 +294,8 @@ class FileCache implements CacheInterface
$type = $raw[0];
$expireStart = strpos($raw, self::DELIM);
$expireEnd = strpos($raw, self::DELIM, $expireStart+1);
$cacheExpire = substr($raw, $expireStart+1, $expireEnd - ($expireStart+1));
$expireEnd = strpos($raw, self::DELIM, $expireStart + 1);
$cacheExpire = substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
if ($cacheExpire >= 0 && $created + $cacheExpire < $now) {
$this->delete($key);
@ -324,7 +324,7 @@ class FileCache implements CacheInterface
case CacheType::_SERIALIZABLE:
case CacheType::_JSONSERIALIZABLE:
$namespaceStart = strpos($raw, self::DELIM, $expireEnd);
$namespaceEnd = strpos($raw, self::DELIM, $namespaceStart+1);
$namespaceEnd = strpos($raw, self::DELIM, $namespaceStart + 1);
$namespace = substr($raw, $namespaceStart, $namespaceEnd);
$value = $namespace::unserialize(substr($raw, $namespaceEnd + 1));
@ -339,7 +339,7 @@ class FileCache implements CacheInterface
*/
public function delete($key, int $expire = -1) : bool
{
if($this->status !== CacheStatus::ACTIVE) {
if ($this->status !== CacheStatus::ACTIVE) {
return false;
}
@ -357,8 +357,8 @@ class FileCache implements CacheInterface
$now = time();
$raw = file_get_contents($path);
$expireStart = strpos($raw, self::DELIM);
$expireEnd = strpos($raw, self::DELIM, $expireStart+1);
$cacheExpire = substr($raw, $expireStart+1, $expireEnd - ($expireStart+1));
$expireEnd = strpos($raw, self::DELIM, $expireStart + 1);
$cacheExpire = substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
if ($cacheExpire >= 0 && $created + $cacheExpire > $now) {
File::delete($path);
@ -402,7 +402,7 @@ class FileCache implements CacheInterface
*/
public function replace($key, $value, int $expire = -1) : bool
{
if($this->status !== CacheStatus::ACTIVE) {
if ($this->status !== CacheStatus::ACTIVE) {
return false;
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;
@ -50,7 +50,7 @@ class MemCache implements CacheInterface
*/
public function __construct()
{
$this->memc = new self();
$this->memc = null;
}
/**

View File

@ -0,0 +1,178 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;
/**
* Memcache class.
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class MemCached implements CacheInterface
{
/**
* Memcache instance.
*
* @var \Memcache
* @since 1.0.0
*/
private $memc = null;
/**
* Only cache if data is larger than threshold (0-100).
*
* @var int
* @since 1.0.0
*/
private $threshold = 10;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->memc = null;
}
/**
* Adding server to server pool.
*
* @param mixed $data Server data array
*
* @return void
*
* @since 1.0.0
*/
public function addServer($data)
{
$this->memc->addServer($data['host'], $data['port'], $data['timeout']);
}
/**
* {@inheritdoc}
*/
public function set($key, $value, int $expire = -1) /* : void */
{
$this->memc->set($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function add($key, $value, int $expire = -1) : bool
{
return $this->memc->add($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function get($key, int $expire = -1)
{
return $this->memc->get($key);
}
/**
* {@inheritdoc}
*/
public function delete($key, int $expire = -1) : bool
{
$this->memc->delete($key);
}
/**
* {@inheritdoc}
*/
public function flush(int $expire = 0) : bool
{
$this->memc->flush();
return true;
}
/**
* {@inheritdoc}
*/
public function flushAll() : bool
{
$this->memc->flush();
return true;
}
/**
* {@inheritdoc}
*/
public function replace($key, $value, int $expire = -1) : bool
{
$this->memc->replace($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function stats() : array
{
/** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
return $this->memc->getExtendedStats();
}
/**
* {@inheritdoc}
*/
public function getThreshold() : int
{
return $this->threshold;
}
/**
* {@inheritdoc}
*/
public function setStatus(int $status) /* : void */
{
$this->status = $status;
}
/**
* Destructor.
*
* @since 1.0.0
*/
public function __destruct()
{
$this->close();
}
/**
* Closing cache.
*
* @since 1.0.0
*/
public function close()
{
if ($this->memc !== null) {
$this->memc->close();
$this->memc = null;
}
}
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cookie;
@ -122,12 +122,12 @@ class CookieJar
*/
public function delete(string $id) : bool
{
if($this->remove($id)) {
if ($this->remove($id)) {
if (self::$isLocked) {
throw new LockException('CookieJar');
}
if(!headers_sent()) {
if (!headers_sent()) {
setcookie($id, '', time() - 3600);
return true;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Connection;
@ -65,15 +65,15 @@ abstract class ConnectionAbstract implements ConnectionInterface
/**
* Database type.
*
* @var \phpOMS\DataStorage\Database\DatabaseType
* @var string
* @since 1.0.0
*/
protected $type = null;
protected $type = 'undefined';
/**
* Database status.
*
* @var DatabaseStatus
* @var int
* @since 1.0.0
*/
protected $status = DatabaseStatus::CLOSED;
@ -89,7 +89,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
/**
* Database grammar.
*
* @var Grammar
* @var SchemaGrammar
* @since 1.0.0
*/
protected $schemaGrammar = null;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Connection;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Connection;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Connection;
@ -60,32 +60,11 @@ class MysqlConnection extends ConnectionAbstract
{
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
if(!isset($this->dbdata['db'])) {
throw new InvalidConnectionConfigException('db');
}
if(!isset($this->dbdata['host'])) {
throw new InvalidConnectionConfigException('host');
}
if(!isset($this->dbdata['port'])) {
throw new InvalidConnectionConfigException('port');
}
if(!isset($this->dbdata['database'])) {
throw new InvalidConnectionConfigException('database');
}
if(!isset($this->dbdata['login'])) {
throw new InvalidConnectionConfigException('login');
}
if(!isset($this->dbdata['password'])) {
throw new InvalidConnectionConfigException('password');
if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])) {
throw new InvalidConnectionConfigException(json_encode($this->dbdata));
}
$this->close();
$this->prefix = $dbdata['prefix'] ?? '';
try {

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Connection;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Connection;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Connection;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;
@ -149,7 +149,7 @@ class DataMapperAbstract implements DataMapperInterface
/**
* Highest mapper to know when to clear initialized objects
*
* @var DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static $parentMapper = null;
@ -269,8 +269,6 @@ class DataMapperAbstract implements DataMapperInterface
// todo: how to handle with of parent objects/extends/relations
self::$fields = $objects;
//return __CLASS__;
}
/**
@ -304,7 +302,7 @@ class DataMapperAbstract implements DataMapperInterface
];
// clear parent and objects
if(static::class === self::$parentMapper) {
if (static::class === self::$parentMapper) {
self::$initObjects = [];
self::$parentMapper = null;
}
@ -325,8 +323,8 @@ class DataMapperAbstract implements DataMapperInterface
$query = static::getQuery();
foreach(static::$columns as $col) {
if(isset($col['autocomplete']) && $col['autocomplete']) {
foreach (static::$columns as $col) {
if (isset($col['autocomplete']) && $col['autocomplete']) {
$query->where(static::$table . '.' . $col['name'], 'LIKE', '%' . $search . '%', 'OR');
}
}
@ -348,7 +346,7 @@ class DataMapperAbstract implements DataMapperInterface
{
self::extend(__CLASS__);
if($obj === null ||
if ($obj === null ||
(is_object($obj) && strpos($className = get_class($obj), '\Null') !== false)
) {
return null;
@ -379,7 +377,7 @@ class DataMapperAbstract implements DataMapperInterface
{
self::extend(__CLASS__);
$objId = self::createModelArray($obj);
$objId = self::createModelArray($obj);
settype($objId, static::$columns[static::$primaryField]['type']);
$obj[static::$columns[static::$primaryField]['internal']] = $objId;
@ -507,7 +505,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
private static function getObjectId($obj, \ReflectionClass $reflectionClass = null)
{
$reflectionClass = $reflectionClass ?? new \ReflectionClass(get_class($obj));
$reflectionClass = $reflectionClass ?? new \ReflectionClass($obj);
$reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
if (!($isPublic = $reflectionProperty->isPublic())) {
@ -596,7 +594,7 @@ class DataMapperAbstract implements DataMapperInterface
}
if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value));
$relReflectionClass = new \ReflectionClass($value);
}
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
@ -931,7 +929,7 @@ class DataMapperAbstract implements DataMapperInterface
}
if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value));
$relReflectionClass = new \ReflectionClass($value);
}
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
@ -992,11 +990,11 @@ class DataMapperAbstract implements DataMapperInterface
$removes = array_diff($many[$propertyName], array_keys($objsIds[$propertyName] ?? []));
$adds = array_diff(array_keys($objsIds[$propertyName] ?? []), $many[$propertyName]);
if(!empty($removes)) {
if (!empty($removes)) {
self::deleteRelationTable($propertyName, $removes, $objId);
}
if(!empty($adds)) {
if (!empty($adds)) {
self::createRelationTable($propertyName, $adds, $objId);
}
}
@ -1162,11 +1160,11 @@ class DataMapperAbstract implements DataMapperInterface
{
self::extend(__CLASS__);
$reflectionClass = new \ReflectionClass(get_class($obj));
$reflectionClass = new \ReflectionClass($obj);
$objId = self::getObjectId($obj, $reflectionClass);
$update = true;
if(empty($objId)) {
if (empty($objId)) {
$update = false;
self::create($obj, $relations);
}
@ -1175,7 +1173,7 @@ class DataMapperAbstract implements DataMapperInterface
self::updateHasMany($reflectionClass, $obj, $objId);
}
if($update) {
if ($update) {
self::updateModel($obj, $objId, $reflectionClass);
}
@ -1229,14 +1227,14 @@ class DataMapperAbstract implements DataMapperInterface
}
if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value));
$relReflectionClass = new \ReflectionClass($value);
}
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
// already in db
if (!empty($primaryKey)) {
if($relations === RelationType::ALL) {
if ($relations === RelationType::ALL) {
$objsIds[$key] = $mapper::delete($value);
} else {
$objsIds[$key] = $primaryKey;
@ -1324,7 +1322,7 @@ class DataMapperAbstract implements DataMapperInterface
$properties = $reflectionClass->getProperties();
if($relations === RelationType::ALL) {
if ($relations === RelationType::ALL) {
foreach ($properties as $property) {
$propertyName = $property->getName();
@ -1372,10 +1370,10 @@ class DataMapperAbstract implements DataMapperInterface
{
self::extend(__CLASS__);
$reflectionClass = new \ReflectionClass(get_class($obj));
$reflectionClass = new \ReflectionClass($obj);
$objId = self::getObjectId($obj, $reflectionClass);
if(empty($objId)) {
if (empty($objId)) {
return null;
}
@ -1478,7 +1476,7 @@ class DataMapperAbstract implements DataMapperInterface
public static function populateManyToMany(array $result, &$obj) /* : void */
{
// todo: maybe pass reflectionClass as optional parameter for performance increase
$reflectionClass = new \ReflectionClass(get_class($obj));
$reflectionClass = new \ReflectionClass($obj);
foreach ($result as $member => $values) {
if (!empty($values) && $reflectionClass->hasProperty($member)) {
@ -1487,7 +1485,7 @@ class DataMapperAbstract implements DataMapperInterface
$reflectionProperty = $reflectionClass->getProperty($member);
$values = array_diff($values, array_keys(self::$initObjects[$mapper] ?? []));
if(empty($values)) {
if (empty($values)) {
continue;
}
@ -1523,7 +1521,7 @@ class DataMapperAbstract implements DataMapperInterface
$mapper = static::$hasMany[$member]['mapper'];
$values = array_diff($values, array_keys(self::$initObjects[$mapper] ?? []));
if(empty($values)) {
if (empty($values)) {
continue;
}
@ -1546,7 +1544,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function populateHasOne(&$obj) /* : void */
{
$reflectionClass = new \ReflectionClass(get_class($obj));
$reflectionClass = new \ReflectionClass($obj);
foreach (static::$hasOne as $member => $one) {
// todo: is that if necessary? performance is suffering for sure!
@ -1560,7 +1558,7 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */
$mapper = static::$hasOne[$member]['mapper'];
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
if (self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
$value = self::$initObjects[$mapper][$id];
} else {
$value = $mapper::get($reflectionProperty->getValue($obj));
@ -1592,7 +1590,7 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */
$mapper = static::$hasOne[$member]['mapper'];
if(self::isInitialized($mapper, $obj['member'])) {
if (self::isInitialized($mapper, $obj['member'])) {
$value = self::$initObjects[$mapper][$obj['member']];
} else {
$value = $mapper::getArray($obj[$member]);
@ -1615,7 +1613,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function populateOwnsOne(&$obj) /* : void */
{
$reflectionClass = new \ReflectionClass(get_class($obj));
$reflectionClass = new \ReflectionClass($obj);
foreach (static::$ownsOne as $member => $one) {
// todo: is that if necessary? performance is suffering for sure!
@ -1629,7 +1627,7 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */
$mapper = static::$ownsOne[$member]['mapper'];
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
if (self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
$value = self::$initObjects[$mapper][$id];
} else {
$value = $mapper::get($reflectionProperty->getValue($obj));
@ -1661,7 +1659,7 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */
$mapper = static::$ownsOne[$member]['mapper'];
if(self::isInitialized($mapper, $obj[$member])) {
if (self::isInitialized($mapper, $obj[$member])) {
$value = self::$initObjects[$mapper][$obj[$member]];
} else {
$value = $mapper::getArray($obj[$member]);
@ -1684,7 +1682,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function populateBelongsTo(&$obj) /* : void */
{
$reflectionClass = new \ReflectionClass(get_class($obj));
$reflectionClass = new \ReflectionClass($obj);
foreach (static::$belongsTo as $member => $one) {
// todo: is that if necessary? performance is suffering for sure!
@ -1698,7 +1696,7 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */
$mapper = static::$belongsTo[$member]['mapper'];
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
if (self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
$value = self::$initObjects[$mapper][$id];
} else {
$value = $mapper::get($reflectionProperty->getValue($obj));
@ -1730,7 +1728,7 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */
$mapper = static::$belongsTo[$member]['mapper'];
if(self::isInitialized($mapper, $obj[$member])) {
if (self::isInitialized($mapper, $obj[$member])) {
$value = self::$initObjects[$mapper][$obj[$member]];
} else {
$value = $mapper::get($obj[$member]);
@ -1754,7 +1752,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function populateAbstract(array $result, $obj)
{
$reflectionClass = new \ReflectionClass(get_class($obj));
$reflectionClass = new \ReflectionClass($obj);
foreach ($result as $column => $value) {
if (isset(static::$columns[$column]['internal']) /* && $reflectionClass->hasProperty(static::$columns[$column]['internal']) */) {
@ -1765,7 +1763,7 @@ class DataMapperAbstract implements DataMapperInterface
}
if (in_array(static::$columns[$column]['type'], ['string', 'int', 'float', 'bool'])) {
if($value !== null || $reflectionProperty->getValue($obj) !== null) {
if ($value !== null || $reflectionProperty->getValue($obj) !== null) {
settype($value, static::$columns[$column]['type']);
}
@ -1838,7 +1836,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null)
{
if(!isset(self::$parentMapper)) {
if (!isset(self::$parentMapper)) {
self::setUpParentMapper();
}
@ -1851,7 +1849,7 @@ class DataMapperAbstract implements DataMapperInterface
$toFill = null;
foreach ($primaryKey as $key => $value) {
if(self::isInitialized(static::class, $value)) {
if (self::isInitialized(static::class, $value)) {
continue;
}
@ -1862,7 +1860,7 @@ class DataMapperAbstract implements DataMapperInterface
$obj[$value] = self::populate(self::getRaw($value), $toFill);
if(method_exists($obj[$value], 'initialize')) {
if (method_exists($obj[$value], 'initialize')) {
$obj[$value]->initialize();
}
@ -1874,9 +1872,9 @@ class DataMapperAbstract implements DataMapperInterface
$countResulsts = count($obj);
if($countResulsts === 0) {
if ($countResulsts === 0) {
return self::getNullModelObj();
} elseif($countResulsts === 1) {
} elseif ($countResulsts === 1) {
return reset($obj);
}
@ -1907,7 +1905,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function getArray($primaryKey, int $relations = RelationType::ALL) : array
{
if(!isset(self::$parentMapper)) {
if (!isset(self::$parentMapper)) {
self::setUpParentMapper();
}
@ -1917,7 +1915,7 @@ class DataMapperAbstract implements DataMapperInterface
$obj = [];
foreach ($primaryKey as $key => $value) {
if(self::isInitialized(static::class, $value)) {
if (self::isInitialized(static::class, $value)) {
continue;
}
@ -1946,7 +1944,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function getFor($refKey, string $ref, int $relations = RelationType::ALL, $fill = null)
{
if(!isset(self::$parentMapper)) {
if (!isset(self::$parentMapper)) {
self::setUpParentMapper();
}
@ -1958,7 +1956,7 @@ class DataMapperAbstract implements DataMapperInterface
foreach ($refKey as $key => $value) {
$toLoad = [];
if(isset(static::$hasMany[$ref]) && static::$hasMany[$ref]['src'] !== null) {
if (isset(static::$hasMany[$ref]) && static::$hasMany[$ref]['src'] !== null) {
$toLoad = self::getHasManyPrimaryKeys($value, $ref);
} else {
$toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($ref));
@ -1969,9 +1967,9 @@ class DataMapperAbstract implements DataMapperInterface
$countResulsts = count($obj);
if($countResulsts === 0) {
if ($countResulsts === 0) {
return self::getNullModelObj();
} elseif($countResulsts === 1) {
} elseif ($countResulsts === 1) {
return reset($obj);
}
@ -1992,7 +1990,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function getForArray($refKey, string $ref, int $relations = RelationType::ALL, $fill = null)
{
if(!isset(self::$parentMapper)) {
if (!isset(self::$parentMapper)) {
self::setUpParentMapper();
}
@ -2004,7 +2002,7 @@ class DataMapperAbstract implements DataMapperInterface
foreach ($refKey as $key => $value) {
$toLoad = [];
if(isset(static::$hasMany[$ref]) && static::$hasMany[$ref]['src'] !== null) {
if (isset(static::$hasMany[$ref]) && static::$hasMany[$ref]['src'] !== null) {
$toLoad = self::getHasManyPrimaryKeys($value, $ref);
} else {
$toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($ref));
@ -2028,7 +2026,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function getAll(int $relations = RelationType::ALL, string $lang = '') : array
{
if(!isset(self::$parentMapper)) {
if (!isset(self::$parentMapper)) {
self::setUpParentMapper();
}
@ -2051,7 +2049,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function getAllArray(int $relations = RelationType::ALL, string $lang = '') : array
{
if(!isset(self::$parentMapper)) {
if (!isset(self::$parentMapper)) {
self::setUpParentMapper();
}
@ -2492,7 +2490,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
private static function addInitialized(string $mapper, $id, $obj = null) /* : void */
{
if(!isset(self::$initObjects[$mapper])) {
if (!isset(self::$initObjects[$mapper])) {
self::$initObjects[$mapper] = [];
}
@ -2564,8 +2562,8 @@ class DataMapperAbstract implements DataMapperInterface
*/
private static function getColumnByMember(string $name) : string
{
foreach(static::$columns as $cName => $column) {
if($column['internal'] === $name) {
foreach (static::$columns as $cName => $column) {
if ($column['internal'] === $name) {
return $cName;
}
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;
@ -283,7 +283,7 @@ class DataMapperBaseAbstract
];
// clear parent and objects
if(static::class === self::$parentMapper) {
if (static::class === self::$parentMapper) {
self::$initObjects = [];
self::$parentMapper = null;
}
@ -426,8 +426,8 @@ class DataMapperBaseAbstract
private static function getColumnByMember(string $name) : string
{
foreach(static::$columns as $cName => $column) {
if($column['internal'] === $name) {
foreach (static::$columns as $cName => $column) {
if ($column['internal'] === $name) {
return $cName;
}
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;
@ -79,11 +79,11 @@ class DatabasePool
*/
public function get(string $key = '') /* : ?ConnectionAbstract */
{
if((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) {
if ((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) {
return null;
}
if(empty($key)) {
if (empty($key)) {
return reset($this->pool);
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Exception;
@ -31,12 +31,12 @@ class InvalidConnectionConfigException extends \InvalidArgumentException
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
* @param \Exception $previous Previous exception
*
* @since 1.0.0
*/
public function __construct(string $message = '', int $code = 0, \Exception $previous = null)
{
parent::__construct('Missing config value for "'. $message .'".', $code, $previous);
parent::__construct('Missing config value for "' . $message . '".', $code, $previous);
}
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Exception;
@ -31,13 +31,13 @@ class InvalidMapperException extends \RuntimeException
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
* @param \Exception $previous Previous exception
*
* @since 1.0.0
*/
public function __construct(string $message = '', int $code = 0, \Exception $previous = null)
{
if($message === '') {
if ($message === '') {
parent::__construct('Empty mapper.', $code, $previous);
} else {
parent::__construct('Mapper "' . $message . '" is invalid.', $code, $previous);

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;
@ -170,7 +170,7 @@ abstract class GrammarAbstract
foreach ($elements as $key => $element) {
if (is_string($element) && $element !== '*') {
if(strpos($element, '.') === false) {
if (strpos($element, '.') === false) {
$prefix = '';
}
@ -237,8 +237,8 @@ abstract class GrammarAbstract
// todo: this is a bad way to handle select count(*) which doesn't need a prefix. Maybe remove prefixes in total?
$identifier = $this->systemIdentifier;
foreach($this->specialKeywords as $keyword) {
if($keyword === '' || strrpos($system, $keyword, -strlen($system)) !== false) {
foreach ($this->specialKeywords as $keyword) {
if ($keyword === '' || strrpos($system, $keyword, -strlen($system)) !== false) {
$prefix = '';
$identifier = '';
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query;
@ -152,7 +152,7 @@ class Builder extends BuilderAbstract
/**
* Offset.
*
* @var array
* @var int
* @since 1.0.0
*/
public $offset = null;
@ -184,7 +184,7 @@ class Builder extends BuilderAbstract
/**
* Raw query.
*
* @var bool
* @var string
* @since 1.0.0
*/
public $raw = '';
@ -356,17 +356,8 @@ class Builder extends BuilderAbstract
*/
public function raw(string $raw) : Builder
{
if($this->isReadOnly) {
$test = strtolower($raw);
if(strpos($test, 'insert') !== false
|| strpos($test, 'update') !== false
|| strpos($test, 'drop') !== false
|| strpos($test, 'delete') !== false
|| strpos($test, 'create') !== false
|| strpos($test, 'alter') !== false) {
throw new \Exception();
}
if (!$this->isValidReadOnly($raw)) {
throw new \Exception();
}
$this->type = QueryType::RAW;
@ -375,6 +366,37 @@ class Builder extends BuilderAbstract
return $this;
}
/**
* Tests if a string contains a non read only component in case the builder is read only.
* If the builder is not read only it will always return true
*
* @param string $raw Raw query
*
* @return bool
*
* @since 1.0.0
*/
private function isValidReadOnly($raw) : bool
{
if (!$this->isReadOnly) {
return true;
}
$test = strtolower($raw);
if (strpos($test, 'insert') !== false
|| strpos($test, 'update') !== false
|| strpos($test, 'drop') !== false
|| strpos($test, 'delete') !== false
|| strpos($test, 'create') !== false
|| strpos($test, 'alter') !== false
) {
return false;
}
return true;
}
/**
* Make raw column selection.
*
@ -459,36 +481,31 @@ class Builder extends BuilderAbstract
*/
public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder
{
// TODO: handle $value is null -> operator NULL
if (isset($operator) && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
throw new \InvalidArgumentException('Unknown operator.');
}
if (is_array($columns)) {
$i = 0;
foreach ($columns as $key => $column) {
if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) {
throw new \InvalidArgumentException('Unknown operator.');
}
if (is_string($columns)) {
$colums = [$columns];
$operator = [$operator];
$values = [$values];
$boolean = [$boolean];
}
$this->wheres[self::getPublicColumnName($column)][] = [
'column' => $column,
'operator' => $operator[$i],
'value' => $values[$i],
'boolean' => $boolean[$i],
];
$i++;
}
} elseif (is_string($columns)) {
if (isset($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
$i = 0;
foreach ($columns as $key => $column) {
if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) {
throw new \InvalidArgumentException('Unknown operator.');
}
$this->wheres[self::getPublicColumnName($columns)][] = ['column' => $columns, 'operator' => $operator, 'value' => $values,
'boolean' => $boolean,];
} else {
throw new \InvalidArgumentException();
$this->wheres[self::getPublicColumnName($column)][] = [
'column' => $column,
'operator' => $operator[$i],
'value' => $values[$i],
'boolean' => $boolean[$i],
];
$i++;
}
return $this;
@ -523,7 +540,7 @@ class Builder extends BuilderAbstract
*/
public function getTableOfSystem($expression, string $systemIdentifier) /* : ?string */
{
if(($pos = strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) {
if (($pos = strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) {
return null;
}
@ -677,7 +694,7 @@ class Builder extends BuilderAbstract
public function orderBy($columns, $order = 'DESC') : Builder
{
if (is_string($columns) || $columns instanceof \Closure) {
if(!isset($this->orders[$order])) {
if (!isset($this->orders[$order])) {
$this->orders[$order] = [];
}
@ -840,7 +857,7 @@ class Builder extends BuilderAbstract
*/
public function insert(...$columns) : Builder
{
if($this->isReadOnly) {
if ($this->isReadOnly) {
throw new \Exception();
}
@ -949,7 +966,7 @@ class Builder extends BuilderAbstract
*/
public function update(...$tables) : Builder
{
if($this->isReadOnly) {
if ($this->isReadOnly) {
throw new \Exception();
}
@ -968,7 +985,7 @@ class Builder extends BuilderAbstract
public function delete() : Builder
{
if($this->isReadOnly) {
if ($this->isReadOnly) {
throw new \Exception();
}
@ -1099,7 +1116,7 @@ class Builder extends BuilderAbstract
{
$sth = $this->connection->con->prepare($this->toSql());
foreach($this->binds as $key => $bind) {
foreach ($this->binds as $key => $bind) {
$type = self::getBindParamType($bind);
$sth->bindParam($key, $bind, $type);
@ -1119,9 +1136,9 @@ class Builder extends BuilderAbstract
*/
public static function getBindParamType($value)
{
if(is_int($value)) {
if (is_int($value)) {
return PDO::PARAM_INT;
} elseif(is_string($value) || is_float($value)) {
} elseif (is_string($value) || is_float($value)) {
return PDO::PARAM_STR;
}
@ -1130,13 +1147,13 @@ class Builder extends BuilderAbstract
public static function getPublicColumnName($column) : string
{
if(is_string($column)) {
if (is_string($column)) {
return $column;
} elseif($column instanceof Column) {
} elseif ($column instanceof Column) {
return $column->getPublicName();
} elseif($column instanceof \Closure) {
} elseif ($column instanceof \Closure) {
return $column();
} elseif($column instanceof \Serializable) {
} elseif ($column instanceof \Serializable) {
return $column;
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query\Grammar;
@ -133,7 +133,6 @@ class Grammar extends GrammarAbstract
break;
case QueryType::RAW:
return [$query->raw];
break;
default:
throw new \InvalidArgumentException('Unknown query type.');
}
@ -270,7 +269,7 @@ class Grammar extends GrammarAbstract
{
$expression = '';
if(!$first) {
if (!$first) {
$expression = ' ' . strtoupper($element['boolean']) . ' ';
}
@ -317,7 +316,7 @@ class Grammar extends GrammarAbstract
protected function compileValue($value, $prefix = '') : string
{
if (is_string($value)) {
if(strpos($value, ':') === 0) {
if (strpos($value, ':') === 0) {
return $value;
}
@ -420,7 +419,7 @@ class Grammar extends GrammarAbstract
$expression = '';
foreach ($orders as $key => $order) {
foreach($order as $column) {
foreach ($order as $column) {
$expression .= $this->compileSystem($column, $query->getPrefix()) . ', ';
}

View File

@ -11,10 +11,10 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query\Grammar;
class GrammarInterface
interface GrammarInterface
{
}

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Query;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Schema;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Schema\Exception;
@ -31,7 +31,7 @@ class TableException extends \PDOException
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
* @param \Exception $previous Previous exception
*
* @since 1.0.0
*/

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Schema\Grammar;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Schema\Grammar;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Schema\Grammar;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Schema\Grammar;

View File

@ -11,7 +11,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Schema\Grammar;

Some files were not shown because too many files have changed in this diff Show More