Skip to content

Commit 071ebd2

Browse files
committed
fixing Scrutinizer issues
1 parent 44c34fe commit 071ebd2

File tree

4 files changed

+5
-15
lines changed

4 files changed

+5
-15
lines changed

src/Euclidean/Point.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private function sanitizeCoordinates(array $coordinates): array
5656
assert(is_array($coordinates));
5757
$errors = array_keys($coordinates, false, true);
5858

59-
if ($errors) {
59+
if (! empty($errors)) {
6060
throw new \InvalidArgumentException(sprintf(
6161
"Invalid set of coordinates: values at offsets [%s] could not be converted to numbers",
6262
implode(',', $errors)

src/Gps/Point.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
use Kmeans\Concerns\HasSpaceTrait;
77
use Kmeans\Interfaces\PointInterface;
88

9-
/**
10-
* @method array{0: float, 1: float} getCoordinates()
11-
*/
129
class Point implements PointInterface
1310
{
1411
use HasDataTrait;

src/Math.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static function euclideanDist(array $a, array $b): float
1212
{
1313
assert(count($a) == count($b));
1414

15-
for ($dist = 0, $n = 0; $n < count($a); $n++) {
15+
for ($dist = 0, $n = 0, $c = count($a); $n < $c; $n++) {
1616
$dist += pow($a[$n] - $b[$n], 2);
1717
}
1818

@@ -46,7 +46,7 @@ public static function centroid(array $points): array
4646
*
4747
* @see https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
4848
*
49-
* @return array{float, float}
49+
* @return array{0: float, 1: float}
5050
*/
5151
public static function gaussianNoise(float $mu, float $sigma): array
5252
{

src/RandomInitialization.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,7 @@ protected function getRandomPoint(PointCollectionInterface $points): PointInterf
3636
throw new \LogicException("Unable to pick a random point out of an empty point collection");
3737
}
3838

39-
$num = mt_rand(0, count($points) - 1);
40-
foreach ($points as $i => $point) {
41-
if ($i > $num) {
42-
break;
43-
}
44-
}
45-
46-
assert(isset($point));
47-
return $point;
39+
$arr = iterator_to_array($points);
40+
return $arr[array_rand($arr)];
4841
}
4942
}

0 commit comments

Comments
 (0)