Replace == with === in GIS classes

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
Maurício Meneghini Fauth 2025-06-07 21:32:51 -03:00
parent 71c1a4cf2a
commit 92db227012
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
9 changed files with 37 additions and 89 deletions

View File

@ -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\<int\>, array\<float\> given\.$#'
message: '#^Parameter \#1 \$points of method PhpMyAdmin\\Image\\ImageWrapper\:\:filledPolygon\(\) expects list\<int\>, list\<float\> 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\<int\>, array\<float\> given\.$#'
message: '#^Parameter \#1 \$points of method PhpMyAdmin\\Image\\ImageWrapper\:\:filledPolygon\(\) expects list\<int\>, list\<float\> 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

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="6.11.0@4ed53b7ccebc09ef60ec4c9e464bf8a01bfd35b0">
<files psalm-version="6.12.0@cf420941d061a57050b6c468ef2c778faf40aee2">
<file src="app/services_loader.php">
<MixedArgument>
<code><![CDATA[$argumentName]]></code>
@ -4622,9 +4622,9 @@
</RedundantPropertyInitializationCheck>
</file>
<file src="src/Gis/GisMultiPolygon.php">
<ArgumentTypeCoercion>
<InvalidArgument>
<code><![CDATA[$pointsArr]]></code>
</ArgumentTypeCoercion>
</InvalidArgument>
<MixedArgument>
<code><![CDATA[$dataRow[$k][$i][$j] ?? null]]></code>
<code><![CDATA[$labelPoint[0]]]></code>
@ -4742,9 +4742,9 @@
</RedundantPropertyInitializationCheck>
</file>
<file src="src/Gis/GisPolygon.php">
<ArgumentTypeCoercion>
<InvalidArgument>
<code><![CDATA[$pointsArr]]></code>
</ArgumentTypeCoercion>
</InvalidArgument>
<MixedArgument>
<code><![CDATA[$dataRow[$i][$j] ?? null]]></code>
</MixedArgument>

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<float> : list<array{float, float}>)
*/
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<array{float, float}>
*/
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<float>
*/
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);
}
/**

View File

@ -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;
}

View File

@ -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;
}

View File

@ -56,7 +56,7 @@ class GisVisualization
[135, 201, 191],
];
/** @var mixed[][] Raw data for the visualization */
/** @var array<int, array<int|string|null>> 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<int, array<int|string|null>> $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<int, array<int|string|null>>|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<int, array<string|null>> */
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<int, array<string|null>>
*/
private function fetchRawData(string $modifiedSql): array
{

View File

@ -11,6 +11,7 @@ use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
#[CoversClass(Polygon::class)]
#[CoversClass(Point::class)]
class PolygonTest extends AbstractTestCase
{
/**