From 7613a42504327b0da54256fce79389e5f69c92e6 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 23 Oct 2017 17:30:52 +0200 Subject: [PATCH 01/15] Fix calculation --- Math/Statistic/Average.php | 4 ++-- Math/Statistic/MeasureOfDispersion.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php index 0bcd1674d..afd73e357 100644 --- a/Math/Statistic/Average.php +++ b/Math/Statistic/Average.php @@ -52,11 +52,11 @@ class Average * * @since 1.0.0 */ - public static function averageChange(array $x, int $h = 1) : float + public static function averageDatasetChange(array $x, int $h = 1) : float { $count = count($x); - return $x[$count - 1] + $h * ($x[$count - 1] - $x[0]) / ($count - 1); + return $h * ($x[$count - 1] - $x[0]) / ($count - 1); } /** diff --git a/Math/Statistic/MeasureOfDispersion.php b/Math/Statistic/MeasureOfDispersion.php index 09bc6d104..b74d931ec 100644 --- a/Math/Statistic/MeasureOfDispersion.php +++ b/Math/Statistic/MeasureOfDispersion.php @@ -47,7 +47,7 @@ public static function range(array $values) : float $end = end($values); $start = reset($values); - return $start - $end; + return $end - $start; } /** From d73e65fd09c6a98f3833fb3061ea74c3eaffac59 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 23 Oct 2017 17:30:57 +0200 Subject: [PATCH 02/15] Add docblock --- Math/Geometry/Shape/D2/Polygon.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Math/Geometry/Shape/D2/Polygon.php b/Math/Geometry/Shape/D2/Polygon.php index a003b6341..d66af7210 100644 --- a/Math/Geometry/Shape/D2/Polygon.php +++ b/Math/Geometry/Shape/D2/Polygon.php @@ -138,7 +138,8 @@ public function pointInPolygon(array $point) : int * @param array $polygon Polygon definition * * @return int - * + * + * @link http://erich.realtimerendering.com/ptinpoly/ * @since 1.0.0 */ public static function isPointInPolygon(array $point, array $polygon) : int From 19afa91ee7f0c7bdac9c90a01581bae4c51c6526 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 23 Oct 2017 17:31:05 +0200 Subject: [PATCH 03/15] Add function --- Utils/ArrayUtils.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 0f66a1faf..a618f65fe 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -74,7 +74,7 @@ public static function unsetArray(string $path, array $data, string $delim = '/' } /** - * Check if needle exists in multidimensional array. + * Set element in array by path * * @param string $path Path to element * @param array $data Array @@ -112,6 +112,29 @@ public static function setArray(string $path, array $data, $value, string $delim return $data; } + /** + * Get element of array by path + * + * @param string $path Path to element + * @param array $data Array + * @param string $delim Delimiter for path + * + * @return mixed + * + * @since 1.0.0 + */ + public static function getArray(string $path, array $data, string $delim = '/') + { + $pathParts = explode($delim, trim($path, $delim)); + $current = $data; + + foreach ($pathParts as $key) { + $current = $current[$key]; + } + + return $current; + } + /** * Check if needle exists in multidimensional array. * From 2bb6eeb5429643c0ed219405e89382acf81b1667 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 24 Oct 2017 17:37:48 +0200 Subject: [PATCH 04/15] Fix html render optimization --- Message/Http/Response.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Message/Http/Response.php b/Message/Http/Response.php index 0b8a5020a..c92c3ede4 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -141,6 +141,12 @@ private function getRaw() : string } } + $types = $this->header->get('Content-Type'); + + if(stripos($types[0], MimeType::M_HTML) !== false) { + return trim(preg_replace('/(\s{2,}|\n)(?![^<>]*<\/pre>)/', ' ', $render)); + } + return $render; } From 546fe210f78e111c12bb9da04d7aec7edbd04587 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 24 Oct 2017 17:41:57 +0200 Subject: [PATCH 05/15] Also replace tabs --- Message/Http/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Message/Http/Response.php b/Message/Http/Response.php index c92c3ede4..deeb020e4 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -144,7 +144,7 @@ private function getRaw() : string $types = $this->header->get('Content-Type'); if(stripos($types[0], MimeType::M_HTML) !== false) { - return trim(preg_replace('/(\s{2,}|\n)(?![^<>]*<\/pre>)/', ' ', $render)); + return trim(preg_replace('/(\s{2,}|\n|\t)(?![^<>]*<\/pre>)/', ' ', $render)); } return $render; From 48d742d68f0cbf6450260adffc42c106e724fa1b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 24 Oct 2017 17:45:56 +0200 Subject: [PATCH 06/15] Fix tabs to whitespace --- Account/AccountStatus.php | 8 ++++---- Account/AccountType.php | 4 ++-- Account/GroupStatus.php | 6 +++--- Asset/AssetType.php | 6 +++--- Module/InfoManager.php | 2 +- System/SystemType.php | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Account/AccountStatus.php b/Account/AccountStatus.php index e8d8efd75..ca92e63a9 100644 --- a/Account/AccountStatus.php +++ b/Account/AccountStatus.php @@ -28,8 +28,8 @@ */ 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; } diff --git a/Account/AccountType.php b/Account/AccountType.php index 93a963465..a4298d5dc 100644 --- a/Account/AccountType.php +++ b/Account/AccountType.php @@ -28,6 +28,6 @@ */ abstract class AccountType extends Enum { - /* public */ const USER = 0; - /* public */ const GROUP = 1; + /* public */ const USER = 0; + /* public */ const GROUP = 1; } diff --git a/Account/GroupStatus.php b/Account/GroupStatus.php index 0af5c9655..42c6ff1f1 100644 --- a/Account/GroupStatus.php +++ b/Account/GroupStatus.php @@ -28,7 +28,7 @@ */ 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; } diff --git a/Asset/AssetType.php b/Asset/AssetType.php index 95fd69919..825d958a8 100644 --- a/Asset/AssetType.php +++ b/Asset/AssetType.php @@ -28,7 +28,7 @@ */ 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; } diff --git a/Module/InfoManager.php b/Module/InfoManager.php index 70c5bcda8..f7ff08fef 100644 --- a/Module/InfoManager.php +++ b/Module/InfoManager.php @@ -99,7 +99,7 @@ public function load() /* : void */ */ public function update() /* : void */ { - if (!file_exists($this->path)) { + if (!file_exists($this->path)) { throw new PathException((string) $this->path); } diff --git a/System/SystemType.php b/System/SystemType.php index 5c630fe64..24aa27dd2 100644 --- a/System/SystemType.php +++ b/System/SystemType.php @@ -30,8 +30,8 @@ */ abstract class SystemType extends Enum { - /* public */ const UNKNOWN = 1; - /* public */ const WIN = 2; - /* public */ const LINUX = 3; - /* public */ const OSX = 4; + /* public */ const UNKNOWN = 1; + /* public */ const WIN = 2; + /* public */ const LINUX = 3; + /* public */ const OSX = 4; } \ No newline at end of file From 3365b59837b939a755a7242afdae541e70accc73 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 18:29:05 +0200 Subject: [PATCH 07/15] Fix #125 --- DataStorage/Database/DataMapperAbstract.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 8c7e7abd6..16b370786 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -269,8 +269,6 @@ public static function with(...$objects) /* : void */ // todo: how to handle with of parent objects/extends/relations self::$fields = $objects; - - //return __CLASS__; } /** From f1e6e7a63b384aab9e8853dc4dd7a9a1da0caccd Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 18:53:26 +0200 Subject: [PATCH 08/15] Fix #127 --- Math/Matrix/LUDecomposition.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Math/Matrix/LUDecomposition.php b/Math/Matrix/LUDecomposition.php index 6517f2c4d..2924ec455 100644 --- a/Math/Matrix/LUDecomposition.php +++ b/Math/Matrix/LUDecomposition.php @@ -84,6 +84,8 @@ public function __construct(Matrix $M) public function getL() { + $L = [[]]; + for ($i = 0; $i < $this->m; ++$i) { for ($j = 0; $j < $this->n; ++$j) { if ($i > $j) { @@ -104,6 +106,8 @@ public function getL() public function getU() { + $U = [[]]; + for ($i = 0; $i < $this->n; ++$i) { for ($j = 0; $j < $this->n; ++$j) { if ($i <= $j) { @@ -154,8 +158,6 @@ public function solve(Matrix $B) if (!$this->isNonsingular()) { } - var_dump($this->piv); - $nx = $B->getM(); $X = $B->getMatrix($this->piv, 0, $nx-1); From 75f86a29bab36bc4ef144a03ea179be76fb2c3e5 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 18:54:46 +0200 Subject: [PATCH 09/15] Fix #128 --- Math/Matrix/QRDecomposition.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Math/Matrix/QRDecomposition.php b/Math/Matrix/QRDecomposition.php index fb735ad08..bdbb71e84 100644 --- a/Math/Matrix/QRDecomposition.php +++ b/Math/Matrix/QRDecomposition.php @@ -81,6 +81,8 @@ public function isFullRank() : bool public function getH() { + $H = [[]]; + for ($i = 0; $i < $this->m; ++$i) { for ($j = 0; $j < $this->n; ++$j) { if ($i >= $j) { @@ -99,6 +101,8 @@ public function getH() public function getR() { + $R = [[]]; + for ($i = 0; $i < $this->n; ++$i) { for ($j = 0; $j < $this->n; ++$j) { if ($i < $j) { @@ -119,10 +123,13 @@ public function getR() public function getQ() { + $Q = [[]]; + for ($k = $this->n-1; $k >= 0; --$k) { for ($i = 0; $i < $this->m; ++$i) { $Q[$i][$k] = 0.0; - } + } + $Q[$k][$k] = 1.0; for ($j = $k; $j < $this->n; ++$j) { if ($this->QR[$k][$k] != 0) { From 9cec1628b78ed386d3e802f17d4bb305bfa2057f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 18:58:13 +0200 Subject: [PATCH 10/15] Fix #130 --- DataStorage/Database/Connection/ConnectionAbstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataStorage/Database/Connection/ConnectionAbstract.php b/DataStorage/Database/Connection/ConnectionAbstract.php index 20f4379a7..90c3c88f4 100644 --- a/DataStorage/Database/Connection/ConnectionAbstract.php +++ b/DataStorage/Database/Connection/ConnectionAbstract.php @@ -89,7 +89,7 @@ abstract class ConnectionAbstract implements ConnectionInterface /** * Database grammar. * - * @var Grammar + * @var SchemaGrammar * @since 1.0.0 */ protected $schemaGrammar = null; From 4a766b6cf004b29ccedb017aa868599a65167aa1 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 19:01:09 +0200 Subject: [PATCH 11/15] Fix #132 --- Module/ModuleManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index 9f605b25b..9af363de9 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -419,13 +419,13 @@ private function activateModule(InfoManager $info) /* : void */ public function reInit(string $module) : bool { $info = $this->loadInfo($module); - /** @var $class InstallerAbstract */ $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer'; if (!Autoloader::exists($class)) { throw new InvalidModuleException($info->getDirectory()); } + /** @var $class InstallerAbstract */ $class::reInit($this->modulePath, $info); } @@ -511,13 +511,13 @@ private function installDependencies(array $dependencies) /* : void */ */ private function installModule(InfoManager $info) /* : void */ { - /** @var $class InstallerAbstract */ $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer'; if (!Autoloader::exists($class)) { throw new InvalidModuleException($info->getDirectory()); } + /** @var $class InstallerAbstract */ $class::install($this->modulePath, $this->app->dbPool, $info); } From 955dd9c05263aec960d4000d01cdc5780101d081 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 19:05:11 +0200 Subject: [PATCH 12/15] Fix #133 --- Utils/JobQueue/JobQueue.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Utils/JobQueue/JobQueue.php b/Utils/JobQueue/JobQueue.php index 0ac7b16d0..bbb5df5b7 100644 --- a/Utils/JobQueue/JobQueue.php +++ b/Utils/JobQueue/JobQueue.php @@ -91,12 +91,7 @@ private function runAsDeamon() fclose(STDOUT); fclose(STDERR); - function shutdown() - { - posix_kill(posix_getpid(), SIGHUP); - } - - register_shutdown_function('shutdown'); + register_shutdown_function(function() { posix_kill(posix_getpid(), SIGHUP); }); } public function setRunning(bool $run = true) /* : void */ From 2e1fd6b1ca6f485eec060aca1bd3df345461bb98 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 19:08:45 +0200 Subject: [PATCH 13/15] Fix #134 --- Math/Optimization/Graph/Graph.php | 222 ------------------------------ 1 file changed, 222 deletions(-) delete mode 100644 Math/Optimization/Graph/Graph.php diff --git a/Math/Optimization/Graph/Graph.php b/Math/Optimization/Graph/Graph.php deleted file mode 100644 index 1cd85c6c3..000000000 --- a/Math/Optimization/Graph/Graph.php +++ /dev/null @@ -1,222 +0,0 @@ -edges = new MultiMap(KeyType::MULTIPLE, OrderType::LOOSE); - } - - /** - * Add vertice to graph. - * - * @param VerticeInterface $vertice Vertice - * - * @return bool - * - * @since 1.0.0 - */ - public function addVertice(VerticeInterface $vertice) : bool - { - if (!isset($this->vertices[$vertice->getId()])) { - $this->vertices[$vertice->getId()] = $vertice; - - return true; - } - - return false; - } - - /** - * Add edge to graph. - * - * @param EdgeInterface $edge Edge - * - * @return bool - * - * @since 1.0.0 - */ - public function addEdge(EdgeInterface $edge) : bool - { - if (!isset($this->edges[$edge->getId()])) { - $this->edges[$edge->getId()] = $edge; - - return true; - } - - return false; - } - - /** - * Remove vertice from graph. - * - * @param mixed $id Id of vertice to remove - * - * @return bool - * - * @since 1.0.0 - */ - public function removeVertice($id) : bool - { - if (isset($this->vertices[$id])) { - unset($this->vertices[$id]); - - return true; - } - - return false; - } - - /** - * Remove edge by nodes from graph. - * - * @param mixed $a First node of edge - * @param mixed $b Second node of edge - * - * @return bool - * - * @since 1.0.0 - */ - public function removeEdge($a, $b) : bool - { - return $this->edges->remove([$a, $b]); - } - - /** - * Remove edge from graph. - * - * @param mixed $id Id of edge to remove - * - * @return bool - * - * @since 1.0.0 - */ - public function removeEdgeById($id) : bool - { - if (isset($this->edges[$id])) { - unset($this->edges[$id]); - - return true; - } - - return false; - } - - /** - * Get vertice. - * - * @param mixed $id Id of vertice - * - * @return VerticeInterface - * - * @since 1.0.0 - */ - public function getVertice($id) : VerticeInterface - { - return $this->vertices[$id] ?? new NullVertice(); - } - - /** - * Get edge by nodes. - * - * Order of nodes is irrelevant - * - * @param mixed $a First node of edge - * @param mixed $b Second node of edge - * - * @return EdgeInterface - * - * @since 1.0.0 - */ - public function getEdge($a, $b) : EdgeInterface - { - return $this->edges->get([$a, $b]) ?? new NullEdge(); - } - - /** - * Get edge by id. - * - * @param int $id Edge id - * - * @return EdgeInterface - * - * @since 1.0.0 - */ - public function getEdgeById(int $id) : EdgeInterface - { - return $this->edges->get($id) ?? new NullEdge(); - } - - /** - * Count vertices. - * - * @return int - * - * @since 1.0.0 - */ - public function countVertices() : int - { - return count($this->vertices); - } - - /** - * Count edges. - * - * @return int - * - * @since 1.0.0 - */ - public function countEdges() : int - { - return count($this->edges); - } -} \ No newline at end of file From 8129077da572728ce986c1a072ca9da42e6f1b74 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 19:12:04 +0200 Subject: [PATCH 14/15] Fix #135 --- DataStorage/Database/Query/Grammar/GrammarInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataStorage/Database/Query/Grammar/GrammarInterface.php b/DataStorage/Database/Query/Grammar/GrammarInterface.php index 234da813f..1624f18bd 100644 --- a/DataStorage/Database/Query/Grammar/GrammarInterface.php +++ b/DataStorage/Database/Query/Grammar/GrammarInterface.php @@ -15,6 +15,6 @@ namespace phpOMS\DataStorage\Database\Query\Grammar; -class GrammarInterface +interface GrammarInterface { } From be140913653b8ba7a71fc34360ed14ed0d7afd5f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Oct 2017 19:16:05 +0200 Subject: [PATCH 15/15] Fix #140 --- System/SystemUtils.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/System/SystemUtils.php b/System/SystemUtils.php index e7e80cc49..b487aa92b 100644 --- a/System/SystemUtils.php +++ b/System/SystemUtils.php @@ -79,9 +79,7 @@ public static function getRAMUsage() : int { $memusage = 0; - if (stristr(PHP_OS, 'WIN')) { - - } elseif (stristr(PHP_OS, 'LINUX')) { + if (stristr(PHP_OS, 'LINUX')) { $free = shell_exec('free'); $free = (string) trim($free); $free_arr = explode("\n", $free);