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;