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 @@ use phpOMS\Stdlib\Base\Enum; */ abstract class AccountStatus extends Enum { - /* public */ const ACTIVE = 1; - /* public */ const INACTIVE = 2; - /* public */ const TIMEOUT = 3; - /* public */ const BANNED = 4; + /* public */ const ACTIVE = 1; + /* public */ const INACTIVE = 2; + /* public */ const TIMEOUT = 3; + /* public */ const BANNED = 4; } 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 @@ use phpOMS\Stdlib\Base\Enum; */ abstract class AccountType extends Enum { - /* public */ const USER = 0; - /* public */ const GROUP = 1; + /* public */ const USER = 0; + /* public */ const GROUP = 1; } 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 @@ use phpOMS\Stdlib\Base\Enum; */ abstract class GroupStatus extends Enum { - /* public */ const ACTIVE = 1; - /* public */ const INACTIVE = 2; - /* public */ const HIDDEN = 4; + /* public */ const ACTIVE = 1; + /* public */ const INACTIVE = 2; + /* public */ const HIDDEN = 4; } 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 @@ use phpOMS\Stdlib\Base\Enum; */ abstract class AssetType extends Enum { - /* public */ const CSS = 0; - /* public */ const JS = 1; - /* public */ const JSLATE = 2; + /* public */ const CSS = 0; + /* public */ const JS = 1; + /* public */ const JSLATE = 2; } 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; 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 @@ class DataMapperAbstract implements DataMapperInterface // todo: how to handle with of parent objects/extends/relations self::$fields = $objects; - - //return __CLASS__; } /** 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 @@ declare(strict_types=1); namespace phpOMS\DataStorage\Database\Query\Grammar; -class GrammarInterface +interface GrammarInterface { } 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 @@ class Polygon implements D2ShapeInterface * @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 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 @@ class LUDecomposition 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 @@ class LUDecomposition 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 @@ class LUDecomposition if (!$this->isNonsingular()) { } - var_dump($this->piv); - $nx = $B->getM(); $X = $B->getMatrix($this->piv, 0, $nx-1); 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 @@ class QRDecomposition 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 @@ class QRDecomposition 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 @@ class QRDecomposition 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) { 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 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 @@ class MeasureOfDispersion $end = end($values); $start = reset($values); - return $start - $end; + return $end - $start; } /** diff --git a/Message/Http/Response.php b/Message/Http/Response.php index 1a0569606..a1576e4ce 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -147,6 +147,12 @@ class Response extends ResponseAbstract implements RenderableInterface return trim(preg_replace('/(\s{2,}|\n)(?![^<>]*<\/pre>)/', ' ', $render); } + $types = $this->header->get('Content-Type'); + + if(stripos($types[0], MimeType::M_HTML) !== false) { + return trim(preg_replace('/(\s{2,}|\n|\t)(?![^<>]*<\/pre>)/', ' ', $render)); + } + return $render; } 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 @@ class InfoManager */ public function update() /* : void */ { - if (!file_exists($this->path)) { + if (!file_exists($this->path)) { throw new PathException((string) $this->path); } 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 @@ class ModuleManager 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 @@ class ModuleManager */ 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); } 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 @@ use phpOMS\Stdlib\Base\Enum; */ 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 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 @@ class SystemUtils { $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); 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 @@ class ArrayUtils } /** - * 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 @@ class ArrayUtils 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. * 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 @@ class JobQueue 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 */