From a02f1cca5d927e67ef78d7c937575d22c2ad4c62 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 20 Aug 2016 12:04:30 +0200 Subject: [PATCH] PhpStorm autofix/format --- DataStorage/Database/DataMapperAbstract.php | 4 +- .../Database/Query/Grammar/Grammar.php | 2 +- Dispatcher/Dispatcher.php | 2 - Event/EventManager.php | 60 ++-- Localization/Default/en_US.json | 118 +++---- Localization/Localization.php | 2 +- Localization/Money.php | 110 +++--- Log/FileLogger.php | 1 - Math/Finance/Forecasting/AR.php | 5 +- Math/Finance/Forecasting/ARCH.php | 3 +- Math/Finance/Forecasting/ARFIMA.php | 3 +- Math/Finance/Forecasting/ARIMA.php | 213 ++++++------ Math/Finance/Forecasting/ARMA.php | 3 +- .../Forecasting/ClassicalDecomposition.php | 138 ++++---- .../Forecasting/ExponentialSmoothing.php | 3 +- Math/Finance/Forecasting/GARCH.php | 3 +- Math/Finance/Forecasting/MA.php | 3 +- Math/Finance/Forecasting/NAR.php | 3 +- Math/Finance/Forecasting/NMA.php | 3 +- Math/Finance/Forecasting/SARIMA.php | 3 +- Math/Number/Irrational.php | 2 +- Math/Statistic/Average.php | 174 +++++----- Math/Statistic/Forecast/Error.php | 23 +- .../Regression/LevelLevelRegression.php | 10 +- .../Regression/LevelLogRegression.php | 16 +- .../Regression/LogLevelRegression.php | 16 +- .../Forecast/Regression/LogLogRegression.php | 16 +- .../Regression/MultipleLinearRegression.php | 30 +- .../Regression/RegressionAbstract.php | 11 +- Message/Mail/OAuth.php | 2 +- Module/InstallerAbstract.php | 12 +- Module/ModuleManager.php | 1 - Pattern/Mediator.php | 10 +- Router/Router.php | 18 +- Stdlib/Collection/Collection.php | 52 +-- System/File/Directory.php | 155 +++++---- System/File/File.php | 328 +++++++++--------- System/File/FileInterface.php | 58 ++-- Uri/UriFactory.php | 2 +- Utils/ArrayUtils.php | 4 +- Utils/Compression/LZW.php | 6 +- Utils/Converter/Ip.php | 31 +- Utils/Git/Repository.php | 2 +- Utils/JobQueue/JobQueue.php | 40 +-- Validation/Barcode/Barcode39.php | 2 +- Validation/Base/Iban.php | 2 +- Validation/BitcoinValidator.php | 1 + Validation/Validator.php | 1 + Views/ViewAbstract.php | 80 ++--- 49 files changed, 912 insertions(+), 875 deletions(-) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 006145e3a..a28425dcc 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -994,7 +994,7 @@ class DataMapperAbstract implements DataMapperInterface /** * Get random object * - * @param int $amount Amount of random models + * @param int $amount Amount of random models * @param int $relations Relations type * * @return mixed @@ -1031,7 +1031,7 @@ class DataMapperAbstract implements DataMapperInterface { $hasMany = count(static::$hasMany) > 0; $hasOne = count(static::$hasOne) > 0; - $ownsOne = count(static::$ownsOne) > 0; + $ownsOne = count(static::$ownsOne) > 0; if ($relations !== RelationType::NONE && ($hasMany || $hasOne)) { foreach ($obj as $key => $value) { diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index 7a0fcfa1e..02ca91fb8 100644 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -87,7 +87,7 @@ class Grammar extends GrammarAbstract * @since 1.0.0 */ protected $randomComponents = [ - 'random' + 'random', ]; /** diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index 4aa179882..1e5f5a829 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -16,8 +16,6 @@ namespace phpOMS\Dispatcher; use phpOMS\ApplicationAbstract; -use phpOMS\Message\RequestAbstract; -use phpOMS\Message\ResponseAbstract; use phpOMS\Module\ModuleAbstract; use phpOMS\System\File\PathException; diff --git a/Event/EventManager.php b/Event/EventManager.php index 6606b3678..81b333c24 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -65,7 +65,7 @@ class EventManager implements Mediator */ public function attach(string $group, \Closure $callback, bool $remove = false) : bool { - if(isset($this->callbacks[$group])) { + if (isset($this->callbacks[$group])) { return false; } @@ -74,54 +74,54 @@ class EventManager implements Mediator return true; } + /** + * {@inheritdoc} + */ + public function trigger(string $group, string $id = '') + { + if (isset($this->groups[$group])) { + unset($this->groups[$group][$id]); + } + + if ($this->hasOutstanding($group)) { + $this->callbacks[$group]['func']; + + if ($this->callbacks[$group]['remove']) { + $this->detach($group); + } + } + } + + /** + * {@inheritdoc} + */ + private function hasOutstanding(string $group) : bool + { + return empty($this->groups[$group]); + } + /** * {@inheritdoc} */ public function detach(string $group) : bool { - if(isset($this->callbacks[$group])) { + if (isset($this->callbacks[$group])) { unset($this->callbacks[$group]); } - if(isset($this->groups[$group])) { + if (isset($this->groups[$group])) { unset($this->groups[$group]); } return true; } - /** - * {@inheritdoc} - */ - public function trigger(string $group, string $id = '') - { - if(isset($this->groups[$group])) { - unset($this->groups[$group][$id]); - } - - if ($this->hasOutstanding($group)) { - $this->callbacks[$group]['func']; - - if($this->callbacks[$group]['remove']) { - $this->detach($group); - } - } - } - - /** - * {@inheritdoc} - */ - private function hasOutstanding(string $group) : bool - { - return empty($this->groups[$group]); - } - /** * {@inheritdoc} */ public function addGroup(string $group, string $id) { - if(!isset($this->groups[$group])) { + if (!isset($this->groups[$group])) { $this->groups[$group] = []; } diff --git a/Localization/Default/en_US.json b/Localization/Default/en_US.json index 37a42f5d8..8f193ad3f 100644 --- a/Localization/Default/en_US.json +++ b/Localization/Default/en_US.json @@ -1,61 +1,61 @@ { - "language": "EN", - "country": "USA", - "currency": { - "code" : "USD", - "position": 0 - }, - "thousand": ",", - "decimal": ".", - "angle": "Degree", - "temperature": "celsius", - "weight": { - "very_light" : "mg", - "light" : "g", - "medium" : "kg", - "heavy" : "t", - "very_heavy" : "t", - }, - "speed": { - "very_slow" : "ms", - "slow" : "ms", - "medium" : "kph", - "fast" : "kph", - "very_fast" : "mach", - "sea" : "knot" - }, - "length": { - "very_short" : "mm", - "short" : "cm", - "medium" : "m", - "long" : "km", - "very_long" : "km", - "sea": "mile" - }, - "area": { - "very_small" : "mm", - "small" : "cm", - "medium" : "m", - "large" : "km", - "very_large" : "ha" - }, - "volume": { - "very_small" : "ml", - "small" : "ml", - "medium" : "l", - "large" : "m", - "very_large" : "km", - "teaspoon": "metric teaspoon", - "tablespoon": "metric tablespoon", - "glass": "metric glass" - }, - "datetime": { - "delim_date": ".", - "delim_time": ":", - "very_short": "d.m", - "short": "m.y", - "medium": "d.m.Y", - "long": "d.m.Y h:i", - "very_long": "d.m.Y h:i:s", - } + "language": "EN", + "country": "USA", + "currency": { + "code": "USD", + "position": 0 + }, + "thousand": ",", + "decimal": ".", + "angle": "Degree", + "temperature": "celsius", + "weight": { + "very_light": "mg", + "light": "g", + "medium": "kg", + "heavy": "t", + "very_heavy": "t", + }, + "speed": { + "very_slow": "ms", + "slow": "ms", + "medium": "kph", + "fast": "kph", + "very_fast": "mach", + "sea": "knot" + }, + "length": { + "very_short": "mm", + "short": "cm", + "medium": "m", + "long": "km", + "very_long": "km", + "sea": "mile" + }, + "area": { + "very_small": "mm", + "small": "cm", + "medium": "m", + "large": "km", + "very_large": "ha" + }, + "volume": { + "very_small": "ml", + "small": "ml", + "medium": "l", + "large": "m", + "very_large": "km", + "teaspoon": "metric teaspoon", + "tablespoon": "metric tablespoon", + "glass": "metric glass" + }, + "datetime": { + "delim_date": ".", + "delim_time": ":", + "very_short": "d.m", + "short": "m.y", + "medium": "d.m.Y", + "long": "d.m.Y h:i", + "very_long": "d.m.Y h:i:s", + } } \ No newline at end of file diff --git a/Localization/Localization.php b/Localization/Localization.php index fb8d2ba9e..fdc8eb585 100644 --- a/Localization/Localization.php +++ b/Localization/Localization.php @@ -382,5 +382,5 @@ class Localization public function setTemperatur(string $temperature) { $this->temperature = $temperature; - } + } } diff --git a/Localization/Money.php b/Localization/Money.php index 080a697d7..1676f0bf0 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -65,10 +65,10 @@ class Money implements \Serializable * Constructor. * * @param string|int|float $value Value - * @param string $thousands Thousands separator - * @param string $decimal Decimal separator - * @param string $symbol Currency symbol - * @param int $position Symbol position + * @param string $thousands Thousands separator + * @param string $decimal Decimal separator + * @param string $symbol Currency symbol + * @param int $position Symbol position * * @since 1.0.0 * @author Dennis Eichhorn @@ -82,42 +82,6 @@ class Money implements \Serializable $this->position = $position; } - /** - * Set localization. - * - * @param string $thousands Thousands separator - * @param string $decimal Decimal separator - * @param string $symbol Currency symbol - * @param int $position Symbol position - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function setLocalization(string $thousands = ',', string $decimal = '.', string $symbol = '', int $position = 0) - { - $this->thousands = $thousands; - $this->decimal = $decimal; - $this->symbol = $symbol; - $this->position = $position; - } - - /** - * Set value by string. - * - * @param string $value Money value - * - * @return Money - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function setString(string $value) : Money - { - $this->value = self::toInt($value, $this->thousands, $this->decimal); - - return $this; - } - /** * Money to int. * @@ -146,6 +110,57 @@ class Money implements \Serializable return (int) (((int) $left) * 10 ** self::MAX_DECIMALS + (int) str_pad($right, self::MAX_DECIMALS, '0')); } + /** + * Set localization. + * + * @param string $thousands Thousands separator + * @param string $decimal Decimal separator + * @param string $symbol Currency symbol + * @param int $position Symbol position + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setLocalization(string $thousands = ',', string $decimal = '.', string $symbol = '', int $position = 0) + { + $this->thousands = $thousands; + $this->decimal = $decimal; + $this->symbol = $symbol; + $this->position = $position; + } + + /** + * Set value by string. + * + * @param string $value Money value + * + * @return Money + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setString(string $value) : Money + { + $this->value = self::toInt($value, $this->thousands, $this->decimal); + + return $this; + } + + /** + * Get money. + * + * @param int $decimals Precision + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCurrency(int $decimals = 2) : string + { + return ($position === 0 ? $smbol : '') . $this->getAmount($decimals, $thousands, $decimal) . ($position === 1 ? $smbol : ''); + } + /** * Get money. * @@ -166,21 +181,6 @@ class Money implements \Serializable return ($decimals > 0) ? number_format($left, 0, $this->decimal, $this->thousands) . $this->decimal . substr($right, 0, $decimals) : (string) $left; } - /** - * Get money. - * - * @param int $decimals Precision - * - * @return string - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function getCurrency(int $decimals = 2) : string - { - return ($position === 0 ? $smbol : '') . $this->getAmount($decimals, $thousands, $decimal) . ($position === 1 ? $smbol : ''); - } - /** * Add money. * diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 653c489f1..2b706cbbb 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -16,7 +16,6 @@ namespace phpOMS\Log; use phpOMS\Datatypes\Exception\InvalidEnumValue; -use phpOMS\System\File\Directory; use phpOMS\System\File\File; use phpOMS\System\File\PathException; use phpOMS\Utils\StringUtils; diff --git a/Math/Finance/Forecasting/AR.php b/Math/Finance/Forecasting/AR.php index 33bcaaabf..7dd4a76d8 100644 --- a/Math/Finance/Forecasting/AR.php +++ b/Math/Finance/Forecasting/AR.php @@ -2,6 +2,7 @@ namespace phpOMS\Math\Finance\Forecasting; -class AR { - +class AR +{ + } \ No newline at end of file diff --git a/Math/Finance/Forecasting/ARCH.php b/Math/Finance/Forecasting/ARCH.php index 57bb45948..f2e8e260a 100644 --- a/Math/Finance/Forecasting/ARCH.php +++ b/Math/Finance/Forecasting/ARCH.php @@ -2,6 +2,7 @@ namespace phpOMS\Math\Finance\Forecasting; -class ARCH { +class ARCH +{ } \ No newline at end of file diff --git a/Math/Finance/Forecasting/ARFIMA.php b/Math/Finance/Forecasting/ARFIMA.php index b65c40e20..ed0357ac6 100644 --- a/Math/Finance/Forecasting/ARFIMA.php +++ b/Math/Finance/Forecasting/ARFIMA.php @@ -2,6 +2,7 @@ namespace phpOMS\Math\Finance\Forecasting; -class ARFIMA { +class ARFIMA +{ } diff --git a/Math/Finance/Forecasting/ARIMA.php b/Math/Finance/Forecasting/ARIMA.php index d10290355..2ca1ce104 100644 --- a/Math/Finance/Forecasting/ARIMA.php +++ b/Math/Finance/Forecasting/ARIMA.php @@ -2,133 +2,144 @@ namespace phpOMS\Math\Finance\Forecasting; -class ARIMA { - public function __construct(array $data, int $order = 12) { - if($order !== 12 && $order !== 4) { - throw new \Exceptions('ARIMA only supports quarterly and monthly decomposition'); - } - } +class ARIMA +{ + public function __construct(array $data, int $order = 12) + { + if ($order !== 12 && $order !== 4) { + throw new \Exceptions('ARIMA only supports quarterly and monthly decomposition'); + } + } - public function getDecomposition() : array { - $iteration1 = $this->getIteration($this->data); - $iteration2 = $this->getIteration($iteration1); - $iteration3 = $this->getIteration($iteration2); + public function getDecomposition() : array + { + $iteration1 = $this->getIteration($this->data); + $iteration2 = $this->getIteration($iteration1); + $iteration3 = $this->getIteration($iteration2); - return $iteration3; - } + return $iteration3; + } - private function getIteration(array $data) : array { - $multiplicativeDecomposition = new ClassicalDecomposition($data, $this->order, ClassicalDecomposition::MULTIPLICATIVE); - $tempDecomposition = $multiplicativeDecomposition->getDecomposition(); + private function getIteration(array $data) : array + { + $multiplicativeDecomposition = new ClassicalDecomposition($data, $this->order, ClassicalDecomposition::MULTIPLICATIVE); + $tempDecomposition = $multiplicativeDecomposition->getDecomposition(); - // 1 - $trendCycleComponent = ClassicalDecomposition::computeTrendCycle($data, $this->order); - $centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE); - $prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 3, null, true), 3, null, true); - $prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent); - $modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5); - $modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder); - $revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 3, null, true), 3, null, true); - $prelimSeasonalAdjustedSeries = $this->getPrelimSeasonalAdjustedSeries($revisedSeasonalComponent); - $trendCycleComponent = $this->getTrendCycleEstimation($prelimSeasonalAdjustedSeries); + // 1 + $trendCycleComponent = ClassicalDecomposition::computeTrendCycle($data, $this->order); + $centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE); + $prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 3, null, true), 3, null, true); + $prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent); + $modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5); + $modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder); + $revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 3, null, true), 3, null, true); + $prelimSeasonalAdjustedSeries = $this->getPrelimSeasonalAdjustedSeries($revisedSeasonalComponent); + $trendCycleComponent = $this->getTrendCycleEstimation($prelimSeasonalAdjustedSeries); - // 2 - $centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE); - $prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 5, null, true), 3, null, true); - $prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent); - $modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5); - $modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder); - $revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 5, null, true), 3, null, true); - $seasonalAdjustedSeries = $this->getSeasonalAdjustedSeries($revisedSeasonalComponent); + // 2 + $centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE); + $prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 5, null, true), 3, null, true); + $prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent); + $modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5); + $modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder); + $revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 5, null, true), 3, null, true); + $seasonalAdjustedSeries = $this->getSeasonalAdjustedSeries($revisedSeasonalComponent); - $remainder = $this->getRemainder($seasonalAdjustedSeries, $trendCycleComponent); - $modifiedRemainder = $this->removeOutliers($remainder, 0.5); - $modifiedData = $this->getModifiedData($trendCycleComponent, $seasonalAdjustedSeries, $modifiedRemainder); + $remainder = $this->getRemainder($seasonalAdjustedSeries, $trendCycleComponent); + $modifiedRemainder = $this->removeOutliers($remainder, 0.5); + $modifiedData = $this->getModifiedData($trendCycleComponent, $seasonalAdjustedSeries, $modifiedRemainder); - return $modifiedData; - } + return $modifiedData; + } - private function getPrelimRemainder(array $centeredRatios, array $prelimSeasonalComponent) : array { - $remainder = []; - $count = count($prelimSeasonalComponent); + private function getPrelimRemainder(array $centeredRatios, array $prelimSeasonalComponent) : array + { + $remainder = []; + $count = count($prelimSeasonalComponent); - for($i = 0; $i < $count; $i++) { - // +1 since 3x3 MA - $remainder[] = $centeredRatios[$i+1] / $prelimSeasonalComponent[$i]; - } + for ($i = 0; $i < $count; $i++) { + // +1 since 3x3 MA + $remainder[] = $centeredRatios[$i + 1] / $prelimSeasonalComponent[$i]; + } - return $remainder; - } + return $remainder; + } - private function removeOutliers(array $data, float $deviation = 0.5) : array { - $avg = AVerage::arithmeticMean($data); + private function removeOutliers(array $data, float $deviation = 0.5) : array + { + $avg = AVerage::arithmeticMean($data); - foreach($data as $key => $value) { - if($value / $avg - 1 > $deviation) { - $data[$key] = $avg; - } - } + foreach ($data as $key => $value) { + if ($value / $avg - 1 > $deviation) { + $data[$key] = $avg; + } + } - return $data; - } + return $data; + } - private function getModifiedCenteredRatios(array $seasonal, array $remainder) : array { - $centeredRatio = []; - $count = count($seasonal); + private function getModifiedCenteredRatios(array $seasonal, array $remainder) : array + { + $centeredRatio = []; + $count = count($seasonal); - for($i = 0; $i < $count; $i++) { - // +1 since 3x3 MA - $centeredRatio[] = $remainder[$i+1] * $seasonal[$i]; - } + for ($i = 0; $i < $count; $i++) { + // +1 since 3x3 MA + $centeredRatio[] = $remainder[$i + 1] * $seasonal[$i]; + } - return $centeredRatio; - } + return $centeredRatio; + } - private function getSeasonalAdjustedSeries(array $seasonal) : array { - $adjusted = []; - $count = count($seasonal); - $start = ClassicalDecomposition::getStartOfDecomposition(count($this->data), $count); + private function getTrendCycleEstimation(array $seasonal) : array + { + $count = count($seasonal); - for($i = 0; $i < $count; $i++) { - $adjusted[] = $this->data[$start + $i] / $seasonal[$i]; - } + if ($count >= 12) { + $weight = Average::MAH23; + } elseif ($count >= 6) { + $weight = Average::MAH13; + } else { + $weight = Average::MAH9; + } - return $adjusted; - } + // todo: implement - private function getTrendCycleEstimation(array $seasonal) : array { - $count = count($seasonal); + return $seasonal; + } - if($count >= 12) { - $weight = Average::MAH23; - } elseif($count >= 6) { - $weight = Average::MAH13; - } else { - $weight = Average::MAH9; - } + private function getSeasonalAdjustedSeries(array $seasonal) : array + { + $adjusted = []; + $count = count($seasonal); + $start = ClassicalDecomposition::getStartOfDecomposition(count($this->data), $count); - // todo: implement + for ($i = 0; $i < $count; $i++) { + $adjusted[] = $this->data[$start + $i] / $seasonal[$i]; + } - return $seasonal; - } + return $adjusted; + } - private function getRemainder(array $seasonal, array $trendCycle) { - $remainder = []; - foreach($seasonal as $key => $e) { - $remainder = $e / $trendCycle[$key]; - } + private function getRemainder(array $seasonal, array $trendCycle) + { + $remainder = []; + foreach ($seasonal as $key => $e) { + $remainder = $e / $trendCycle[$key]; + } - return $remainder; - } + return $remainder; + } - private function getModifiedData(array $trendCycleComponent, array $seasonalAdjustedSeries, array $remainder) : array { - $data = []; - $count = count($trendCycleComponent); + private function getModifiedData(array $trendCycleComponent, array $seasonalAdjustedSeries, array $remainder) : array + { + $data = []; + $count = count($trendCycleComponent); - for($i = 0; $i < $count; $i++) { - $data[] = $trendCycleComponent[$i] * $seasonalAdjustedSeries[$i] * $remainder[$i]; - } + for ($i = 0; $i < $count; $i++) { + $data[] = $trendCycleComponent[$i] * $seasonalAdjustedSeries[$i] * $remainder[$i]; + } - return $data; - } + return $data; + } } \ No newline at end of file diff --git a/Math/Finance/Forecasting/ARMA.php b/Math/Finance/Forecasting/ARMA.php index 769859a1f..50c4a4a3f 100644 --- a/Math/Finance/Forecasting/ARMA.php +++ b/Math/Finance/Forecasting/ARMA.php @@ -2,6 +2,7 @@ namespace phpOMS\Math\Finance\Forecasting; -class ARMA { +class ARMA +{ } diff --git a/Math/Finance/Forecasting/ClassicalDecomposition.php b/Math/Finance/Forecasting/ClassicalDecomposition.php index 93f22df95..478cbacd4 100644 --- a/Math/Finance/Forecasting/ClassicalDecomposition.php +++ b/Math/Finance/Forecasting/ClassicalDecomposition.php @@ -4,88 +4,96 @@ namespace phpOMS\Math\Finance\Forecasting; use phpOMS\Math\Statistic\Average; -class ClassicalDecomposition { - const ADDITIVE = 0; - const MULTIPLICATIVE = 1; +class ClassicalDecomposition +{ + const ADDITIVE = 0; + const MULTIPLICATIVE = 1; - private $mode = self::ADDITIVE; - private $data = []; - private $order = 0; - private $dataSize = 0; + private $mode = self::ADDITIVE; + private $data = []; + private $order = 0; + private $dataSize = 0; - public function __construct(array $data, int $order, int $mode = self::ADDITIVE) { - $this->mode = $mode; - $this->data = $data; - $this->order = $order; + public function __construct(array $data, int $order, int $mode = self::ADDITIVE) + { + $this->mode = $mode; + $this->data = $data; + $this->order = $order; - $this->dataSize = count($data); - } + $this->dataSize = count($data); + } - public function getDecomposition() : array { - $trendCycleComponent = self::computeTrendCycle($this->data, $this->order); - $detrendedSeries = self::computeDetrendedSeries($this->data, $trendCycleComponent, $this->mode); - $seasonalComponent = $this->computeSeasonalComponent($detrendedSeries, $this->order); - $remainderComponent = $this->computeRemainderComponent($trendCycleComponent, $seasonalComponent); + public function getDecomposition() : array + { + $trendCycleComponent = self::computeTrendCycle($this->data, $this->order); + $detrendedSeries = self::computeDetrendedSeries($this->data, $trendCycleComponent, $this->mode); + $seasonalComponent = $this->computeSeasonalComponent($detrendedSeries, $this->order); + $remainderComponent = $this->computeRemainderComponent($trendCycleComponent, $seasonalComponent); - return [ - 'trendCycleComponent' => $trendCycleComponent, - 'detrendedSeries' => $detrendedSeries, - 'seasonalComponent' => $seasonalComponent, - 'remainderComponent' => $remainderComponent, - ]; - } + return [ + 'trendCycleComponent' => $trendCycleComponent, + 'detrendedSeries' => $detrendedSeries, + 'seasonalComponent' => $seasonalComponent, + 'remainderComponent' => $remainderComponent, + ]; + } - public static function computeTrendCycle(array $data, int $order) : array { - $mMA = Average::totalMovingAverage($data, $order, null, true); + public static function computeTrendCycle(array $data, int $order) : array + { + $mMA = Average::totalMovingAverage($data, $order, null, true); - return $order % 2 === 0 ? Average::totalMovingAverage($mMA, 2, null, true) : $mMA; - } + return $order % 2 === 0 ? Average::totalMovingAverage($mMA, 2, null, true) : $mMA; + } - public static function computeDetrendedSeries(array $data, array $trendCycleComponent, int $mode) : array { - $detrended = []; - $count = count($trendCycleComponent); - $start = self::getStartOfDecomposition(count($data), $count); + public static function computeDetrendedSeries(array $data, array $trendCycleComponent, int $mode) : array + { + $detrended = []; + $count = count($trendCycleComponent); + $start = self::getStartOfDecomposition(count($data), $count); - for($i = 0; $i < $count; $i++) { - $detrended[] = $mode === self::ADDITIVE ? $data[$start + $i] - $trendCycleComponent[$i] : $data[$start + $i] / $trendCycleComponent[$i]; - } + for ($i = 0; $i < $count; $i++) { + $detrended[] = $mode === self::ADDITIVE ? $data[$start + $i] - $trendCycleComponent[$i] : $data[$start + $i] / $trendCycleComponent[$i]; + } - return $detrended; - } + return $detrended; + } - /** - * Moving average can't start at index 0 since it needs to go m indices back for average -> can only start at m - */ - public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int { - return ($dataSize - $trendCycleComponents) / 2; - } + /** + * Moving average can't start at index 0 since it needs to go m indices back for average -> can only start at m + */ + public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int + { + return ($dataSize - $trendCycleComponents) / 2; + } - private function computeSeasonalComponent() : array { - $seasonalComponent = []; + private function computeSeasonalComponent() : array + { + $seasonalComponent = []; - for($i = 0; $i < $this->orderSize; $i++) { - $temp = []; + for ($i = 0; $i < $this->orderSize; $i++) { + $temp = []; - for($j = $i * $this->order; $j < $count; $j += $this->order) { - $temp[] = $this->data[$j]; - } + for ($j = $i * $this->order; $j < $count; $j += $this->order) { + $temp[] = $this->data[$j]; + } - $seasonalComponent[] = Average::arithmeticMean($temp); - } + $seasonalComponent[] = Average::arithmeticMean($temp); + } - return $seasonalComponent; - } + return $seasonalComponent; + } - public static function computeRemainderComponent(array $trendCycleComponent, array $seasonalComponent) : array { - $remainderComponent = []; - $count = count($trendCycleComponent); - $start = self::getStartOfDecomposition($this->dataSize, $count); - $seasons = count($seasonalComponent); + public static function computeRemainderComponent(array $trendCycleComponent, array $seasonalComponent) : array + { + $remainderComponent = []; + $count = count($trendCycleComponent); + $start = self::getStartOfDecomposition($this->dataSize, $count); + $seasons = count($seasonalComponent); - for($i = 0; $i < $count; $i++) { - $remainderComponent[] = $this->mode === self::ADDITIVE ? $this->data[$start + $i] - $trendCycleComponent[$i] - $seasonalComponent[$i % $seasons] : $this->data[$start + $i] / ($trendCycleComponent[$i] * $seasonalComponent[$i % $seasons]); - } + for ($i = 0; $i < $count; $i++) { + $remainderComponent[] = $this->mode === self::ADDITIVE ? $this->data[$start + $i] - $trendCycleComponent[$i] - $seasonalComponent[$i % $seasons] : $this->data[$start + $i] / ($trendCycleComponent[$i] * $seasonalComponent[$i % $seasons]); + } - return $remainderComponent; - } + return $remainderComponent; + } } \ No newline at end of file diff --git a/Math/Finance/Forecasting/ExponentialSmoothing.php b/Math/Finance/Forecasting/ExponentialSmoothing.php index 3cea0a01f..ea4d2b761 100644 --- a/Math/Finance/Forecasting/ExponentialSmoothing.php +++ b/Math/Finance/Forecasting/ExponentialSmoothing.php @@ -2,6 +2,7 @@ namespace phpOMS\Math\Finance\Forecasting; -class ExponentialSmoothing { +class ExponentialSmoothing +{ } diff --git a/Math/Finance/Forecasting/GARCH.php b/Math/Finance/Forecasting/GARCH.php index 99caecf2f..36a6ab57d 100644 --- a/Math/Finance/Forecasting/GARCH.php +++ b/Math/Finance/Forecasting/GARCH.php @@ -2,6 +2,7 @@ namespace phpOMS\Math\Finance\Forecasting; -class GARCH { +class GARCH +{ } diff --git a/Math/Finance/Forecasting/MA.php b/Math/Finance/Forecasting/MA.php index 1ecbfcb05..664b5de94 100644 --- a/Math/Finance/Forecasting/MA.php +++ b/Math/Finance/Forecasting/MA.php @@ -2,7 +2,8 @@ namespace phpOMS\Math\Finance\Forecasting; -class MA { +class MA +{ } diff --git a/Math/Finance/Forecasting/NAR.php b/Math/Finance/Forecasting/NAR.php index d509a77f3..8c18b5071 100644 --- a/Math/Finance/Forecasting/NAR.php +++ b/Math/Finance/Forecasting/NAR.php @@ -2,7 +2,8 @@ namespace phpOMS\Math\Finance\Forecasting; -class NAR { +class NAR +{ } diff --git a/Math/Finance/Forecasting/NMA.php b/Math/Finance/Forecasting/NMA.php index db988c00a..25f062ce3 100644 --- a/Math/Finance/Forecasting/NMA.php +++ b/Math/Finance/Forecasting/NMA.php @@ -2,7 +2,8 @@ namespace phpOMS\Math\Finance\Forecasting; -class NMA { +class NMA +{ } diff --git a/Math/Finance/Forecasting/SARIMA.php b/Math/Finance/Forecasting/SARIMA.php index 6cc909028..7e3c2c9dc 100644 --- a/Math/Finance/Forecasting/SARIMA.php +++ b/Math/Finance/Forecasting/SARIMA.php @@ -2,7 +2,8 @@ namespace phpOMS\Math\Finance\Forecasting; -class SARIMA { +class SARIMA +{ } diff --git a/Math/Number/Irrational.php b/Math/Number/Irrational.php index 1f6781558..337d47066 100644 --- a/Math/Number/Irrational.php +++ b/Math/Number/Irrational.php @@ -18,5 +18,5 @@ namespace phpOMS\Math\Number; class Irrational { - + } \ No newline at end of file diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php index f2990fee0..40281364b 100644 --- a/Math/Statistic/Average.php +++ b/Math/Statistic/Average.php @@ -30,18 +30,92 @@ namespace phpOMS\Math\Statistic; class Average { - const MA3 = [1/3, 1/3]; + const MA3 = [1 / 3, 1 / 3]; const MA5 = [0.2, 0.2, 0.2]; - const MA2x12 = [5/6, 5/6, 5/6, 5/6, 5/6, 5/6, 0.42]; - const MA3x3 = [1/3, 2/9, 1/9]; - const MA3x5 = [0.2, 0.2, 2/15, 4/6]; - const MAS15 = [0.231, 0.209, 0.144, 2/3, 0.009, -0.016, -0.019, -0.009]; + const MA2x12 = [5 / 6, 5 / 6, 5 / 6, 5 / 6, 5 / 6, 5 / 6, 0.42]; + const MA3x3 = [1 / 3, 2 / 9, 1 / 9]; + const MA3x5 = [0.2, 0.2, 2 / 15, 4 / 6]; + const MAS15 = [0.231, 0.209, 0.144, 2 / 3, 0.009, -0.016, -0.019, -0.009]; const MAS21 = [0.171, 0.163, 0.134, 0.37, 0.51, 0.017, -0.006, -0.014, -0.014, -0.009, -0.003]; const MAH5 = [0.558, 0.294, -0.73]; const MAH9 = [0.330, 0.267, 0.119, -0.010, -0.041]; const MAH13 = [0.240, 0.214, 0.147, 0.66, 0, -0.028, -0.019]; const MAH23 = [0.148, 0.138, 0.122, 0.097, 0.068, 0.039, 0.013, -0.005, -0.015, -0.016, -0.011, -0.004]; + /** + * Average change. + * + * @param array $x Dataset + * @param int $h Future steps + * + * @return float + * + * @throws + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function averageChange(array $x, int $h = 1) : float + { + $count = count($x); + + return $x[$count - 1] + $h * ($x[$count - 1] - $x[0]) / ($count - 1); + } + + /** + * t = 3 and p = 3 means -1 0 +1, t = 4 and p = 2 means -1 0 + * periods should be replaced with order than it's possible to test for even or odd m + * todo: maybe floor()? + */ + public static function totalMovingAverage(array $x, int $order, array $weight = null, bool $symmetric = false) : array + { + $periods = (int) ($order / 2); + $count = count($x) - ($symmetric ? $periods : 0); + $avg = []; + + for ($i = $periods; $i < $count; $i++) { + $avg[] = self::movingAverage($x, $i, $order, $weight, $symmetric); + } + + return $avg; + } + + /** + * Moving average or order m. + * + * @param array $x Dataset + * @param int $t Current period + * @param int $periods Periods to use for average + * + * @return float + * + * @todo : allow counter i also to go into the future... required for forecast how? should be doable! + * + * @throws + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function movingAverage(array $x, int $t, int $order, array $weight = null, bool $symmetric = false) : float + { + $periods = (int) ($order / 2); + $count = count($x); + + if ($t < $periods || ($count < $periods) || ($symmetric && $t + $periods < $count)) { + throw new \Exception('Periods'); + } + + $end = $symmetric ? $periods - 1 : 0; + $end = $order % 2 === 0 ? $end - 1 : $end; + $start = $t - 1 - ($periods - 2); + + if (isset($weight)) { + return self::weightedAverage(array_slice($x, $start, $end - $start), array_slice($weight, $start, $end - $start)); + } else { + return self::arithmeticMean(array_slice($x, $start, $end - $start)); + } + } + /** * Calculate weighted average. * @@ -73,10 +147,11 @@ class Average } /** - * Average change. + * Calculate the arithmetic mean. * - * @param array $x Dataset - * @param int $h Future steps + * Example: ([1, 2, 2, 3, 4, 4, 2]) + * + * @param array $values Values * * @return float * @@ -85,63 +160,15 @@ class Average * @since 1.0.0 * @author Dennis Eichhorn */ - public static function averageChange(array $x, int $h = 1) : float + public static function arithmeticMean(array $values) { - $count = count($x); + $count = count($values); - return $x[$count - 1] + $h * ($x[$count - 1] - $x[0]) / ($count - 1); - } - - /** - * Moving average or order m. - * - * @param array $x Dataset - * @param int $t Current period - * @param int $periods Periods to use for average - * - * @return float - * - * @todo: allow counter i also to go into the future... required for forecast how? should be doable! - * - * @throws - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public static function movingAverage(array $x, int $t, int $order, array $weight = null, bool $symmetric = false) : float { - $periods = (int) ($order / 2); - $count = count($x); - - if($t < $periods || ($count < $periods) || ($symmetric && $t + $periods < $count)) { - throw new \Exception('Periods'); + if ($count === 0) { + throw new \Exception('Division zero'); } - $end = $symmetric ? $periods - 1 : 0; - $end = $order % 2 === 0 ? $end - 1 : $end; - $start = $t - 1 -($periods - 2); - - if(isset($weight)) { - return self::weightedAverage(array_slice($x, $start, $end-$start), array_slice($weight, $start, $end-$start)); - } else { - return self::arithmeticMean(array_slice($x, $start, $end-$start)); - } - } - - /** - * t = 3 and p = 3 means -1 0 +1, t = 4 and p = 2 means -1 0 - * periods should be replaced with order than it's possible to test for even or odd m - * todo: maybe floor()? - */ - public static function totalMovingAverage(array $x, int $order, array $weight = null, bool $symmetric = false) : array { - $periods = (int) ($order / 2); - $count = count($x) - ($symmetric ? $periods : 0); - $avg = []; - - for($i = $periods; $i < $count; $i++) { - $avg[] = self::movingAverage($x, $i, $order, $weight, $symmetric); - } - - return $avg; + return array_sum($values) / $count; } /** @@ -193,31 +220,6 @@ class Average return $median; } - /** - * Calculate the arithmetic mean. - * - * Example: ([1, 2, 2, 3, 4, 4, 2]) - * - * @param array $values Values - * - * @return float - * - * @throws - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public static function arithmeticMean(array $values) - { - $count = count($values); - - if ($count === 0) { - throw new \Exception('Division zero'); - } - - return array_sum($values) / $count; - } - /** * Calculate the geometric mean. * diff --git a/Math/Statistic/Forecast/Error.php b/Math/Statistic/Forecast/Error.php index 84a6a0990..f806b55cd 100644 --- a/Math/Statistic/Forecast/Error.php +++ b/Math/Statistic/Forecast/Error.php @@ -181,17 +181,19 @@ class Error * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSumSquaredError(array $errors) : float { + public static function getSumSquaredError(array $errors) : float + { $error = 0.0; - foreach($errors as $e) { - $error += $e*$e; + foreach ($errors as $e) { + $error += $e * $e; } return $error; } - public static function getRBarSquared(float $R, int $observations, int $predictors) : float { + public static function getRBarSquared(float $R, int $observations, int $predictors) : float + { return 1 - (1 - $R * ($observations - 1) / ($observations - $predictors - 1)); } @@ -199,7 +201,8 @@ class Error * Get Aike's information criterion (AIC) * */ - public static function getAkaikeInformationCriterion(float $sse, int $observations, int $predictors) : float { + public static function getAkaikeInformationCriterion(float $sse, int $observations, int $predictors) : float + { return $observations * log($sse / $observations) + 2 * ($predictors + 2); } @@ -208,16 +211,18 @@ class Error * * Correction for small amount of observations */ - public static function getCorrectedAkaikeInformationCriterion(float $aic, int $observations, int $predictors) : float { - return $aic + (2*($predictors +2)*($predictors + 3)) / ($observations - $predictors - 3); + public static function getCorrectedAkaikeInformationCriterion(float $aic, int $observations, int $predictors) : float + { + return $aic + (2 * ($predictors + 2) * ($predictors + 3)) / ($observations - $predictors - 3); } /** * Get Bayesian information criterion (BIC) * */ - public static function getSchwarzBayesianInformationCriterion(float $sse, int $observations, int $predictors) : float { - return $observations * log($sse / $observations) + ($predictors +2)*log($observations); + public static function getSchwarzBayesianInformationCriterion(float $sse, int $observations, int $predictors) : float + { + return $observations * log($sse / $observations) + ($predictors + 2) * log($observations); } /** diff --git a/Math/Statistic/Forecast/Regression/LevelLevelRegression.php b/Math/Statistic/Forecast/Regression/LevelLevelRegression.php index 8c4d91221..8e50c2dae 100644 --- a/Math/Statistic/Forecast/Regression/LevelLevelRegression.php +++ b/Math/Statistic/Forecast/Regression/LevelLevelRegression.php @@ -16,10 +16,6 @@ namespace phpOMS\Math\Statistic\Forecast\Regression; -use phpOMS\Math\Statistic\Average; -use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier; -use phpOMS\Math\Statistic\MeasureOfDispersion; - /** * Regression class. * @@ -33,11 +29,13 @@ use phpOMS\Math\Statistic\MeasureOfDispersion; */ class LevelLevelRegression extends RegressionAbstract { - public static function getSlope(float $b1, float $y, float $x) : float { + public static function getSlope(float $b1, float $y, float $x) : float + { return $b1; } - public static function getElasticity(float $b1, float $y, float $x): float { + public static function getElasticity(float $b1, float $y, float $x): float + { return $b1 * $y / $x; } } \ No newline at end of file diff --git a/Math/Statistic/Forecast/Regression/LevelLogRegression.php b/Math/Statistic/Forecast/Regression/LevelLogRegression.php index e64c3aedb..15b9d3457 100644 --- a/Math/Statistic/Forecast/Regression/LevelLogRegression.php +++ b/Math/Statistic/Forecast/Regression/LevelLogRegression.php @@ -16,10 +16,6 @@ namespace phpOMS\Math\Statistic\Forecast\Regression; -use phpOMS\Math\Statistic\Average; -use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier; -use phpOMS\Math\Statistic\MeasureOfDispersion; - /** * Regression class. * @@ -48,23 +44,25 @@ class LevelLogRegression extends RegressionAbstract */ public static function getRegression(array $x, array $y) : array { - if(($c = count($x)) != count($y)) { + if (($c = count($x)) != count($y)) { throw new \Exception('Dimension'); } - for($i = 0; $i < $c; $i++) { + for ($i = 0; $i < $c; $i++) { $x[$i] = log($x[i]); } return parent::getRegression($x, $y); } - public static function getSlope(float $b1, float $y, float $x) : float { + public static function getSlope(float $b1, float $y, float $x) : float + { return $b1 / $x; } - public static function getElasticity(float $b1, float $y, float $x): float { + public static function getElasticity(float $b1, float $y, float $x): float + { return $b1 / $x; } - + } \ No newline at end of file diff --git a/Math/Statistic/Forecast/Regression/LogLevelRegression.php b/Math/Statistic/Forecast/Regression/LogLevelRegression.php index d7d2946a1..52322db47 100644 --- a/Math/Statistic/Forecast/Regression/LogLevelRegression.php +++ b/Math/Statistic/Forecast/Regression/LogLevelRegression.php @@ -16,10 +16,6 @@ namespace phpOMS\Math\Statistic\Forecast\Regression; -use phpOMS\Math\Statistic\Average; -use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier; -use phpOMS\Math\Statistic\MeasureOfDispersion; - /** * Regression class. * @@ -48,23 +44,25 @@ class LogLevelRegression extends RegressionAbstract */ public static function getRegression(array $x, array $y) : array { - if(($c = count($x)) != count($y)) { + if (($c = count($x)) != count($y)) { throw new \Exception('Dimension'); } - for($i = 0; $i < $c; $i++) { + for ($i = 0; $i < $c; $i++) { $y[$i] = log($y[i]); } return parent::getRegression($x, $y); } - public static function getSlope(float $b1, float $y, float $x) : float { + public static function getSlope(float $b1, float $y, float $x) : float + { return $b1 * $y; } - public static function getElasticity(float $b1, float $y, float $x): float { + public static function getElasticity(float $b1, float $y, float $x): float + { return $b1 * $x; } - + } \ No newline at end of file diff --git a/Math/Statistic/Forecast/Regression/LogLogRegression.php b/Math/Statistic/Forecast/Regression/LogLogRegression.php index 0ee514aff..acdcf7822 100644 --- a/Math/Statistic/Forecast/Regression/LogLogRegression.php +++ b/Math/Statistic/Forecast/Regression/LogLogRegression.php @@ -16,10 +16,6 @@ namespace phpOMS\Math\Statistic\Forecast\Regression; -use phpOMS\Math\Statistic\Average; -use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier; -use phpOMS\Math\Statistic\MeasureOfDispersion; - /** * Regression class. * @@ -48,11 +44,11 @@ class LogLogRegression extends RegressionAbstract */ public static function getRegression(array $x, array $y) : array { - if(($c = count($x)) != count($y)) { + if (($c = count($x)) != count($y)) { throw new \Exception('Dimension'); } - for($i = 0; $i < $c; $i++) { + for ($i = 0; $i < $c; $i++) { $x[$i] = log($x[i]); $y[$i] = log($y[i]); } @@ -60,12 +56,14 @@ class LogLogRegression extends RegressionAbstract return parent::getRegression($x, $y); } - public static function getSlope(float $b1, float $y, float $x) : float { + public static function getSlope(float $b1, float $y, float $x) : float + { return $b1 * $y / $x; } - public static function getElasticity(float $b1, float $y, float $x): float { + public static function getElasticity(float $b1, float $y, float $x): float + { return $b1; } - + } \ No newline at end of file diff --git a/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php b/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php index 1c28b4588..2ba3ee6a0 100644 --- a/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php +++ b/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php @@ -2,20 +2,26 @@ namespace phpOMS\Math\Statistic\Forecast\Regression; -class MultipleLinearRegression { - public static function getRegression(array $x, array $y) : array { - $X = new Matrix(count($x), count($x[0])); - $X->setArray($x); - $XT = $X->transpose(); +class MultipleLinearRegression +{ + public static function getRegression(array $x, array $y) : array + { + $X = new Matrix(count($x), count($x[0])); + $X->setArray($x); + $XT = $X->transpose(); - $Y = new Matrix(count($y)); - $Y->setArray($y); - + $Y = new Matrix(count($y)); + $Y->setArray($y); - return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->toArray(); - } - public static function getVariance() : float {} + return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->toArray(); + } - public static function getPredictionInterval() : array {} + public static function getVariance() : float + { + } + + public static function getPredictionInterval() : array + { + } } \ No newline at end of file diff --git a/Math/Statistic/Forecast/Regression/RegressionAbstract.php b/Math/Statistic/Forecast/Regression/RegressionAbstract.php index 8afd99c8b..2b4498956 100644 --- a/Math/Statistic/Forecast/Regression/RegressionAbstract.php +++ b/Math/Statistic/Forecast/Regression/RegressionAbstract.php @@ -6,7 +6,8 @@ use phpOMS\Math\Statistic\Average; use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier; use phpOMS\Math\Statistic\MeasureOfDispersion; -abstract class RegressionAbstract { +abstract class RegressionAbstract +{ /** * Get linear regression based on scatter plot. * @@ -22,7 +23,7 @@ abstract class RegressionAbstract { */ public static function getRegression(array $x, array $y) : array { - if(count($x) != count($y)) { + if (count($x) != count($y)) { throw new \Exception('Dimension'); } @@ -30,7 +31,7 @@ abstract class RegressionAbstract { return ['b0' => self::getBeta0($x, $y, $b1), 'b1' => $b1]; } - + /** * Standard error of the regression. * @@ -129,7 +130,7 @@ abstract class RegressionAbstract { return Average::arithmeticMean($y) - $b1 * Average::arithmeticMean($x); } - abstract public static function getSlope(float $b1, float $y, float $x) : float; + abstract public static function getSlope(float $b1, float $y, float $x) : float; - abstract public static function getElasticity(float $b1, float $y, float $x): float; + abstract public static function getElasticity(float $b1, float $y, float $x): float; } \ No newline at end of file diff --git a/Message/Mail/OAuth.php b/Message/Mail/OAuth.php index 672f31f8d..a22e473be 100644 --- a/Message/Mail/OAuth.php +++ b/Message/Mail/OAuth.php @@ -4,5 +4,5 @@ namespace phpOMS\Message\Mail; class OAuth { - + } \ No newline at end of file diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index c1b030b0c..0d790b188 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -154,9 +154,9 @@ class InstallerAbstract { $directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes'); - foreach($directories as $key => $subdir) { - if($subdir instanceof Directory) { - foreach($subdir as $key2 => $file) { + foreach ($directories as $key => $subdir) { + if ($subdir instanceof Directory) { + foreach ($subdir as $key2 => $file) { self::installRoutes(ROOT_PATH . '/' . $subdir->getName() . '/' . basename($file->getName(), '.php') . '/Routes.php', $file->getPath()); } } @@ -178,7 +178,7 @@ class InstallerAbstract */ private static function installRoutes(string $destRoutePath, string $srcRoutePath) { - if(!file_exists($destRoutePath)) { + if (!file_exists($destRoutePath)) { file_put_contents($destRoutePath, 'routes += include $path; @@ -76,7 +76,7 @@ class Router * * @param string $route Route regex * @param mixed $destination Destination e.g. Module:function & verb - * @param int $verb Request verb + * @param int $verb Request verb * * @return void * @@ -85,7 +85,7 @@ class Router */ public function add(string $route, $destination, int $verb = RouteVerb::GET) { - if(!isset($this->routes[$route])) { + if (!isset($this->routes[$route])) { $this->routes[$route] = []; } @@ -99,7 +99,7 @@ class Router * Route request. * * @param RequestAbstract $request Request to route - * @param int $verb Route verb + * @param int $verb Route verb * * @return string[] * @@ -110,10 +110,10 @@ class Router */ public function route($request, int $verb = RouteVerb::GET) : array { - if($request instanceof RequestAbstract) { - $uri = $request->getUri(); + if ($request instanceof RequestAbstract) { + $uri = $request->getUri(); $verb = $request->getRouteVerb(); - } elseif(is_string($request)) { + } elseif (is_string($request)) { $uri = $request; } else { throw new \Exception(); @@ -135,9 +135,9 @@ class Router * Match route and uri. * * @param string $route Route - * @param int $routeVerb GET,POST for this route + * @param int $routeVerb GET,POST for this route * @param string $uri Uri - * @param int $remoteVerb Verb this request is using + * @param int $remoteVerb Verb this request is using * * @return bool * diff --git a/Stdlib/Collection/Collection.php b/Stdlib/Collection/Collection.php index 838776a7a..bb6e5cb7b 100644 --- a/Stdlib/Collection/Collection.php +++ b/Stdlib/Collection/Collection.php @@ -51,6 +51,15 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab return $this->sum() / $this->count(); } + public function sum() + { + } + + public function count() + { + return count($this->collection); + } + public function chunk() { @@ -69,11 +78,6 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab { } - public function count() - { - return count($this->collection); - } - public function diff() { } @@ -85,23 +89,36 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab public function every(int $n) { $new = []; - for($i = 0; $i < $this->count(); $i += $n) { + for ($i = 0; $i < $this->count(); $i += $n) { $new[] = $this->get($i); } return new self($new); } + public function get($key) + { + if (!isset($this->collection[$key])) { + if (is_int($key) && $key < $this->count()) { + return $this->collection[array_keys($this->collection)[$key]]; + } + } else { + return $this->collection[$key]; + } + + return null; + } + public function except($filter) { - if(!is_array($filter)) { + if (!is_array($filter)) { $filter = [$filter]; } $new = []; - for($i = 0; $i < $this->count(); $i++) { + for ($i = 0; $i < $this->count(); $i++) { - if(!in_array($this->get($i), $filter)) { + if (!in_array($this->get($i), $filter)) { $new[] = $this->get($i); } } @@ -154,19 +171,6 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab { } - public function get($key) - { - if(!isset($this->collection[$key])) { - if(is_int($key) && $key < $this->count()) { - return $this->collection[array_keys($this->collection)[$key]]; - } - } else { - return $this->collection[$key]; - } - - return null; - } - public function groupBy() { } @@ -203,10 +207,6 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab { } - public function sum() - { - } - public function merge() { } diff --git a/System/File/Directory.php b/System/File/Directory.php index f3562ca4d..2e2b04ed4 100644 --- a/System/File/Directory.php +++ b/System/File/Directory.php @@ -80,7 +80,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess parent::index(); foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) { - if(!StringUtils::endsWith(trim($filename), '.') ) { + if (!StringUtils::endsWith(trim($filename), '.')) { $file = is_dir($filename) ? new self($filename) : new File($filename); $this->add($file); @@ -215,6 +215,83 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess return true; } + /** + * Get parent directory path. + * + * @param string $path Path + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function parent(string $path) : string + { + $path = explode('/', str_replace('\\', '/', $path)); + array_pop($path); + + return implode('/', $path); + } + + public static function created(string $path) : \DateTime + { + // TODO: Implement created() method. + } + + public static function changed(string $path) : \DateTime + { + // TODO: Implement changed() method. + } + + public static function owner(string $path) : int + { + // TODO: Implement owner() method. + } + + public static function permission(string $path) : int + { + // TODO: Implement permission() method. + } + + /* Iterator */ + + public static function delete(string $path) : bool + { + // TODO: Implement delete() method. + } + + public static function copy(string $from, string $to, bool $overwrite = false) : bool + { + // TODO: Implement copy() method. + } + + public static function move(string $from, string $to, bool $overwrite = false) : bool + { + // TODO: Implement move() method. + } + + public static function put(string $path, string $content, bool $overwrite = true) : bool + { + // TODO: Implement put() method. + } + + public static function get(string $path) : string + { + // TODO: Implement get() method. + } + + /* ArrayAccess */ + + public static function size(string $path) : int + { + // TODO: Implement size() method. + } + + public static function exists(string $path) : bool + { + return file_exists($path); + } + /** * Get node by name. * @@ -261,24 +338,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess return false; } - /** - * Get parent directory path. - * - * @param string $path Path - * - * @return string - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public static function parent(string $path) : string - { - $path = explode('/', str_replace('\\', '/', $path)); - array_pop($path); - - return implode('/', $path); - } - /** * Remove by name. * @@ -305,8 +364,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess return false; } - /* Iterator */ - /** * {@inheritdoc} */ @@ -349,7 +406,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess return ($key !== null && $key !== false); } - /* ArrayAccess */ /** * {@inheritdoc} */ @@ -417,59 +473,4 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess { // TODO: Implement getContent() method. } - - public static function created(string $path) : \DateTime - { - // TODO: Implement created() method. - } - - public static function changed(string $path) : \DateTime - { - // TODO: Implement changed() method. - } - - public static function owner(string $path) : int - { - // TODO: Implement owner() method. - } - - public static function permission(string $path) : int - { - // TODO: Implement permission() method. - } - - public static function delete(string $path) : bool - { - // TODO: Implement delete() method. - } - - public static function copy(string $from, string $to, bool $overwrite = false) : bool - { - // TODO: Implement copy() method. - } - - public static function move(string $from, string $to, bool $overwrite = false) : bool - { - // TODO: Implement move() method. - } - - public static function put(string $path, string $content, bool $overwrite = true) : bool - { - // TODO: Implement put() method. - } - - public static function get(string $path) : string - { - // TODO: Implement get() method. - } - - public static function size(string $path) : int - { - // TODO: Implement size() method. - } - - public static function exists(string $path) : bool - { - return file_exists($path); - } } \ No newline at end of file diff --git a/System/File/File.php b/System/File/File.php index 063046f7b..47e6c60da 100644 --- a/System/File/File.php +++ b/System/File/File.php @@ -49,16 +49,6 @@ class File extends FileAbstract } } - public function getDirName() : string - { - return basename(dirname($this->path)); - } - - public function getDirPath() : string - { - return dirname($this->path); - } - /** * Index file. * @@ -74,6 +64,155 @@ class File extends FileAbstract $this->size = filesize($this->path); } + public static function put(string $path, string $content, bool $overwrite = true) : bool + { + if ($overwrite || !file_exists($path)) { + if (!Directory::exists(dirname($path))) { + Directory::create(dirname($path), '0644', true); + } + + file_put_contents($path, $content); + + return true; + } + + return false; + } + + public static function get(string $path) : string + { + if (!file_exists($path)) { + throw new PathException($path); + } + + return file_get_contents($path); + } + + public static function exists(string $path) : bool + { + return file_exists($path); + } + + public static function parent(string $path) : string + { + return Directory::parent(dirname($path)); + } + + public static function created(string $path) : \DateTime + { + if (!file_exists($path)) { + throw new PathException($path); + } + + $created = new \DateTime(); + $created->setTimestamp(filemtime($path)); + + return $created; + } + + public static function changed(string $path) : \DateTime + { + if (!file_exists($path)) { + throw new PathException($path); + } + + $changed = new \DateTime(); + $changed->setTimestamp(filectime($path)); + + return $changed; + } + + public static function size(string $path) : int + { + if (!file_exists($path)) { + throw new PathException($path); + } + + return filesize($path); + } + + public static function owner(string $path) : int + { + if (!file_exists($path)) { + throw new PathException($path); + } + + return fileowner($path); + } + + public static function permission(string $path) : int + { + if (!file_exists($path)) { + throw new PathException($path); + } + + return fileperms($path); + } + + public static function dirname(string $path) : string + { + return dirname($path); + } + + public static function copy(string $from, string $to, bool $overwrite = false) : bool + { + if (!file_exists($from)) { + throw new PathException($from); + } + + if ($overwrite || !file_exists($to)) { + if (!Directory::exists(dirname($to))) { + Directory::create(dirname($to), '0644', true); + } + + copy($from, $to); + + return true; + } + + return false; + } + + public static function move(string $from, string $to, bool $overwrite = false) : bool + { + if (!file_exists($from)) { + throw new PathException($from); + } + + if ($overwrite || !file_exists($to)) { + if (!Directory::exists(dirname($to))) { + Directory::create(dirname($to), '0644', true); + } + + rename($from, $to); + + return true; + } + + return false; + } + + public static function delete(string $path) : bool + { + if (!file_exists($path)) { + return false; + } + + unlink($path); + + return true; + } + + public function getDirName() : string + { + return basename(dirname($this->path)); + } + + public function getDirPath() : string + { + return dirname($this->path); + } + /** * {@inheritdoc} */ @@ -82,6 +221,21 @@ class File extends FileAbstract return self::create($this->path); } + public static function create(string $path) : bool + { + if (!file_exists($path)) { + if (!Directory::exists(dirname($path))) { + Directory::create(dirname($path), '0644', true); + } + + touch($path); + + return true; + } + + return false; + } + /** * Get file content. * @@ -108,21 +262,6 @@ class File extends FileAbstract file_put_contents($this->path, $content); } - public static function put(string $path, string $content, bool $overwrite = true) : bool - { - if($overwrite || !file_exists($path)) { - if(!Directory::exists(dirname($path))) { - Directory::create(dirname($path), '0644', true); - } - - file_put_contents($path, $content); - - return true; - } - - return false; - } - public function getFileName() : string { return explode('.', $this->name)[0]; @@ -135,145 +274,6 @@ class File extends FileAbstract return $extension[1] ?? ''; } - public static function get(string $path) : string - { - if(!file_exists($path)) { - throw new PathException($path); - } - - return file_get_contents($path); - } - - public static function exists(string $path) : bool - { - return file_exists($path); - } - - public static function create(string $path) : bool - { - if(!file_exists($path)) { - if(!Directory::exists(dirname($path))) { - Directory::create(dirname($path), '0644', true); - } - - touch($path); - - return true; - } - - return false; - } - - public static function parent(string $path) : string - { - return Directory::parent(dirname($path)); - } - - public static function created(string $path) : \DateTime - { - if(!file_exists($path)) { - throw new PathException($path); - } - - $created = new \DateTime(); - $created->setTimestamp(filemtime($path)); - - return $created; - } - - public static function changed(string $path) : \DateTime - { - if(!file_exists($path)) { - throw new PathException($path); - } - - $changed = new \DateTime(); - $changed->setTimestamp(filectime($path)); - - return $changed; - } - - public static function size(string $path) : int - { - if(!file_exists($path)) { - throw new PathException($path); - } - - return filesize($path); - } - - public static function owner(string $path) : int - { - if(!file_exists($path)) { - throw new PathException($path); - } - - return fileowner($path); - } - - public static function permission(string $path) : int - { - if(!file_exists($path)) { - throw new PathException($path); - } - - return fileperms($path); - } - - public static function dirname(string $path) : string - { - return dirname($path); - } - - public static function copy(string $from, string $to, bool $overwrite = false) : bool - { - if(!file_exists($from)) { - throw new PathException($from); - } - - if($overwrite || !file_exists($to)) { - if(!Directory::exists(dirname($to))) { - Directory::create(dirname($to), '0644', true); - } - - copy($from, $to); - - return true; - } - - return false; - } - - public static function move(string $from, string $to, bool $overwrite = false) : bool - { - if(!file_exists($from)) { - throw new PathException($from); - } - - if($overwrite || !file_exists($to)) { - if(!Directory::exists(dirname($to))) { - Directory::create(dirname($to), '0644', true); - } - - rename($from, $to); - - return true; - } - - return false; - } - - public static function delete(string $path) : bool - { - if(!file_exists($path)) { - return false; - } - - unlink($path); - - return true; - } - public function getParent() : FileInterface { // TODO: Implement getParent() method. diff --git a/System/File/FileInterface.php b/System/File/FileInterface.php index c3518ed3b..76af1146c 100644 --- a/System/File/FileInterface.php +++ b/System/File/FileInterface.php @@ -30,61 +30,61 @@ namespace phpOMS\System\File; */ interface FileInterface { - public function getCount() : int; + public static function created(string $path) : \DateTime; - public function getSize() : int; + public static function changed(string $path) : \DateTime; - public function getName() : string; + public static function owner(string $path) : int; - public function getPath() : string; + public static function permission(string $path) : int; - public function getParent() : FileInterface; + public static function parent(string $path) : string; - public function createNode() : bool; + public static function create(string $path) : bool; - public function copyNode() : bool; + public static function delete(string $path) : bool; - public function moveNode() : bool; + public static function copy(string $from, string $to, bool $overwrite = false) : bool; - public function deleteNode() : bool; + public static function move(string $from, string $to, bool $overwrite = false) : bool; - public function putContent() : bool; + public static function put(string $path, string $content, bool $overwrite = true) : bool; - public function getContent() : string; + public static function get(string $path) : string; - public function getCreatedAt() : \DateTime; + public static function size(string $path) : int; - public function getChangedAt() : \DateTime; + public static function exists(string $path) : bool; - public function getOwner() : int; + public function getCount() : int; - public function getPermission() : string; + public function getSize() : int; - public function index(); + public function getName() : string; - public static function created(string $path) : \DateTime; + public function getPath() : string; - public static function changed(string $path) : \DateTime; + public function getParent() : FileInterface; - public static function owner(string $path) : int; + public function createNode() : bool; - public static function permission(string $path) : int; + public function copyNode() : bool; - public static function parent(string $path) : string; + public function moveNode() : bool; - public static function create(string $path) : bool; + public function deleteNode() : bool; - public static function delete(string $path) : bool; + public function putContent() : bool; - public static function copy(string $from, string $to, bool $overwrite = false) : bool; + public function getContent() : string; - public static function move(string $from, string $to, bool $overwrite = false) : bool; + public function getCreatedAt() : \DateTime; - public static function put(string $path, string $content, bool $overwrite = true) : bool; + public function getChangedAt() : \DateTime; - public static function get(string $path) : string; + public function getOwner() : int; - public static function size(string $path) : int; + public function getPermission() : string; - public static function exists(string $path) : bool; + public function index(); } diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 50046873a..751b1ec1b 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -94,7 +94,7 @@ class UriFactory * . = DOM class * / = Current path * ? = Current query - * @ = + * @ = * $ = Other data * * @param string $uri Path data diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index b9d847c49..3a752229a 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -239,10 +239,10 @@ class ArrayUtils */ public static function getArg(string $id, array $args) { - if(($key = array_search($id, $args)) === false || $key === count($args) - 1) { + if (($key = array_search($id, $args)) === false || $key === count($args) - 1) { return null; } - return trim($args[$key+1], '" '); + return trim($args[$key + 1], '" '); } } diff --git a/Utils/Compression/LZW.php b/Utils/Compression/LZW.php index 62804fee2..3f8c017ff 100644 --- a/Utils/Compression/LZW.php +++ b/Utils/Compression/LZW.php @@ -81,8 +81,8 @@ class LZW implements CompressionInterface $w = chr($compressed[0]); $result = $w; - $count = count($compressed); - + $count = count($compressed); + for ($i = 1; $i < $count; $i++) { $k = $compressed[$i]; @@ -90,7 +90,7 @@ class LZW implements CompressionInterface $entry = $dictionary[$k]; } else { if ($k !== $dictSize) { - throw new \Exception('Wrong dictionary size!'. $k . '.' . $dictSize); + throw new \Exception('Wrong dictionary size!' . $k . '.' . $dictSize); } $entry = $w . $w[0]; diff --git a/Utils/Converter/Ip.php b/Utils/Converter/Ip.php index af243582f..ec06496dd 100644 --- a/Utils/Converter/Ip.php +++ b/Utils/Converter/Ip.php @@ -31,48 +31,44 @@ class Ip const IP_TABLE_PATH = __DIR__ . '/../../Localization/Default/Ip/ipGeoLocation.csv'; const IP_TABLE_ITERATIONS = 100; - private function __construct() {} - - public static function ip2Float(string $ip) : float + private function __construct() { - $split = explode('.', $ip); - return $split[0] * (256 ** 3) + $split[1] * (256 ** 2) + $split[2] * (256 ** 1) + $split[3]; } - public static function ip2Country(string $ip) : string + public static function ip2Country(string $ip) : string { $fh = fopen(self::IP_TABLE_PATH, 'r'); fseek($fh, 0, SEEK_END); $end = ftell($fh); fseek($fh, 0); - $start = 0; + $start = 0; $current = $start; - $ip = self::ip2Float($ip); + $ip = self::ip2Float($ip); $country = ''; $counter = 0; - while($counter < self::IP_TABLE_ITERATIONS) { + while ($counter < self::IP_TABLE_ITERATIONS) { $line = fgets($fh, 150); - if($current !== 0) { + if ($current !== 0) { $line = fgets($fh, 150); } $split = explode(',', $line); - if($ip >= $split[0] && $ip <= $split[1]) { + if ($ip >= $split[0] && $ip <= $split[1]) { $country = $split[2]; break; } - if($ip > $split[1]) { + if ($ip > $split[1]) { $larger = true; - $start = $current; + $start = $current; fseek($fh, ($end - $current) / 2, SEEK_CUR); } else { $larger = false; - $end = $current; + $end = $current; fseek($fh, ($start - $current) / 2, SEEK_CUR); } @@ -84,4 +80,11 @@ class Ip return $country; } + + public static function ip2Float(string $ip) : float + { + $split = explode('.', $ip); + + return $split[0] * (256 ** 3) + $split[1] * (256 ** 2) + $split[2] * (256 ** 1) + $split[3]; + } } \ No newline at end of file diff --git a/Utils/Git/Repository.php b/Utils/Git/Repository.php index d0ddc68cc..c56655b97 100644 --- a/Utils/Git/Repository.php +++ b/Utils/Git/Repository.php @@ -642,7 +642,7 @@ class Repository continue; } - if(!file_exists($path = $this->getDirectoryPath() . ($this->bare ? '/' : '/../') . $line)) { + if (!file_exists($path = $this->getDirectoryPath() . ($this->bare ? '/' : '/../') . $line)) { return 0; } diff --git a/Utils/JobQueue/JobQueue.php b/Utils/JobQueue/JobQueue.php index c0cace183..0c8ebb7eb 100644 --- a/Utils/JobQueue/JobQueue.php +++ b/Utils/JobQueue/JobQueue.php @@ -86,6 +86,21 @@ class JobQueue sleep(1); } + private function runAsDeamon() + { + ob_end_clean(); + fclose(STDIN); + fclose(STDOUT); + fclose(STDERR); + + function shutdown() + { + posix_kill(posix_getpid(), SIGHUP); + } + + register_shutdown_function('shutdown'); + } + public function setRunning(bool $run = true) { $this->run = $run; @@ -97,16 +112,16 @@ class JobQueue return $this->run; } - public function setSuspended(bool $suspended = true) - { - $this->suspended = $suspended; - } - public function isSuspended() : bool { return $this->suspended; } + public function setSuspended(bool $suspended = true) + { + $this->suspended = $suspended; + } + public function isTerminating() : bool { return $this->isTerminating; @@ -127,21 +142,6 @@ class JobQueue $this->isDeamonized = $deamonized; } - private function runAsDeamon() - { - ob_end_clean(); - fclose(STDIN); - fclose(STDOUT); - fclose(STDERR); - - function shutdown() - { - posix_kill(posix_getpid(), SIGHUP); - } - - register_shutdown_function('shutdown'); - } - private function savePid() { // todo: save pid somewhere for kill diff --git a/Validation/Barcode/Barcode39.php b/Validation/Barcode/Barcode39.php index 2cc2d5445..f14371b2f 100644 --- a/Validation/Barcode/Barcode39.php +++ b/Validation/Barcode/Barcode39.php @@ -19,5 +19,5 @@ use phpOMS\Validation\ValidatorAbstract; class Barcode39 extends ValidatorAbstract { - + } \ No newline at end of file diff --git a/Validation/Base/Iban.php b/Validation/Base/Iban.php index ef931541b..058da289b 100644 --- a/Validation/Base/Iban.php +++ b/Validation/Base/Iban.php @@ -51,7 +51,7 @@ abstract class Iban extends ValidatorAbstract */ public static function isValid($value) : bool { - $value = str_replace(' ', '', strtolower($value)); + $value = str_replace(' ', '', strtolower($value)); $enumName = 'C_' . strtoupper(substr($value, 0, 2)); if (!IbanEnum::isValidName($enumName)) { diff --git a/Validation/BitcoinValidator.php b/Validation/BitcoinValidator.php index f7d9319ab..d455c3591 100644 --- a/Validation/BitcoinValidator.php +++ b/Validation/BitcoinValidator.php @@ -53,6 +53,7 @@ class BitcoinValidator extends ValidatorAbstract return true; } catch (\Exception $e) { self::$msg = $e->getMessage(); + return false; } } diff --git a/Validation/Validator.php b/Validation/Validator.php index cbf76f938..b792a418a 100644 --- a/Validation/Validator.php +++ b/Validation/Validator.php @@ -14,6 +14,7 @@ * @link http://orange-management.com */ namespace phpOMS\Validation; + use phpOMS\Utils\StringUtils; /** diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index 2c815db5b..796cc6353 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -57,6 +57,26 @@ abstract class ViewAbstract implements \Serializable { } + /** + * Sort views by order. + * + * @param array $a Array 1 + * @param array $b Array 2 + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + private static function viewSort(array $a, array $b) : int + { + if ($a['order'] === $b['order']) { + return 0; + } + + return ($a['order'] < $b['order']) ? -1 : 1; + } + /** * Get the template. * @@ -85,26 +105,6 @@ abstract class ViewAbstract implements \Serializable $this->template = $template; } - /** - * Sort views by order. - * - * @param array $a Array 1 - * @param array $b Array 2 - * - * @return int - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - private static function viewSort(array $a, array $b) : int - { - if ($a['order'] === $b['order']) { - return 0; - } - - return ($a['order'] < $b['order']) ? -1 : 1; - } - /** * @return View[] * @@ -195,6 +195,25 @@ abstract class ViewAbstract implements \Serializable } } + /** + * Serialize view for rendering. + * + * @return string|array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function serialize() + { + $path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php'); + + if ($path === false) { + return $this->toArray(); + } + + return $this->render(); + } + /** * Arrayify view and it's subviews. * @@ -207,7 +226,7 @@ abstract class ViewAbstract implements \Serializable { $viewArray = []; - if($this->template !== '') { + if ($this->template !== '') { $viewArray[] = $this->render(); } @@ -246,25 +265,6 @@ abstract class ViewAbstract implements \Serializable return $ob; } - /** - * Serialize view for rendering. - * - * @return string|array - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function serialize() - { - $path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php'); - - if ($path === false) { - return $this->toArray(); - } - - return $this->render(); - } - /** * Unserialize view. *