diff --git a/Algorithm/Graph/MarkovChain.php b/Algorithm/Graph/MarkovChain.php index dde713a45..c74eb26ac 100644 --- a/Algorithm/Graph/MarkovChain.php +++ b/Algorithm/Graph/MarkovChain.php @@ -130,22 +130,21 @@ final class MarkovChain $prob = \mt_rand(1, 100) / 100; $cProb = 0.0; - $found = false; $val = null; + $new = null; foreach (($this->data[$keyString] ?? []) as $val => $p) { $cProb += $p; if ($prob <= $cProb) { $new = $val; - $found = true; break; } } // Couldn't find possible key - if (!$found) { + if ($new === null) { $new = $orderValues[\array_rand($orderValues)]; } diff --git a/Math/Geometry/ConvexHull/GrahamScan.php b/Math/Geometry/ConvexHull/GrahamScan.php index 2e8aa6afc..440d5cc60 100644 --- a/Math/Geometry/ConvexHull/GrahamScan.php +++ b/Math/Geometry/ConvexHull/GrahamScan.php @@ -66,11 +66,14 @@ final class GrahamScan $c = $points[1]; + /** @var array $subpoints */ $subpoints = \array_slice($points, 2, $count); - \usort($subpoints, function (array $a, array $b) use ($c) : bool { - return atan2($a['y'] - $c['y'], $a['x'] - $c['x']) < atan2( $b['y'] - $c['y'], $b['x'] - $c['x']); + \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']); }); + /** @var array $points */ $points = \array_merge([$points[0], $points[1]], $subpoints); $points[0] = $points[$count]; @@ -103,9 +106,9 @@ final class GrahamScan /** * Counterclockwise rotation * - * @param float[] $a Vector - * @param float[] $b Vector - * @param float[] $c Vector + * @param array $a Vector + * @param array $b Vector + * @param array $c Vector * * @return int|float * diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 0bff1b872..7b336f8b8 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -27,7 +27,7 @@ class BinarySearchTree /** * Root node * - * @param null|Node + * @var null|Node * @since 1.0.0 */ public ?Node $root = null; @@ -62,9 +62,9 @@ class BinarySearchTree $comparison = $this->root->compare($data); if ($comparison > 0) { - return $this->root->left->search($data); + return $this->root->left?->search($data); } elseif ($comparison < 0) { - return $this->root->right->search($data); + return $this->root->right?->search($data); } return $this->root; @@ -126,7 +126,7 @@ class BinarySearchTree } $top = $node->parent; - while ($top !== Null && $top->compare($node->data)) { + while ($top !== null && $top->compare($node->data)) { $node = $top; $top = $top->parent; } @@ -272,7 +272,7 @@ class BinarySearchTree return; } else { - $temp = $this->successor($node); + $temp = $this->successor($node); $node->key = $temp->key; $node->data = $temp->data; diff --git a/Stdlib/Tree/Node.php b/Stdlib/Tree/Node.php index 3d8c0ce83..35c5acd03 100644 --- a/Stdlib/Tree/Node.php +++ b/Stdlib/Tree/Node.php @@ -82,7 +82,7 @@ class Node */ public function __construct(string $key, mixed $data = null) { - $this->key = $key; + $this->key = $key; $this->data = $data; } diff --git a/tests/Message/Http/RestTest.php b/tests/Message/Http/RestTest.php index 488e4c34a..f4b7af59b 100755 --- a/tests/Message/Http/RestTest.php +++ b/tests/Message/Http/RestTest.php @@ -54,7 +54,7 @@ final class RestTest extends \PHPUnit\Framework\TestCase $request = new HttpRequest(new HttpUri('https://httpbin.org/post')); $request->setMethod(RequestMethod::POST); self::assertTrue($request->setData('pdata', 'abc')); - self::assertEquals('abc', REST::request($request)->get('form')['pdata'] ?? ''); + self::assertEquals('abc', REST::request($request)->getData('form')['pdata'] ?? ''); } /** @@ -67,7 +67,7 @@ final class RestTest extends \PHPUnit\Framework\TestCase $request = new HttpRequest(new HttpUri('https://httpbin.org/put')); $request->setMethod(RequestMethod::PUT); self::assertTrue($request->setData('pdata', 'abc')); - self::assertEquals('abc', REST::request($request)->get('form')['pdata'] ?? ''); + self::assertEquals('abc', REST::request($request)->getData('form')['pdata'] ?? ''); } /** @@ -80,7 +80,7 @@ final class RestTest extends \PHPUnit\Framework\TestCase $request = new HttpRequest(new HttpUri('https://httpbin.org/delete')); $request->setMethod(RequestMethod::DELETE); self::assertTrue($request->setData('ddata', 'abc')); - self::assertEquals('abc', REST::request($request)->get('form')['ddata'] ?? ''); + self::assertEquals('abc', REST::request($request)->getData('form')['ddata'] ?? ''); } /** @@ -93,7 +93,7 @@ final class RestTest extends \PHPUnit\Framework\TestCase $request = new HttpRequest(new HttpUri('https://httpbin.org/get')); $request->setMethod(RequestMethod::GET); self::assertTrue($request->setData('gdata', 'abc')); - self::assertEquals('abc', REST::request($request)->get('args')['gdata'] ?? ''); + self::assertEquals('abc', REST::request($request)->getData('args')['gdata'] ?? ''); } /**