From 0422411c898671e13c4843a2c57a5ca6ed08f602 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 7 Oct 2019 22:22:41 +0200 Subject: [PATCH] phpstan fixes --- Algorithm/Knappsack/Backpack.php | 81 +++++++-- Algorithm/PathFinding/AStar.php | 12 +- Algorithm/PathFinding/Grid.php | 27 ++- Algorithm/PathFinding/JumpPointSearch.php | 159 ++++++++++-------- Algorithm/PathFinding/Path.php | 4 + Algorithm/PathFinding/PathFinderInterface.php | 15 ++ Business/Finance/Depreciation.php | 10 ++ Business/Finance/FinanceFormulas.php | 9 + Business/Finance/Loan.php | 10 ++ Business/Finance/Lorenzkurve.php | 10 ++ Business/Finance/StockBonds.php | 10 ++ Business/Marketing/Metrics.php | 1 + Business/Programming/Metrics.php | 1 + Business/Sales/MarketShareEstimation.php | 1 + Config/SettingsAbstract.php | 4 +- DataStorage/Database/BuilderAbstract.php | 14 +- DataStorage/Database/DataMapperAbstract.php | 7 +- DataStorage/Database/DatabasePool.php | 7 +- DataStorage/Database/GrammarAbstract.php | 2 +- .../Database/Query/Grammar/Grammar.php | 8 +- .../Query/Grammar/MicrosoftGrammar.php | 2 +- .../Database/Query/Grammar/MysqlGrammar.php | 2 +- .../Database/Query/Grammar/OracleGrammar.php | 2 +- .../Query/Grammar/PostgresGrammar.php | 2 +- .../Database/Query/Grammar/SQLiteGrammar.php | 2 +- DataStorage/Database/Schema/Field.php | 27 +++ .../Database/Schema/Grammar/MysqlGrammar.php | 2 +- DataStorage/Database/Schema/Table.php | 27 +++ DataStorage/Database/SchemaMapper.php | 10 +- Module/ModuleManager.php | 6 +- Stdlib/Base/Heap.php | 10 +- 31 files changed, 354 insertions(+), 130 deletions(-) create mode 100644 DataStorage/Database/Schema/Field.php create mode 100644 DataStorage/Database/Schema/Table.php diff --git a/Algorithm/Knappsack/Backpack.php b/Algorithm/Knappsack/Backpack.php index a47a98622..37c0e0fe6 100644 --- a/Algorithm/Knappsack/Backpack.php +++ b/Algorithm/Knappsack/Backpack.php @@ -14,10 +14,10 @@ declare(strict_types=1); -namespace phpOMS\Algorithm\Backpack; +namespace phpOMS\Algorithm\Knappsack; /** - * Matching a value with a set of coins + * Backpack for the Knappsack problem * * @package phpOMS\Algorithm\Knappsack * @license OMS License 1.0 @@ -26,38 +26,99 @@ namespace phpOMS\Algorithm\Backpack; */ class Backpack { - private $maxCost = 0.0; + /** + * Maximum amount of cost this backpack can hold + * + * @var float + * @since 1.0.0 + */ + private float $maxCost = 0.0; - private $value = 0.0; + /** + * Current value + * + * @var float + * @since 1.0.0 + */ + private float $value = 0.0; - private $cost = 0.0; + /** + * Current cost + * + * @var float + * @since 1.0.0 + */ + private float $cost = 0.0; + /** + * Items inside the backpack + * + * @var Item[] + * @since 1.0.0 + */ private array $items = []; - public function __construct($maxCost) + /** + * Constructor. + * + * @param float $maxCost Maximum amount of costs the backpack can hold + * + * @since 1.0.0 + */ + public function __construct(float $maxCost) { $this->maxCost = $maxCost; } - public function getValue() + /** + * Get the value of the stored items + * + * @return float + * + * @since 1.0.0 + */ + public function getValue() : float { return $this->value; } - public function getCost() + /** + * Get the cost of the stored items + * + * @return float + * + * @since 1.0.0 + */ + public function getCost() : float { return $this->cost; } + /** + * Get items + * + * @return array + * + * @since 1.0.0 + */ public function getItems() : array { return $this->items; } + /** + * Add item to backpack + * + * @param Item $item Item + * + * @return void + * + * @since 1.0.0 + */ public function addItem(Item $item) : void { $this->items[] = $item; - $this->value += $item->getValue(); - $this->cost += $item->getCost(); + $this->value += $item->getValue(); + $this->cost += $item->getCost(); } } diff --git a/Algorithm/PathFinding/AStar.php b/Algorithm/PathFinding/AStar.php index 64b898053..698760f08 100644 --- a/Algorithm/PathFinding/AStar.php +++ b/Algorithm/PathFinding/AStar.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace phpOMS\Algorithm\PathFinding; +use phpOMS\Stdlib\Base\Heap; + /** * Perform path finding. * @@ -24,14 +26,19 @@ namespace phpOMS\Algorithm\PathFinding; */ class JumpPointSearch implements PathFinderInterface { + /** + * {@inheritdoc} + */ public static function findPath( int $startX, int $startY, int $endX, int $endY, Grid $grid, int $heuristic, int $movement ) : Path { + /** @var null|AStarNode $startNode */ $startNode = $grid->getNode($startX, $startY); - $endNode = $grid->getNode($endX, $endY); + /** @var null|AStarNode $endNode */ + $endNode = $grid->getNode($endX, $endY); if ($startNode === null || $endNode === null) { return new Path($grid); @@ -41,8 +48,9 @@ class JumpPointSearch implements PathFinderInterface $startNode->setF(0.0); $startNode->setOpened(true); - $openList = new Heap(function($node1, $node2) { return $node1->getF() - $node2->getF(); }); + $openList = new Heap(function(AStarNode $node1, AStarNode $node2) { return $node1->getF() - $node2->getF(); }); $openList->push($startNode); + $node = null; while (!$openList->isEmpty()) { diff --git a/Algorithm/PathFinding/Grid.php b/Algorithm/PathFinding/Grid.php index 3a450cd71..c80941125 100644 --- a/Algorithm/PathFinding/Grid.php +++ b/Algorithm/PathFinding/Grid.php @@ -51,7 +51,7 @@ class Grid public function getNode(int $x, int $y) : ?Node { - if (!isset($this->nodes[$y]) || $this->nodes[$y][$x]) { + if (!isset($this->nodes[$y]) || !isset($this->nodes[$y][$x])) { // todo: add null node to grid because we need to modify some properties later on and remember them! return null; } @@ -59,6 +59,15 @@ class Grid return $this->nodes[$y][$x]; } + public function isWalkable(int $x, int $y) : bool + { + if (!isset($this->nodes[$y]) || !isset($this->nodes[$y][$x]) || !$this->nodes[$y][$x]->isWalkable()) { + return false; + } + + return true; + } + public function getNeighbors(Node $node, int $movement) : array { $x = $node->getX(); @@ -75,22 +84,22 @@ class Grid $d3 = false; // todo: check $x and $y because original implementation is flipped!!! - if ($this->getNode($x, $y - 1)->isWalkable()) { + if ($this->isWalkable($x, $y - 1)) { $neighbors[] = $this->getNode($x, $y - 1); $s0 = true; } - if ($this->getNode($x + 1, $y)->isWalkable()) { + if ($this->isWalkable($x + 1, $y)) { $neighbors[] = $this->getNode($x + 1, $y); $s1 = true; } - if ($this->getNode($x, $y + 1)->isWalkable()) { + if ($this->isWalkable($x, $y + 1)) { $neighbors[] = $this->getNode($x, $y + 1); $s2 = true; } - if ($this->getNode($x - 1, $y)->isWalkable()) { + if ($this->isWalkable($x - 1, $y)) { $neighbors[] = $this->getNode($x - 1, $y); $s3 = true; } @@ -116,19 +125,19 @@ class Grid $d3 = true; } - if ($d0 && $this->getNode($x - 1, $y - 1)->isWalkable()) { + if ($d0 && $this->isWalkable($x - 1, $y - 1)) { $neighbors[] = $this->getNode($x - 1, $y - 1); } - if ($d1 && $this->getNode($x + 1, $y - 1)->isWalkable()) { + if ($d1 && $this->isWalkable($x + 1, $y - 1)) { $neighbors[] = $this->getNode($x + 1, $y - 1); } - if ($d2 && $this->getNode($x + 1, $y + 1)->isWalkable()) { + if ($d2 && $this->isWalkable($x + 1, $y + 1)) { $neighbors[] = $this->getNode($x + 1, $y + 1); } - if ($d3 && $this->getNode($x - 1, $y + 1)->isWalkable()) { + if ($d3 && $this->isWalkable($x - 1, $y + 1)) { $neighbors[] = $this->getNode($x - 1, $y + 1); } diff --git a/Algorithm/PathFinding/JumpPointSearch.php b/Algorithm/PathFinding/JumpPointSearch.php index 88c7792fa..405475b6b 100644 --- a/Algorithm/PathFinding/JumpPointSearch.php +++ b/Algorithm/PathFinding/JumpPointSearch.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace phpOMS\Algorithm\PathFinding; +use phpOMS\Stdlib\Base\Heap; + /** * Perform path finding. * @@ -24,14 +26,19 @@ namespace phpOMS\Algorithm\PathFinding; */ class JumpPointSearch implements PathFinderInterface { + /** + * {@inheritdoc} + */ public static function findPath( int $startX, int $startY, int $endX, int $endY, Grid $grid, int $heuristic, int $movement ) : Path { + /** @var null|JumpPointNode $startNode */ $startNode = $grid->getNode($startX, $startY); - $endNode = $grid->getNode($endX, $endY); + /** @var null|JumpPointNode $endNode */ + $endNode = $grid->getNode($endX, $endY); if ($startNode === null || $endNode === null) { return new Path($grid); @@ -66,7 +73,7 @@ class JumpPointSearch implements PathFinderInterface return $path; } - public static function identifySuccessors(Node $node, Grid $grid, int $heuristic, int $movement, Node $endNode, Heap $openList) : Heap + public static function identifySuccessors(JumpPointNode $node, Grid $grid, int $heuristic, int $movement, JumpPointNode $endNode, Heap $openList) : Heap { $neighbors = self::findNeighbors($node, $movement, $grid); $neighborsLength = \count($neighbors); @@ -84,7 +91,7 @@ class JumpPointSearch implements PathFinderInterface if (!$jumpPoint->isOpened() || $ng < $jumpPoint->getG()) { $jumpPoint->setG($ng); - $jumpPoint->setH($jumpPoint->getH() ?? Heuristic::metric($jumpPoint->getCoordinates(), $endNode->getCoordinates(), $metric)); + $jumpPoint->setH($jumpPoint->getH() ?? Heuristic::metric($jumpPoint->getCoordinates(), $endNode->getCoordinates(), $heuristic)); $jumpPoint->setF($jumpPoint->getG() + $jumpPoint->getH()); $jumpPoint->setParent($node); @@ -100,7 +107,7 @@ class JumpPointSearch implements PathFinderInterface return $openList; } - private static function findNeighbors(Node $node, int $movement, Grid $grid) : array + private static function findNeighbors(JumpPointNode $node, int $movement, Grid $grid) : array { if ($movement === MovementType::STRAIGHT) { return self::findNeighborsStraight($node, $grid); @@ -113,7 +120,7 @@ class JumpPointSearch implements PathFinderInterface return self::findNeighborsDiagonalNoObstacle($node, $grid); } - private static function findNeighborsStraight(Node $node, Grid $grid) : array + private static function findNeighborsStraight(JumpPointNode $node, Grid $grid) : array { if ($node->getParent() === null) { return $grid->getNeighbors($node, MovementType::STRAIGHT); @@ -125,32 +132,34 @@ class JumpPointSearch implements PathFinderInterface $px = $node->getParent()->getX(); $py = $node->getParent()->getY(); + /** @var int $dx */ $dx = ($x - $px) / \max(\abs($x - $px), 1); + /** @var int $dy */ $dy = ($y - $py) / \may(\abs($y - $py), 1); $neighbors = []; if ($dx !== 0) { - if ($grid->getNode($x, $y - 1)->isWalkable()) { + if ($grid->isWalkable($x, $y - 1)) { $neighbors[] = $grid->getNode($x, $y - 1); } - if ($grid->getNode($x, $y + 1)->isWalkable()) { + if ($grid->isWalkable($x, $y + 1)) { $neighbors[] = $grid->getNode($x, $y + 1); } - if ($grid->getNode($x + $dx, $y)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y); } } elseif ($dy !== 0) { - if ($grid->getNode($x - 1, $y)->isWalkable()) { + if ($grid->isWalkable($x - 1, $y)) { $neighbors[] = $grid->getNode($x - 1, $y); } - if ($grid->getNode($x + 1, $y)->isWalkable()) { + if ($grid->isWalkable($x + 1, $y)) { $neighbors[] = $grid->getNode($x + 1, $y); } - if ($grid->getNode($x, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x, $y + $dy)) { $neighbors[] = $grid->getNode($x, $y + $dy); } } @@ -158,7 +167,7 @@ class JumpPointSearch implements PathFinderInterface return $neighbors; } - private static function findNeighborsDiagonal(Node $node, Grid $grid) : array + private static function findNeighborsDiagonal(JumpPointNode $node, Grid $grid) : array { if ($node->getParent() === null) { return $grid->getNeighbors($node, MovementType::DIAGONAL); @@ -170,52 +179,54 @@ class JumpPointSearch implements PathFinderInterface $px = $node->getParent()->getX(); $py = $node->getParent()->getY(); + /** @var int $dx */ $dx = ($x - $px) / \max(\abs($x - $px), 1); + /** @var int $dy */ $dy = ($y - $py) / \may(\abs($y - $py), 1); $neighbors = []; if ($dx !== 0 && $dy !== 0) { - if ($grid->getNode($x, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x, $y + $dy)) { $neighbors[] = $grid->getNode($x, $y + $dy); } - if ($grid->getNode($x + $dx, $y)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y); } - if ($grid->getNode($x + $dx, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y + $dy)) { $neighbors[] = $grid->getNode($x + $dx, $y + $dy); } - if (!$grid->getNode($x - $dx, $y)->isWalkable()) { + if (!$grid->isWalkable($x - $dx, $y)) { $neighbors[] = $grid->getNode($x - $dx, $y + $dy); } - if (!$grid->getNode($x, $y - $dy)->isWalkable()) { + if (!$grid->isWalkable($x, $y - $dy)) { $neighbors[] = $grid->getNode($x + $dx, $y - $dy); } } elseif ($dx === 0) { - if ($grid->getNode($x, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x, $y + $dy)) { $neighbors[] = $grid->getNode($x, $y + $dy); } - if (!$grid->getNode($x + 1, $y)->isWalkable()) { + if (!$grid->isWalkable($x + 1, $y)) { $neighbors[] = $grid->getNode($x + 1, $y + $dy); } - if (!$grid->getNode($x - 1, $y)->isWalkable()) { + if (!$grid->isWalkable($x - 1, $y)) { $neighbors[] = $grid->getNode($x - 1, $y + $dy); } } else { - if ($grid->getNode($x + $dx, $y)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y); } - if (!$grid->getNode($x, $y + 1)->isWalkable()) { + if (!$grid->isWalkable($x, $y + 1)) { $neighbors[] = $grid->getNode($x + $dx, $y + 1); } - if (!$grid->getNode($x, $y - 1)->isWalkable()) { + if (!$grid->isWalkable($x, $y - 1)) { $neighbors[] = $grid->getNode($x + $dx, $y - 1); } } @@ -223,7 +234,7 @@ class JumpPointSearch implements PathFinderInterface return $neighbors; } - private static function findNeighborsDiagonalOneObstacle(Node $node, Grid $grid) : array + private static function findNeighborsDiagonalOneObstacle(JumpPointNode $node, Grid $grid) : array { if ($node->getParent() === null) { return $grid->getNeighbors($node, MovementType::DIAGONAL_ONE_OBSTACLE); @@ -235,47 +246,49 @@ class JumpPointSearch implements PathFinderInterface $px = $node->getParent()->getX(); $py = $node->getParent()->getY(); + /** @var int $dx */ $dx = ($x - $px) / \max(\abs($x - $px), 1); + /** @var int $dy */ $dy = ($y - $py) / \may(\abs($y - $py), 1); $neighbors = []; if ($dx !== 0 && $dy !== 0) { - if ($grid->getNode($x, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x, $y + $dy)) { $neighbors[] = $grid->getNode($x, $y + $dy); } - if ($grid->getNode($x + $dx, $y)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y); } - if ($grid->getNode($x, $y + $dy) || $grid->getNode($x + $dx, $y)->isWalkable()) { + if ($grid->isWalkable($x, $y + $dy) || $grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y + $dy); } - if (!$grid->getNode($x - $dx, $y) && $grid->getNode($x, $y + $dy)->isWalkable()) { + if (!$grid->getNode($x - $dx, $y) && $grid->isWalkable($x, $y + $dy)) { $neighbors[] = $grid->getNode($x - $dx, $y + $dy); } - if (!$grid->getNode($x, $y - $dy) && $grid->getNode($x + $dx, $y)->isWalkable()) { + if (!$grid->getNode($x, $y - $dy) && $grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y - $dy); } } elseif ($dx === 0) { - if ($grid->getNode($x, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x, $y + $dy)) { $neighbors[] = $grid->getNode($x, $y + $dy); - if (!$grid->getNode($x + 1, $y)->isWalkable()) { + if (!$grid->isWalkable($x + 1, $y)) { $neighbors[] = $grid->getNode($x + 1, $y + $dy); } - if (!$grid->getNode($x - 1, $y)->isWalkable()) { + if (!$grid->isWalkable($x - 1, $y)) { $neighbors[] = $grid->getNode($x - 1, $y + $dy); } } } else { - if ($grid->getNode($x + $dx, $y)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y); - if (!$grid->getNode($x, $y + 1)->isWalkable()) { + if (!$grid->isWalkable($x, $y + 1)) { $neighbors[] = $grid->getNode($x + $dx, $y + 1); } - if (!$grid->getNode($x, $y - 1)->isWalkable()) { + if (!$grid->isWalkable($x, $y - 1)) { $neighbors[] = $grid->getNode($x + $dx, $y - 1); } } @@ -284,7 +297,7 @@ class JumpPointSearch implements PathFinderInterface return $neighbors; } - private static function findNeighborsDiagonalNoObstacle(Node $node, Grid $grid) : array + private static function findNeighborsDiagonalNoObstacle(JumpPointNode $node, Grid $grid) : array { if ($node->getParent() === null) { return $grid->getNeighbors($node, MovementType::DIAGONAL_NO_OBSTACLE); @@ -296,26 +309,28 @@ class JumpPointSearch implements PathFinderInterface $px = $node->getParent()->getX(); $py = $node->getParent()->getY(); + /** @var int $dx */ $dx = ($x - $px) / \max(\abs($x - $px), 1); + /** @var int $dy */ $dy = ($y - $py) / \may(\abs($y - $py), 1); $neighbors = []; if ($dx !== 0 && $dy !== 0) { - if ($grid->getNode($x, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x, $y + $dy)) { $neighbors[] = $grid->getNode($x, $y + $dy); } - if ($grid->getNode($x + $dx, $y)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y); } - if ($grid->getNode($x, $y + $dy) || $grid->getNode($x + $dx, $y)->isWalkable()) { + if ($grid->isWalkable($x, $y + $dy) || $grid->isWalkable($x + $dx, $y)) { $neighbors[] = $grid->getNode($x + $dx, $y + $dy); } } elseif ($dx !== 0 && $dy === 0) { - $isNextWalkable = $grid->getNode($x + $dx, $y)->isWalkable(); - $isTopWalkable = $grid->getNode($x, $y + 1)->isWalkable(); - $isBottomWalkable = $grid->getNode($x, $y - 1)->isWalkable(); + $isNextWalkable = $grid->isWalkable($x + $dx, $y); + $isTopWalkable = $grid->isWalkable($x, $y + 1); + $isBottomWalkable = $grid->isWalkable($x, $y - 1); if ($isNextWalkable) { $neighbors[] = $grid->getNode($x + $dx, $y); @@ -336,9 +351,9 @@ class JumpPointSearch implements PathFinderInterface $neighbors[] = $grid->getNode($x, $y - 1); } } elseif ($dx === 0 && $dy !== 0) { - $isNextWalkable = $grid->getNode($x, $y + $dy)->isWalkable(); - $isRightWalkable = $grid->getNode($x + 1, $y)->isWalkable(); - $isLeftWalkable = $grid->getNode($x - 1, $y)->isWalkable(); + $isNextWalkable = $grid->isWalkable($x, $y + $dy); + $isRightWalkable = $grid->isWalkable($x + 1, $y); + $isLeftWalkable = $grid->isWalkable($x - 1, $y); if ($isNextWalkable) { $neighbors[] = $grid->getNode($x, $y + $dy); @@ -363,7 +378,7 @@ class JumpPointSearch implements PathFinderInterface return $neighbors; } - private static function jump(Node $node, Node $endNode, int $movement, Grid $grid) : ?Node + private static function jump(JumpPointNode $node, JumpPointNode $endNode, int $movement, Grid $grid) : ?JumpPointNode { if ($movement === MovementType::STRAIGHT) { return self::jumpStraight($node, $endNode, $grid); @@ -376,7 +391,7 @@ class JumpPointSearch implements PathFinderInterface return self::jumpDiagonalNoObstacle($node, $endNode, $grid); } - private static function jumpStraight(Node $node, Node $endNode, Grid $grid) : ?Node + private static function jumpStraight(JumpPointNode $node, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode { $x = $node->getX(); $y = $node->getY(); @@ -396,14 +411,14 @@ class JumpPointSearch implements PathFinderInterface } if ($dx !== 0) { - if (($grid->getNode($x, $y - 1)->isWalkable() && !$grid->getNode($x - $dx, $y - 1)->isWalkable()) - || ($grid->getNode($x, $y + 1)->isWalkable() && !$grid->getNode($x - $dx, $y + 1)->isWalkable()) + if (($grid->isWalkable($x, $y - 1) && !$grid->isWalkable($x - $dx, $y - 1)) + || ($grid->isWalkable($x, $y + 1) && !$grid->isWalkable($x - $dx, $y + 1)) ) { return $node; } } elseif ($dy !== 0) { - if (($grid->getNode($x - 1, $y)->isWalkable() && !$grid->getNode($x - 1, $y - $dy)->isWalkable()) - || ($grid->getNode($x + 1, $y)->isWalkable() && !$grid->getNode($x + 1, $y - $dy)->isWalkable()) + if (($grid->isWalkable($x - 1, $y) && !$grid->isWalkable($x - 1, $y - $dy)) + || ($grid->isWalkable($x + 1, $y) && !$grid->isWalkable($x + 1, $y - $dy)) ) { return $node; } @@ -420,7 +435,7 @@ class JumpPointSearch implements PathFinderInterface return self::jumpStraight($grid->getNode($x + $dx, $y + $dy), $node, $grid); } - private static function jumpDiagonal(Node $node, Node $endNode, Grid $grid) : ?Node + private static function jumpDiagonal(JumpPointNode $node, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode { $x = $node->getX(); $y = $node->getY(); @@ -440,8 +455,8 @@ class JumpPointSearch implements PathFinderInterface } if ($dx !== 0 && $dy !== 0) { - if (($grid->getNode($x - $dx, $y + $dy)->isWalkable() && !$grid->getNode($x - $dx, $y)->isWalkable()) - || ($grid->getNode($x + $dx, $y - $dy)->isWalkable() && !$grid->getNode($x, $y - $dy)->isWalkable()) + if (($grid->isWalkable($x - $dx, $y + $dy) && !$grid->isWalkable($x - $dx, $y)) + || ($grid->isWalkable($x + $dx, $y - $dy) && !$grid->isWalkable($x, $y - $dy)) ) { return $node; } @@ -452,14 +467,14 @@ class JumpPointSearch implements PathFinderInterface return $node; } } elseif ($dx !== 0 && $dy === 0) { - if (($grid->getNode($x + $dx, $y + 1)->isWalkable() && !$grid->getNode($x, $y + 1)->isWalkable()) - || ($grid->getNode($x + $dx, $y - 1)->isWalkable() && !$grid->getNode($x, $y - 1)->isWalkable()) + if (($grid->isWalkable($x + $dx, $y + 1) && !$grid->isWalkable($x, $y + 1)) + || ($grid->isWalkable($x + $dx, $y - 1) && !$grid->isWalkable($x, $y - 1)) ) { return $node; } } else { - if (($grid->getNode($x + 1, $y + $dy)->isWalkable() && !$grid->getNode($x + 1, $y)->isWalkable()) - || ($grid->getNode($x - 1, $y + $dy)->isWalkable() && !$grid->getNode($x - 1, $y)->isWalkable()) + if (($grid->isWalkable($x + 1, $y + $dy) && !$grid->isWalkable($x + 1, $y)) + || ($grid->isWalkable($x - 1, $y + $dy) && !$grid->isWalkable($x - 1, $y)) ) { return $node; } @@ -468,7 +483,7 @@ class JumpPointSearch implements PathFinderInterface return self::jumpDiagonal($grid->getNode($x + $dx, $y + $dy), $node, $grid); } - private static function jumpDiagonalOneObstacle(Node $node, Node $endNode, Grid $grid) : ?Node + private static function jumpDiagonalOneObstacle(JumpPointNode $node, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode { $x = $node->getX(); $y = $node->getY(); @@ -488,8 +503,8 @@ class JumpPointSearch implements PathFinderInterface } if ($dx !== 0 && $dy !== 0) { - if (($grid->getNode($x - $dx, $y + $dy)->isWalkable() && !$grid->getNode($x - $dx, $y)->isWalkable()) - || ($grid->getNode($x + $dx, $y - $dy)->isWalkable() && !$grid->getNode($x, $y - $dy)->isWalkable()) + if (($grid->isWalkable($x - $dx, $y + $dy) && !$grid->isWalkable($x - $dx, $y)) + || ($grid->isWalkable($x + $dx, $y - $dy) && !$grid->isWalkable($x, $y - $dy)) ) { return $node; } @@ -500,27 +515,27 @@ class JumpPointSearch implements PathFinderInterface return $node; } } elseif ($dx !== 0 && $dy === 0) { - if (($grid->getNode($x + $dx, $y + 1)->isWalkable() && !$grid->getNode($x, $y + 1)->isWalkable()) - || ($grid->getNode($x + $dx, $y - 1)->isWalkable() && !$grid->getNode($x, $y - 1)->isWalkable()) + if (($grid->isWalkable($x + $dx, $y + 1) && !$grid->isWalkable($x, $y + 1)) + || ($grid->isWalkable($x + $dx, $y - 1) && !$grid->isWalkable($x, $y - 1)) ) { return $node; } } else { - if (($grid->getNode($x + 1, $y + $dy)->isWalkable() && !$grid->getNode($x + 1, $y)->isWalkable()) - || ($grid->getNode($x - 1, $y + $dy)->isWalkable() && !$grid->getNode($x - 1, $y)->isWalkable()) + if (($grid->isWalkable($x + 1, $y + $dy) && !$grid->isWalkable($x + 1, $y)) + || ($grid->isWalkable($x - 1, $y + $dy) && !$grid->isWalkable($x - 1, $y)) ) { return $node; } } - if ($grid->getNode($x + $dx, $y)->isWalkable() || $grid->getNode($x, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y) || $grid->isWalkable($x, $y + $dy)) { return self::jumpDiagonalOneObstacle($grid->getNode($x + $dx, $y + $dy), $node, $grid); } return null; } - private static function jumpDiagonalNoObstacle(Node $node, Node $endNode, Grid $grid) : ?Node + private static function jumpDiagonalNoObstacle(JumpPointNode $node, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode { $x = $node->getX(); $y = $node->getY(); @@ -546,20 +561,20 @@ class JumpPointSearch implements PathFinderInterface return $node; } } elseif ($dx !== 0 && $dy === 0) { - if (($grid->getNode($x, $y - 1)->isWalkable() && !$grid->getNode($x - $dx, $y - 1)->isWalkable()) - || ($grid->getNode($x, $y + 1)->isWalkable() && !$grid->getNode($x - $dx, $y + 1)->isWalkable()) + if (($grid->isWalkable($x, $y - 1) && !$grid->isWalkable($x - $dx, $y - 1)) + || ($grid->isWalkable($x, $y + 1) && !$grid->isWalkable($x - $dx, $y + 1)) ) { return $node; } } elseif ($dx === 0 && $dy !== 0) { - if (($grid->getNode($x - 1, $y)->isWalkable() && !$grid->getNode($x - 1, $y - $dy)->isWalkable()) - || ($grid->getNode($x + 1, $y)->isWalkable() && !$grid->getNode($x + 1, $y - $dy)->isWalkable()) + if (($grid->isWalkable($x - 1, $y) && !$grid->isWalkable($x - 1, $y - $dy)) + || ($grid->isWalkable($x + 1, $y) && !$grid->isWalkable($x + 1, $y - $dy)) ) { return $node; } } - if ($grid->getNode($x + $dx, $y)->isWalkable() || $grid->getNode($x, $y + $dy)->isWalkable()) { + if ($grid->isWalkable($x + $dx, $y) || $grid->isWalkable($x, $y + $dy)) { return self::jumpDiagonalNoObstacle($grid->getNode($x + $dx, $y + $dy), $node, $grid); } diff --git a/Algorithm/PathFinding/Path.php b/Algorithm/PathFinding/Path.php index 9fa16250b..06cec0afa 100644 --- a/Algorithm/PathFinding/Path.php +++ b/Algorithm/PathFinding/Path.php @@ -98,6 +98,10 @@ class Path } $node = $this->grid->getNode($x0, $y0); + + if ($node === null) { + break; + } } return $line; diff --git a/Algorithm/PathFinding/PathFinderInterface.php b/Algorithm/PathFinding/PathFinderInterface.php index 70b45b844..bf5e993a6 100644 --- a/Algorithm/PathFinding/PathFinderInterface.php +++ b/Algorithm/PathFinding/PathFinderInterface.php @@ -23,6 +23,21 @@ namespace phpOMS\Algorithm\PathFinding; * @since 1.0.0 */ interface PathFinderInterface { + /** + * Find path from one point to another + * + * @param int $startX Start point X-Coordinate + * @param int $startY Start point Y-Coordinate + * @param int $endX End point X-Coordinate + * @param int $endY End point Y-Coordinate + * @param Grid $grid Grid with the walkable points + * @param int $heuristic Heuristic algorithm to use in order to calculate the distance for a good path + * @param int $movement Allowed movement (e.g. straight, diagonal, ...) + * + * @return Path + * + * @since 1.0.0 + */ public static function findPath( int $startX, int $startY, int $endX, int $endY, diff --git a/Business/Finance/Depreciation.php b/Business/Finance/Depreciation.php index 5d2de8c97..d7913bdcd 100644 --- a/Business/Finance/Depreciation.php +++ b/Business/Finance/Depreciation.php @@ -24,6 +24,16 @@ namespace phpOMS\Business\Finance; */ final class Depreciation { + /** + * Constructure + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + private function __construct() + { + } + /** * Calculate linear depretiation rate * diff --git a/Business/Finance/FinanceFormulas.php b/Business/Finance/FinanceFormulas.php index 4a14c0251..55d3d754d 100644 --- a/Business/Finance/FinanceFormulas.php +++ b/Business/Finance/FinanceFormulas.php @@ -29,6 +29,15 @@ use phpOMS\Math\Statistic\Average; */ final class FinanceFormulas { + /** + * Constructure + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + private function __construct() + { + } /** * Annual Percentage Yield diff --git a/Business/Finance/Loan.php b/Business/Finance/Loan.php index 869e1b6ed..3188d0014 100644 --- a/Business/Finance/Loan.php +++ b/Business/Finance/Loan.php @@ -27,6 +27,16 @@ namespace phpOMS\Business\Finance; */ final class Loan { + /** + * Constructure + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + private function __construct() + { + } + /** * Balloon Loan - Payments * diff --git a/Business/Finance/Lorenzkurve.php b/Business/Finance/Lorenzkurve.php index af995609c..14cc86414 100644 --- a/Business/Finance/Lorenzkurve.php +++ b/Business/Finance/Lorenzkurve.php @@ -24,6 +24,16 @@ namespace phpOMS\Business\Finance; */ final class Lorenzkurve { + /** + * Constructure + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + private function __construct() + { + } + /** * Calculate Gini coefficient * diff --git a/Business/Finance/StockBonds.php b/Business/Finance/StockBonds.php index b74ad4177..90c7353f3 100644 --- a/Business/Finance/StockBonds.php +++ b/Business/Finance/StockBonds.php @@ -27,6 +27,16 @@ namespace phpOMS\Business\Finance; */ final class StockBonds { + /** + * Constructure + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + private function __construct() + { + } + /** * Bond Equivalent Yield * diff --git a/Business/Marketing/Metrics.php b/Business/Marketing/Metrics.php index a2c763b8a..33e8d8c0a 100644 --- a/Business/Marketing/Metrics.php +++ b/Business/Marketing/Metrics.php @@ -30,6 +30,7 @@ final class Metrics * Constructure * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Business/Programming/Metrics.php b/Business/Programming/Metrics.php index d984481f9..4964ecf74 100644 --- a/Business/Programming/Metrics.php +++ b/Business/Programming/Metrics.php @@ -30,6 +30,7 @@ final class Metrics * Constructure * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Business/Sales/MarketShareEstimation.php b/Business/Sales/MarketShareEstimation.php index 0892aa4ce..603256a3d 100644 --- a/Business/Sales/MarketShareEstimation.php +++ b/Business/Sales/MarketShareEstimation.php @@ -31,6 +31,7 @@ final class MarketShareEstimation * Constructure * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Config/SettingsAbstract.php b/Config/SettingsAbstract.php index 0fa550957..d05f7da53 100644 --- a/Config/SettingsAbstract.php +++ b/Config/SettingsAbstract.php @@ -44,10 +44,10 @@ abstract class SettingsAbstract implements OptionsInterface /** * Database connection instance. * - * @var null|ConnectionAbstract + * @var ConnectionAbstract * @since 1.0.0 */ - protected ?ConnectionAbstract $connection = null; + protected ConnectionAbstract $connection; /** * Settings table. diff --git a/DataStorage/Database/BuilderAbstract.php b/DataStorage/Database/BuilderAbstract.php index 1c6b186d6..e8562331e 100644 --- a/DataStorage/Database/BuilderAbstract.php +++ b/DataStorage/Database/BuilderAbstract.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace phpOMS\DataStorage\Database; use phpOMS\DataStorage\Database\Query\QueryType; -use phpOMS\DataStorage\DataStorageConnectionInterface; +use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; /** * Database query builder. @@ -30,18 +30,18 @@ abstract class BuilderAbstract /** * Grammar. * - * @var null|GrammarAbstract + * @var GrammarAbstract * @since 1.0.0 */ - protected ?GrammarAbstract $grammar = null; + protected GrammarAbstract $grammar; /** * Database connection. * - * @var null|DataStorageConnectionInterface + * @var ConnectionAbstract * @since 1.0.0 */ - protected ?DataStorageConnectionInterface $connection = null; + protected ConnectionAbstract $connection; /** * Query type. @@ -70,11 +70,11 @@ abstract class BuilderAbstract /** * Get connection * - * @return DataStorageConnectionInterface + * @return ConnectionAbstract * * @since 1.0.0 */ - public function getConnection() : DataStorageConnectionInterface + public function getConnection() : ConnectionAbstract { return $this->connection; } diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 7dabbd825..03672423f 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -38,10 +38,10 @@ class DataMapperAbstract implements DataMapperInterface /** * Database connection. * - * @var null|ConnectionAbstract + * @var ConnectionAbstract * @since 1.0.0 */ - protected static ?ConnectionAbstract $db = null; + protected static ConnectionAbstract $db; /** * Overwriting extended values. @@ -2003,9 +2003,6 @@ class DataMapperAbstract implements DataMapperInterface } /** - * Populate data. - * - * @param mixed $obj Object to add the relations to * * @return void * diff --git a/DataStorage/Database/DatabasePool.php b/DataStorage/Database/DatabasePool.php index 6806640f3..b6e5ccdaa 100644 --- a/DataStorage/Database/DatabasePool.php +++ b/DataStorage/Database/DatabasePool.php @@ -18,6 +18,7 @@ use phpOMS\DataStorage\Database\Connection\ConnectionFactory; use phpOMS\DataStorage\Database\Connection\NullConnection; use phpOMS\DataStorage\DataStorageConnectionInterface; use phpOMS\DataStorage\DataStoragePoolInterface; +use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; /** * Database pool handler. @@ -33,7 +34,7 @@ final class DatabasePool implements DataStoragePoolInterface /** * Databases. * - * @var DataStorageConnectionInterface[] + * @var ConnectionAbstract[] * @since 1.0.0 */ private array $pool = []; @@ -73,11 +74,11 @@ final class DatabasePool implements DataStoragePoolInterface * * @param string $key Database key * - * @return DataStorageConnectionInterface + * @return ConnectionAbstract * * @since 1.0.0 */ - public function get(string $key = '') : DataStorageConnectionInterface + public function get(string $key = '') : ConnectionAbstract { if ((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) { return new NullConnection(); diff --git a/DataStorage/Database/GrammarAbstract.php b/DataStorage/Database/GrammarAbstract.php index 1db7d39ed..9ecf6385e 100644 --- a/DataStorage/Database/GrammarAbstract.php +++ b/DataStorage/Database/GrammarAbstract.php @@ -194,7 +194,7 @@ abstract class GrammarAbstract * * @param array $elements Elements * @param string $prefix Prefix for table - * @param string $column Is always column? + * @param bool $column Is column? * * @return string * diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index 662e6f317..e01062531 100644 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -316,12 +316,12 @@ class Grammar extends GrammarAbstract return $this->compileSystem($value->getColumn(), $prefix); } elseif ($value instanceof Builder) { return '(' . \rtrim($value->toSql(), ';') . ')'; - } elseif ($value instanceof \JsonSerializable) { + } elseif ($value instanceof \JsonSerializable) { $encoded = \json_encode($value); - return $encoded ? $encoded : null; - } elseif ($value instanceof \Serializable) { - return $element->serialize(); + return $encoded ? $encoded : 'NULL'; + } elseif ($value instanceof \Serializable) { + return $value->serialize(); } else { throw new \InvalidArgumentException(\gettype($value)); } diff --git a/DataStorage/Database/Query/Grammar/MicrosoftGrammar.php b/DataStorage/Database/Query/Grammar/MicrosoftGrammar.php index d3ce1b6e9..09b805fde 100644 --- a/DataStorage/Database/Query/Grammar/MicrosoftGrammar.php +++ b/DataStorage/Database/Query/Grammar/MicrosoftGrammar.php @@ -46,6 +46,6 @@ class MicrosoftGrammar extends Grammar $query->limit = $query->limit ?? 1; - return 'SELECT TOP ' . $query->limit . ' ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY IDX FETCH FIRST ' . $query->limit . ' ROWS ONLY'; + return 'SELECT TOP ' . $query->limit . ' ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY IDX FETCH FIRST ' . ($query->limit ?? 1) . ' ROWS ONLY'; } } diff --git a/DataStorage/Database/Query/Grammar/MysqlGrammar.php b/DataStorage/Database/Query/Grammar/MysqlGrammar.php index 750f8207a..c3f42d913 100644 --- a/DataStorage/Database/Query/Grammar/MysqlGrammar.php +++ b/DataStorage/Database/Query/Grammar/MysqlGrammar.php @@ -53,6 +53,6 @@ class MysqlGrammar extends Grammar $expression = '*'; } - return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY \rand() ' . $this->compileLimit($query, $query->limit); + return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY \rand() ' . $this->compileLimit($query, $query->limit ?? 1); } } diff --git a/DataStorage/Database/Query/Grammar/OracleGrammar.php b/DataStorage/Database/Query/Grammar/OracleGrammar.php index 43a0af2c6..730745c6d 100644 --- a/DataStorage/Database/Query/Grammar/OracleGrammar.php +++ b/DataStorage/Database/Query/Grammar/OracleGrammar.php @@ -46,6 +46,6 @@ class OracleGrammar extends Grammar $query->limit = $query->limit ?? 1; - return 'SELECT ' . $expression . ' FROM (SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY dbms_random.value) WHERE rownum >= 1 AND rownum <= ' . $query->limit; + return 'SELECT ' . $expression . ' FROM (SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY dbms_random.value) WHERE rownum >= 1 AND rownum <= ' . ($query->limit ?? 1); } } diff --git a/DataStorage/Database/Query/Grammar/PostgresGrammar.php b/DataStorage/Database/Query/Grammar/PostgresGrammar.php index f21289a22..8b05849aa 100644 --- a/DataStorage/Database/Query/Grammar/PostgresGrammar.php +++ b/DataStorage/Database/Query/Grammar/PostgresGrammar.php @@ -44,6 +44,6 @@ class PostgresGrammar extends Grammar $expression = '*'; } - return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit); + return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit ?? 1); } } diff --git a/DataStorage/Database/Query/Grammar/SQLiteGrammar.php b/DataStorage/Database/Query/Grammar/SQLiteGrammar.php index 736a350f1..f2d091c49 100644 --- a/DataStorage/Database/Query/Grammar/SQLiteGrammar.php +++ b/DataStorage/Database/Query/Grammar/SQLiteGrammar.php @@ -53,6 +53,6 @@ class SQLiteGrammar extends Grammar $expression = '*'; } - return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit); + return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit ?? 1); } } diff --git a/DataStorage/Database/Schema/Field.php b/DataStorage/Database/Schema/Field.php new file mode 100644 index 000000000..d880ec560 --- /dev/null +++ b/DataStorage/Database/Schema/Field.php @@ -0,0 +1,27 @@ +db); - $tNames = $builder->selectFields()->execute(); + $tNames = $builder->selectFields($table)->execute(); $fields = []; foreach ($tNames as $name) { - $fields[] = $this->getField($name); + $fields[] = $this->getField($table, $name); } return $fields; diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index bb10bbee6..b908d65c5 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -56,10 +56,10 @@ final class ModuleManager /** * Application instance. * - * @var null|ApplicationAbstract + * @var ApplicationAbstract * @since 1.0.0 */ - private ?ApplicationAbstract $app = null; + private ApplicationAbstract $app; /** * Installed modules. @@ -249,7 +249,7 @@ final class ModuleManager if (empty($this->all)) { \chdir($this->modulePath); $files = \glob('*', \GLOB_ONLYDIR); - $c = \count($files); + $c = $files === false ? 0 : \count($files); for ($i = 0; $i < $c; ++$i) { $path = $this->modulePath . '/' . $files[$i] . '/info.json'; diff --git a/Stdlib/Base/Heap.php b/Stdlib/Base/Heap.php index 220dc5bd6..3e2e8b421 100644 --- a/Stdlib/Base/Heap.php +++ b/Stdlib/Base/Heap.php @@ -26,6 +26,12 @@ class Heap { private \Closure $compare; + /** + * Heap elements + * + * @var array + * @since 1.0.0 + */ private array $nodes = []; public function __construct(\Closure $compare = null) @@ -39,7 +45,7 @@ class Heap while ($lo < $hi) { $mid = (int) \floor(($lo + $hi) / 2); - if (($this->compare)($x, $this->node[$mid]) < 0) { + if (($this->compare)($x, $this->nodes[$mid]) < 0) { $hi = $mid; } else { $lo = $mid + 1; @@ -210,7 +216,7 @@ class Heap $this->nodes = []; } - public function empty() : bool + public function isEmpty() : bool { return empty($this->nodes); }