From 0b5d51f9b884f79005bcc430460cebe360a53401 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 Oct 2023 17:41:45 +0000 Subject: [PATCH 001/116] code fixes --- Algorithm/Graph/MarkovChain.php | 4 ++-- DataStorage/Database/Mapper/ReadMapper.php | 4 ++-- Math/Geometry/ConvexHull/GrahamScan.php | 8 +++---- Math/Optimization/Simplex.php | 23 ++++++++++--------- Stdlib/Tree/BinarySearchTree.php | 4 ++-- .../SpreadsheetDatabaseMapperTest.php | 2 +- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Algorithm/Graph/MarkovChain.php b/Algorithm/Graph/MarkovChain.php index c74eb26ac..ea74bc960 100644 --- a/Algorithm/Graph/MarkovChain.php +++ b/Algorithm/Graph/MarkovChain.php @@ -137,7 +137,7 @@ final class MarkovChain $cProb += $p; if ($prob <= $cProb) { - $new = $val; + $new = $val; break; } @@ -177,7 +177,7 @@ final class MarkovChain $prob = 1.0; for ($i = $this->order; $i < $length; ++$i) { - $prob *= $this->data[\implode($key)][$path[$i]] ?? 0.0; + $prob *= $this->data[\implode(' ', $key)][$path[$i]] ?? 0.0; $key[] = $path[$i]; \array_shift($key); diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index 7d696467d..ca4a3650f 100755 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -433,7 +433,7 @@ final class ReadMapper extends DataMapperAbstract $query = $this->getQuery( null, [ - 'COUNT(' . (empty($this->columns) ? '*' : \implode($this->columns)) . ')' => 'count' + 'COUNT(' . (empty($this->columns) ? '*' : \implode(',', $this->columns)) . ')' => 'count', ] ); @@ -452,7 +452,7 @@ final class ReadMapper extends DataMapperAbstract $query = $this->getQuery( null, [ - 'SUM(' . (empty($this->columns) ? '*' : \implode($this->columns)) . ')' => 'sum' + 'SUM(' . (empty($this->columns) ? '*' : \implode(',', $this->columns)) . ')' => 'sum', ] ); diff --git a/Math/Geometry/ConvexHull/GrahamScan.php b/Math/Geometry/ConvexHull/GrahamScan.php index 440d5cc60..a9f566c69 100644 --- a/Math/Geometry/ConvexHull/GrahamScan.php +++ b/Math/Geometry/ConvexHull/GrahamScan.php @@ -70,7 +70,7 @@ final class GrahamScan $subpoints = \array_slice($points, 2, $count); \usort($subpoints, function (array $a, array $b) use ($c) : int { // @todo: Might be wrong order of comparison - return \atan2($a['y'] - $c['y'], $a['x'] - $c['x']) <=> \atan2( $b['y'] - $c['y'], $b['x'] - $c['x']); + return \atan2($a['y'] - $c['y'], $a['x'] - $c['x']) <=> \atan2($b['y'] - $c['y'], $b['x'] - $c['x']); }); /** @var array $points */ @@ -106,9 +106,9 @@ final class GrahamScan /** * Counterclockwise rotation * - * @param array $a Vector - * @param array $b Vector - * @param array $c Vector + * @param array{x:int|float, y:int|float} $a Vector + * @param array{x:int|float, y:int|float} $b Vector + * @param array{x:int|float, y:int|float} $c Vector * * @return int|float * diff --git a/Math/Optimization/Simplex.php b/Math/Optimization/Simplex.php index 190f28a48..1a46ef507 100644 --- a/Math/Optimization/Simplex.php +++ b/Math/Optimization/Simplex.php @@ -26,6 +26,7 @@ namespace phpOMS\Math\Optimization; class Simplex { private int $m = 0; + private int $n = 0; private array $A = []; @@ -40,7 +41,7 @@ class Simplex private array $Nonbasic = []; - private function pivot (int $x, int $y) + private function pivot (int $x, int $y) : void { for ($j = 0; $j < $this->n; ++$j) { if ($j !== $y) { @@ -73,20 +74,20 @@ class Simplex $this->v += $this->c[$y] * $this->b[$x]; $this->c[$y] *= $this->A[$x][$y]; - $temp = $this->Basic[$x]; - $this->Basic[$x] = $this->Nonbasic[$y]; + $temp = $this->Basic[$x]; + $this->Basic[$x] = $this->Nonbasic[$y]; $this->Nonbasic[$y] = $temp; } private function iterate() : int { - $ind = -1; + $ind = -1; $best = -1; for ($j = 0; $j < $this->n; ++$j) { if ($this->c[$j] > 0) { if ($best === -1 || $this->Nonbasic[$j] < $ind) { - $ind = $this->Nonbasic[$j]; + $ind = $this->Nonbasic[$j]; $best = $j; } } @@ -96,14 +97,14 @@ class Simplex return 1; } - $maxConstraint = \INF; + $maxConstraint = \INF; $bestConstraint = -1; for ($i = 0; $i < $this->m; ++$i) { if ($this->A[$i][$best] < 0) { $currentConstraint = -$this->b[$i] / $this->A[$i][$best]; if ($currentConstraint < $maxConstraint) { - $maxConstraint = $currentConstraint; + $maxConstraint = $currentConstraint; $bestConstraint = $i; } } @@ -120,12 +121,12 @@ class Simplex private function initialize() : int { - $k = -1; + $k = -1; $minB = -1; for ($i = 0; $i < $this->m; ++$i) { if ($k === -1 || $this->b[$i] < $minB) { - $k = $i; + $k = $i; $minB = $this->b[$i]; } } @@ -201,8 +202,8 @@ class Simplex $this->A[$i][$nonbasicZ] = $this->A[$i][$this->n - 1]; } - $temp = $this->Nonbasic[$nonbasicZ]; - $this->Nonbasic[$nonbasicZ] = $this->Nonbasic[$this->n - 1]; + $temp = $this->Nonbasic[$nonbasicZ]; + $this->Nonbasic[$nonbasicZ] = $this->Nonbasic[$this->n - 1]; $this->Nonbasic[$this->n - 1] = $temp; --$this->n; diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 7b336f8b8..044e217c2 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -185,7 +185,7 @@ class BinarySearchTree if ($comparison < 0) { if ($current->left === null) { - $BST = new BinarySearchTree(); + $BST = new self(); $new = new Node($node->key, $node->data); $new->parent = $current; $new->tree = $BST; @@ -197,7 +197,7 @@ class BinarySearchTree } } elseif ($comparison > 0) { if ($current->right === null) { - $BST = new BinarySearchTree(); + $BST = new self(); $new = new Node($node->key, $node->data); $new->parent = $current; $new->tree = $BST; diff --git a/tests/Utils/IO/Spreadsheet/SpreadsheetDatabaseMapperTest.php b/tests/Utils/IO/Spreadsheet/SpreadsheetDatabaseMapperTest.php index b30db62f7..032ed1ab9 100755 --- a/tests/Utils/IO/Spreadsheet/SpreadsheetDatabaseMapperTest.php +++ b/tests/Utils/IO/Spreadsheet/SpreadsheetDatabaseMapperTest.php @@ -14,9 +14,9 @@ declare(strict_types=1); namespace phpOMS\tests\Utils\IO\Spreadsheet; -use phpOMS\tests\Autoloader; use phpOMS\DataStorage\Database\Connection\SQLiteConnection; use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\tests\Autoloader; use phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper; use phpOMS\Utils\StringUtils; From e997408bb6a1cc6e26765ce9a7fa120f65fba8c4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 Oct 2023 18:14:27 +0000 Subject: [PATCH 002/116] null checks --- Stdlib/Tree/BinarySearchTree.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 044e217c2..6fb6392b0 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -180,7 +180,7 @@ class BinarySearchTree } $current = $this->root; - while (true) { + while ($current !== null) { $comparison = $node->compare($current->data); if ($comparison < 0) { @@ -226,9 +226,13 @@ class BinarySearchTree { if ($node->left === null && $node->right === null) { if ($node->parent !== null) { - if ($node->parent->left !== null && $node->parent->left->root->compare($node->data) === 0) { + if ($node->parent->left !== null + && $node->parent->left->root?->compare($node->data) === 0 + ) { $node->parent->left = null; - } elseif ($node->parent->right !== null && $node->parent->right->root->compare($node) === 0) { + } elseif ($node->parent->right !== null + && $node->parent->right->root->compare($node) === 0 + ) { $node->parent->right = null; } } @@ -242,9 +246,13 @@ class BinarySearchTree if ($node->left === null) { $temp = $node->right->root; if ($node->parent !== null) { - if ($node->parent->left !== null && $node->parent->left->root->compare($node->data) === 0) { + if ($node->parent->left !== null + && $node->parent->left->root?->compare($node->data) === 0 + ) { $node->parent->left = $temp->tree; - } elseif ($node->parent->right !== null && $node->parent->right->root->compare($node->data) === 0) { + } elseif ($node->parent->right !== null + && $node->parent->right->root?->compare($node->data) === 0 + ) { $node->parent->right = $temp->tree; } } @@ -259,9 +267,13 @@ class BinarySearchTree if ($node->right === null) { $temp = $node->left->root; if ($node->parent !== null) { - if ($node->parent->left !== null && $node->parent->left->root->compare($node->data) === 0) { + if ($node->parent->left !== null + && $node->parent->left->root?->compare($node->data) === 0 + ) { $node->parent->left = $temp->tree; - } elseif ($node->parent->right !== null && $node->parent->right->root->compare($node->data) === 0) { + } elseif ($node->parent->right !== null + && $node->parent->right->root?->compare($node->data) === 0 + ) { $node->parent->right = $temp->tree; } } From 4807dcf5c2ded9a572bd38e2209e60c0b083ea57 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 Oct 2023 18:58:36 +0000 Subject: [PATCH 003/116] fix tests --- DataStorage/Database/Mapper/ReadMapper.php | 5 +---- Math/Geometry/ConvexHull/GrahamScan.php | 4 +++- Math/Optimization/Simplex.php | 10 +++++----- Stdlib/Tree/BinarySearchTree.php | 2 +- tests/DataStorage/Database/Query/BuilderTest.php | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index ca4a3650f..b72052a25 100755 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -1223,11 +1223,8 @@ final class ReadMapper extends DataMapperAbstract } $objects = $objectMapper->execute(); - if (empty($objects) || $objects === false) { - return false; - } - return true; + return !empty($objects) && $objects !== false; } elseif (isset($this->mapper::OWNS_ONE[$member]) || isset($this->mapper::BELONGS_TO[$member]) ) { diff --git a/Math/Geometry/ConvexHull/GrahamScan.php b/Math/Geometry/ConvexHull/GrahamScan.php index a9f566c69..df65eedd1 100644 --- a/Math/Geometry/ConvexHull/GrahamScan.php +++ b/Math/Geometry/ConvexHull/GrahamScan.php @@ -55,7 +55,9 @@ final class GrahamScan $points = \array_merge([null], $points); for ($i = 2; $i < $count; ++$i) { - if ($points[$i]['y'] < $points[$min]['y'] || ($points[$i]['y'] == $points[$min]['y'] && $points[$i]['x'] < $points[$min]['x'])) { + if ($points[$i]['y'] < $points[$min]['y'] + || ($points[$i]['y'] === $points[$min]['y'] && $points[$i]['x'] < $points[$min]['x']) + ) { $min = $i; } } diff --git a/Math/Optimization/Simplex.php b/Math/Optimization/Simplex.php index 1a46ef507..687e6509a 100644 --- a/Math/Optimization/Simplex.php +++ b/Math/Optimization/Simplex.php @@ -85,11 +85,11 @@ class Simplex $best = -1; for ($j = 0; $j < $this->n; ++$j) { - if ($this->c[$j] > 0) { - if ($best === -1 || $this->Nonbasic[$j] < $ind) { - $ind = $this->Nonbasic[$j]; - $best = $j; - } + if ($this->c[$j] > 0 + && ($best === -1 || $this->Nonbasic[$j] < $ind) + ) { + $ind = $this->Nonbasic[$j]; + $best = $j; } } diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 6fb6392b0..4a171d881 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -231,7 +231,7 @@ class BinarySearchTree ) { $node->parent->left = null; } elseif ($node->parent->right !== null - && $node->parent->right->root->compare($node) === 0 + && $node->parent->right->root?->compare($node->data) === 0 ) { $node->parent->right = null; } diff --git a/tests/DataStorage/Database/Query/BuilderTest.php b/tests/DataStorage/Database/Query/BuilderTest.php index fb61096a5..81237c111 100755 --- a/tests/DataStorage/Database/Query/BuilderTest.php +++ b/tests/DataStorage/Database/Query/BuilderTest.php @@ -763,7 +763,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $this->expectException(\InvalidArgumentException::class); $query = new Builder($con, true); - $query->select(false); + $query->select(new class {}); } /** From bd29e83c063dbd48322621e84ff04a43c9cb2abb Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 Oct 2023 19:12:07 +0000 Subject: [PATCH 004/116] remove DataMapperFactory line 697 --- DataStorage/Database/Mapper/DataMapperFactory.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/DataStorage/Database/Mapper/DataMapperFactory.php b/DataStorage/Database/Mapper/DataMapperFactory.php index 3cf431d76..d6fcf5613 100755 --- a/DataStorage/Database/Mapper/DataMapperFactory.php +++ b/DataStorage/Database/Mapper/DataMapperFactory.php @@ -695,19 +695,8 @@ class DataMapperFactory } if ($count > $pageLimit) { - // @todo: can be maybe removed? - /* - if (!$hasNext) { - \array_pop($data); - $hasNext = true; - --$count; - } - */ - - if ($count > $pageLimit) { - $hasPrevious = true; - \array_pop($data); - } + $hasPrevious = true; + \array_pop($data); } $data = \array_reverse($data); From 2b6e7b008d24d75a7acc32bbc7ae5090360e5198 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 Oct 2023 19:32:04 +0000 Subject: [PATCH 005/116] null fixes --- Stdlib/Tree/BinarySearchTree.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 4a171d881..885ba1123 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -249,15 +249,15 @@ class BinarySearchTree if ($node->parent->left !== null && $node->parent->left->root?->compare($node->data) === 0 ) { - $node->parent->left = $temp->tree; + $node->parent->left = $temp?->tree; } elseif ($node->parent->right !== null && $node->parent->right->root?->compare($node->data) === 0 ) { - $node->parent->right = $temp->tree; + $node->parent->right = $temp?->tree; } } - $temp->parent = $node->parent; + $temp->parent = $node?->parent; $node = null; @@ -270,21 +270,20 @@ class BinarySearchTree if ($node->parent->left !== null && $node->parent->left->root?->compare($node->data) === 0 ) { - $node->parent->left = $temp->tree; + $node->parent->left = $temp?->tree; } elseif ($node->parent->right !== null && $node->parent->right->root?->compare($node->data) === 0 ) { - $node->parent->right = $temp->tree; + $node->parent->right = $temp?->tree; } } - $temp->parent = $node->parent; + $temp->parent = $node?->parent; $node = null; return; - } else { - $temp = $this->successor($node); + } elseif (($temp = $this->successor($node)) !== null) { $node->key = $temp->key; $node->data = $temp->data; From dcc60246dfb681fdd5f16b0f53e93bffff3dcf35 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 Oct 2023 19:58:55 +0000 Subject: [PATCH 006/116] fix null checks --- Stdlib/Tree/BinarySearchTree.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 885ba1123..729cae455 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -257,7 +257,9 @@ class BinarySearchTree } } - $temp->parent = $node?->parent; + if ($temp !== null) { + $temp->parent = $node->parent; + } $node = null; @@ -278,7 +280,9 @@ class BinarySearchTree } } - $temp->parent = $node?->parent; + if ($temp !== null) { + $temp->parent = $node->parent; + } $node = null; From 9c86108a0f0da5b19124f648bdbef4c6376e7427 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 18 Oct 2023 12:30:42 +0000 Subject: [PATCH 007/116] revert api function changes --- Stdlib/Tree/BinarySearchTree.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 729cae455..885ba1123 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -257,9 +257,7 @@ class BinarySearchTree } } - if ($temp !== null) { - $temp->parent = $node->parent; - } + $temp->parent = $node?->parent; $node = null; @@ -280,9 +278,7 @@ class BinarySearchTree } } - if ($temp !== null) { - $temp->parent = $node->parent; - } + $temp->parent = $node?->parent; $node = null; From 0d8a2fc59d47244baf249da0873349848e452e9e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 19 Oct 2023 17:54:59 +0000 Subject: [PATCH 008/116] update readme --- CONTRIBUTING.md | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e237dc9e3..4f4653b71 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ Generally, the development philosophy is result orientated. This means that anyo Developers are encouraged to pick open tasks with high priorities according to their own skill level. Senior developers may directly assign tasks to developers based on their importance. New developers may find it easier to start with a task that has a low priority as they often also have a lower difficulty. -Open tasks can be found in the project overview: [PROJECT.md](https://github.com/Karaka-Management/Organization-Guide/blob/master/Project/PROJECT.md) +Open tasks can be found in the project overview: [PROJECT.md](https://github.com/orgs/Karaka-Management/projects/10) Tasks currently in development are prefixed in the priority column with an asterisk `*` and a name tag in the task description of the developer who is working on the task. diff --git a/README.md b/README.md index a554c0131..2d308fd78 100755 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Currently Karaka is still developing the first Alpha version. As soon as we have General updates can be found in our info section at https://jingga.app/info and developer updates can be found in our developer section at https://jingga.app/dev. In our developer section you can also check out the automatically generated reports such as code coverage, code style, static analysis etc. as well as our code style guide lines and developer documentation. -* [Project Status](https://github.com/Karaka-Management/Organization-Guide/blob/master/Project/PROJECT.md) +* [Project Status](https://github.com/orgs/Karaka-Management/projects/10) ## Tech stack @@ -62,7 +62,7 @@ General updates can be found in our info section at https://jingga.app/info and ## Become a contributor -Karaka has a very open culture and we always welcome new people who share our philosophy in providing create solutions which just work. You can find the development process description which also describes how to become a contributer in the [Organization documentation](https://github.com/Karaka-Management/Organization-Guide/blob/master/Processes/Development.md). +Karaka has a very open culture and we always welcome new people who share our philosophy in providing create solutions which just work. You can find the development process description which also describes how to become a contributer in the [Organization documentation](https://github.com/Karaka-Management/Organization-Guide/blob/master/Processes/01_Development.md). ## Misc From 4a208b8cd00f3c3e12df949c85977d263e035b66 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 19 Oct 2023 21:44:09 +0000 Subject: [PATCH 009/116] change icon font to google icons --- Utils/Parser/Presentation/PresentationWriter.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Utils/Parser/Presentation/PresentationWriter.php b/Utils/Parser/Presentation/PresentationWriter.php index 7feccb979..96c25e2e6 100755 --- a/Utils/Parser/Presentation/PresentationWriter.php +++ b/Utils/Parser/Presentation/PresentationWriter.php @@ -121,20 +121,20 @@ class PresentationWriter */ protected function displayPhpPresentation(PhpPresentation $oPHPPpt) : void { - $this->append('
  • PhpPresentation'); + $this->append('
  • folder_open PhpPresentation'); $this->append('