diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 534cf6cb86..19ba5d3bb7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6912,30 +6912,6 @@ parameters: count: 1 path: src/Footer.php - - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' - identifier: notEqual.notAllowed - count: 1 - path: src/Gis/Ds/Point.php - - - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' - identifier: equal.notAllowed - count: 2 - path: src/Gis/Ds/Point.php - - - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' - identifier: equal.notAllowed - count: 2 - path: src/Gis/Ds/Polygon.php - - - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' - identifier: notEqual.notAllowed - count: 2 - path: src/Gis/GisGeometry.php - - message: '#^Only numeric types are allowed in \+, int\<0, max\>\|false given on the left side\.$#' identifier: plus.leftNonNumeric @@ -7122,12 +7098,6 @@ parameters: count: 3 path: src/Gis/GisMultiPoint.php - - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' - identifier: equal.notAllowed - count: 8 - path: src/Gis/GisMultiPoint.php - - message: '#^Parameter \#1 \$point of method PhpMyAdmin\\Gis\\GisGeometry\:\:getWktCoord\(\) expects array\{x\: float\|int\|string, y\: float\|int\|string\}\|null, mixed given\.$#' identifier: argument.type @@ -7255,7 +7225,7 @@ parameters: path: src/Gis/GisMultiPolygon.php - - message: '#^Parameter \#1 \$points of method PhpMyAdmin\\Image\\ImageWrapper\:\:filledPolygon\(\) expects list\, array\ given\.$#' + message: '#^Parameter \#1 \$points of method PhpMyAdmin\\Image\\ImageWrapper\:\:filledPolygon\(\) expects list\, list\ given\.$#' identifier: argument.type count: 1 path: src/Gis/GisMultiPolygon.php @@ -7296,12 +7266,6 @@ parameters: count: 1 path: src/Gis/GisPoint.php - - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' - identifier: equal.notAllowed - count: 4 - path: src/Gis/GisPoint.php - - message: '#^Parameter \#1 \$point of method PhpMyAdmin\\Gis\\GisGeometry\:\:getWktCoord\(\) expects array\{x\: float\|int\|string, y\: float\|int\|string\}\|null, mixed given\.$#' identifier: argument.type @@ -7351,7 +7315,7 @@ parameters: path: src/Gis/GisPolygon.php - - message: '#^Parameter \#1 \$points of method PhpMyAdmin\\Image\\ImageWrapper\:\:filledPolygon\(\) expects list\, array\ given\.$#' + message: '#^Parameter \#1 \$points of method PhpMyAdmin\\Image\\ImageWrapper\:\:filledPolygon\(\) expects list\, list\ given\.$#' identifier: argument.type count: 1 path: src/Gis/GisPolygon.php @@ -7398,12 +7362,6 @@ parameters: count: 1 path: src/Gis/GisVisualization.php - - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' - identifier: notEqual.notAllowed - count: 1 - path: src/Gis/GisVisualization.php - - message: '#^Binary operation "\*" between 24 and mixed results in an error\.$#' identifier: binaryOp.invalid diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f1148b6f4d..373362a22f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + @@ -4622,9 +4622,9 @@ - + - + @@ -4742,9 +4742,9 @@ - + - + diff --git a/src/Gis/Ds/Point.php b/src/Gis/Ds/Point.php index ce843af75e..489918315d 100644 --- a/src/Gis/Ds/Point.php +++ b/src/Gis/Ds/Point.php @@ -21,7 +21,7 @@ final readonly class Point $noOfPoints = $polygon->count(); // If first point is repeated at the end remove it - if ($polygon->top() == $polygon->bottom()) { + if ($polygon->top()->isEqual($polygon->bottom())) { --$noOfPoints; } @@ -46,11 +46,11 @@ final readonly class Point continue; } - if ($p1->y != $p2->y) { + if ($p1->y !== $p2->y) { $xinters = ($this->y - $p1->y) * ($p2->x - $p1->x) / ($p2->y - $p1->y) + $p1->x; - if ($p1->x == $p2->x || $this->x <= $xinters) { + if ($p1->x === $p2->x || $this->x <= $xinters) { $counter++; } } @@ -60,4 +60,9 @@ final readonly class Point return $counter % 2 !== 0; } + + public function isEqual(self $point): bool + { + return $this->x === $point->x && $this->y === $point->y; + } } diff --git a/src/Gis/Ds/Polygon.php b/src/Gis/Ds/Polygon.php index ca9ddf7c8d..e7be558635 100644 --- a/src/Gis/Ds/Polygon.php +++ b/src/Gis/Ds/Polygon.php @@ -31,7 +31,7 @@ final class Polygon extends SplDoublyLinkedList $noOfPoints = $this->count(); // If the last point is same as the first point ignore it - if ($this->top() == $this->bottom()) { + if ($this->top()->isEqual($this->bottom())) { --$noOfPoints; } @@ -108,7 +108,7 @@ final class Polygon extends SplDoublyLinkedList //If both are outside the polygon reduce the epsilon and //recalculate the points(reduce exponentially for faster convergence) $epsilon **= 2; - if ($epsilon == 0) { + if ($epsilon === 0.0) { return false; } } diff --git a/src/Gis/GisGeometry.php b/src/Gis/GisGeometry.php index 74bdade2e2..98f935e07e 100644 --- a/src/Gis/GisGeometry.php +++ b/src/Gis/GisGeometry.php @@ -235,7 +235,7 @@ abstract class GisGeometry * @param ScaleData|null $scaleData data related to scaling * @param bool $linear if true, as a 1D array, else as a 2D array * - * @return float[]|float[][] scaled points + * @psalm-return ($linear is true ? list : list) */ private function extractPointsInternal(string $pointSet, ScaleData|null $scaleData, bool $linear): array { @@ -249,7 +249,7 @@ abstract class GisGeometry // Extract coordinates of the point $coordinates = explode(' ', $point); - if (isset($coordinates[1]) && trim($coordinates[0]) != '' && trim($coordinates[1]) != '') { + if (isset($coordinates[1]) && trim($coordinates[0]) !== '' && trim($coordinates[1]) !== '') { $x = (float) $coordinates[0]; $y = (float) $coordinates[1]; if ($scaleData !== null) { @@ -278,14 +278,11 @@ abstract class GisGeometry * @param string $wktCoords string of comma separated points * @param ScaleData|null $scaleData data related to scaling * - * @return float[][] scaled points + * @return list */ protected function extractPoints1d(string $wktCoords, ScaleData|null $scaleData): array { - /** @var float[][] $pointsArr */ - $pointsArr = $this->extractPointsInternal($wktCoords, $scaleData, false); - - return $pointsArr; + return $this->extractPointsInternal($wktCoords, $scaleData, false); } /** @@ -294,14 +291,11 @@ abstract class GisGeometry * @param string $wktCoords string of comma separated points * @param ScaleData|null $scaleData data related to scaling * - * @return float[] scaled points + * @return list */ protected function extractPoints1dLinear(string $wktCoords, ScaleData|null $scaleData): array { - /** @var float[] $pointsArr */ - $pointsArr = $this->extractPointsInternal($wktCoords, $scaleData, true); - - return $pointsArr; + return $this->extractPointsInternal($wktCoords, $scaleData, true); } /** diff --git a/src/Gis/GisMultiPoint.php b/src/Gis/GisMultiPoint.php index fe17a80191..63bc198a86 100644 --- a/src/Gis/GisMultiPoint.php +++ b/src/Gis/GisMultiPoint.php @@ -87,10 +87,6 @@ class GisMultiPoint extends GisGeometry foreach ($pointsArr as $point) { // draw a small circle to mark the point - if ($point[0] == '' || $point[1] == '') { - continue; - } - $image->arc( (int) round($point[0]), (int) round($point[1]), @@ -102,7 +98,7 @@ class GisMultiPoint extends GisGeometry ); } - if ($label === '' || $pointsArr[0][0] == '' || $pointsArr[0][1] == '') { + if ($label === '' || ! isset($pointsArr[0])) { return; } @@ -139,14 +135,10 @@ class GisMultiPoint extends GisGeometry foreach ($pointsArr as $point) { // draw a small circle to mark the point - if ($point[0] == '' || $point[1] == '') { - continue; - } - $pdf->Circle($point[0], $point[1], 2, 0, 360, 'D', $line); } - if ($label === '' || $pointsArr[0][0] == '' || $pointsArr[0][1] == '') { + if ($label === '' || ! isset($pointsArr[0])) { return; } diff --git a/src/Gis/GisPoint.php b/src/Gis/GisPoint.php index debf35a2c4..e5a3060fe8 100644 --- a/src/Gis/GisPoint.php +++ b/src/Gis/GisPoint.php @@ -83,7 +83,7 @@ class GisPoint extends GisGeometry $pointsArr = $this->extractPoints1dLinear($point, $scaleData); // draw a small circle to mark the point - if ($pointsArr[0] == '' || $pointsArr[1] == '') { + if (! isset($pointsArr[0], $pointsArr[1])) { return; } @@ -131,7 +131,7 @@ class GisPoint extends GisGeometry $point = mb_substr($spatial, 6, -1); $pointsArr = $this->extractPoints1dLinear($point, $scaleData); - if ($pointsArr[0] == '' || $pointsArr[1] == '') { + if (! isset($pointsArr[0], $pointsArr[1])) { return; } diff --git a/src/Gis/GisVisualization.php b/src/Gis/GisVisualization.php index 049200b14c..426011c5d3 100644 --- a/src/Gis/GisVisualization.php +++ b/src/Gis/GisVisualization.php @@ -56,7 +56,7 @@ class GisVisualization [135, 201, 191], ]; - /** @var mixed[][] Raw data for the visualization */ + /** @var array> Raw data for the visualization */ private array $data; /** The width of the GIS visualization.*/ @@ -117,8 +117,7 @@ class GisVisualization /** * Get visualization * - * @param mixed[][] $data Raw data, if set, parameters other - * than $options will be ignored + * @param array> $data Raw data, if set, parameters other than $options will be ignored */ public static function getByData(array $data, GisVisualizationSettings $options): GisVisualization { @@ -131,7 +130,7 @@ class GisVisualization public function hasSrid(): bool { foreach ($this->data as $row) { - if ($row['srid'] != 0) { + if ((int) $row['srid'] !== 0) { return true; } } @@ -142,11 +141,10 @@ class GisVisualization /** * Stores user specified options. * - * @param mixed[][]|string $sqlOrData SQL to fetch raw data for visualization - * or an array with data. - * If it is an array row and pos are ignored - * @param int $rows Number of rows - * @param int $pos Start position + * @param array>|string $sqlOrData SQL to fetch raw data for visualization or an array + * with data. If it is an array row and pos are ignored + * @param int $rows Number of rows + * @param int $pos Start position */ private function __construct( array|string $sqlOrData, @@ -167,7 +165,7 @@ class GisVisualization : $sqlOrData; } - /** @return mixed[][] raw data */ + /** @return array> */ private function modifyQueryAndFetch(string $sqlQuery): array { $modifiedSql = $this->modifySqlQuery($sqlQuery); @@ -235,7 +233,7 @@ class GisVisualization /** * Returns raw data for GIS visualization. * - * @return mixed[][] the raw data. + * @return array> */ private function fetchRawData(string $modifiedSql): array { diff --git a/tests/unit/Gis/Ds/PolygonTest.php b/tests/unit/Gis/Ds/PolygonTest.php index e3f510fb85..5b9efc8361 100644 --- a/tests/unit/Gis/Ds/PolygonTest.php +++ b/tests/unit/Gis/Ds/PolygonTest.php @@ -11,6 +11,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(Polygon::class)] +#[CoversClass(Point::class)] class PolygonTest extends AbstractTestCase { /**