diff --git a/libraries/classes/Gis/GisGeometry.php b/libraries/classes/Gis/GisGeometry.php index a1c4dc89d7..097ea9c8ef 100644 --- a/libraries/classes/Gis/GisGeometry.php +++ b/libraries/classes/Gis/GisGeometry.php @@ -20,6 +20,7 @@ use function preg_match; use function random_int; use function sprintf; use function str_replace; +use function strtoupper; use function trim; /** @@ -166,15 +167,14 @@ abstract class GisGeometry } /** - * Generates parameters for the GIS data editor from the value of the GIS column. - * This method performs common work. - * More specific work is performed by each of the geom classes. + * Parses the wkt and optional srid from a combined string for the GIS data editor * * @param string $value value of the GIS column * - * @return array parameters for the GIS editor from the value of the GIS column + * @return array parameters for the GIS editor from the value of the GIS column + * @psalm-return array{'srid':int,'wkt':string} */ - public function generateParams($value): array + protected function parseWktAndSrid(string $value): array { $geom_types = '(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)'; $srid = 0; @@ -194,6 +194,38 @@ abstract class GisGeometry ]; } + /** + * Generate coordinate parameters for the GIS data editor from the value of the GIS column. + * + * @param string $wkt Value of the GIS column + * + * @return array Coordinate params for the GIS data editor from the value of the GIS column + */ + abstract protected function getCoordinateParams(string $wkt): array; + + /** + * Generate parameters for the GIS data editor from the value of the GIS column. + * + * @param string $value Value of the GIS column + * + * @return array params for the GIS data editor from the value of the GIS column + */ + public function generateParams(string $value): array + { + $data = $this->parseWktAndSrid($value); + $index = 0; + $wkt = $data['wkt']; + preg_match('/^\w+/', $wkt, $matches); + $wkt_type = strtoupper($matches[0]); + + return [ + 'srid' => $data['srid'], + $index => [ + $wkt_type => $this->getCoordinateParams($wkt), + ], + ]; + } + /** * Extracts points, scales and returns them as an array. * diff --git a/libraries/classes/Gis/GisGeometryCollection.php b/libraries/classes/Gis/GisGeometryCollection.php index f3b6344233..267bba502c 100644 --- a/libraries/classes/Gis/GisGeometryCollection.php +++ b/libraries/classes/Gis/GisGeometryCollection.php @@ -7,14 +7,15 @@ declare(strict_types=1); namespace PhpMyAdmin\Gis; +use ErrorException; use PhpMyAdmin\Image\ImageWrapper; use TCPDF; -use function array_merge; use function count; use function mb_strpos; use function mb_substr; use function str_split; +use function strtoupper; /** * Handles actions related to GIS GEOMETRYCOLLECTION objects @@ -299,6 +300,16 @@ class GisGeometryCollection extends GisGeometry return $wkt . ')'; } + /** + * GeometryCollection does not have coordinates of its own + * + * @param string $wkt Value of the GIS column + */ + protected function getCoordinateParams(string $wkt): array + { + throw new ErrorException('Has no own coordinates'); + } + /** * Generates parameters for the GIS data editor from the value of the GIS column. * @@ -306,37 +317,38 @@ class GisGeometryCollection extends GisGeometry * * @return array parameters for the GIS editor from the value of the GIS column */ - public function generateParams($value): array + public function generateParams(string $value): array { - $params = []; - $data = GisGeometry::generateParams($value); - $params['srid'] = $data['srid']; + $data = $this->parseWktAndSrid($value); $wkt = $data['wkt']; // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' $goem_col = mb_substr($wkt, 19, -1); - // Split the geometry collection object to get its constituents. - $sub_parts = $this->explodeGeomCol($goem_col); - $params['GEOMETRYCOLLECTION']['geom_count'] = count($sub_parts); + $wkt_geometries = $this->explodeGeomCol($goem_col); + $params = [ + 'srid' => $data['srid'], + 'GEOMETRYCOLLECTION' => [ + 'geom_count' => count($wkt_geometries), + ], + ]; $i = 0; - foreach ($sub_parts as $sub_part) { - $type_pos = mb_strpos($sub_part, '('); + foreach ($wkt_geometries as $wkt_geometry) { + $type_pos = mb_strpos($wkt_geometry, '('); if ($type_pos === false) { continue; } - $type = mb_substr($sub_part, 0, $type_pos); - /** - * @var GisMultiPolygon|GisPolygon|GisMultiPoint|GisPoint|GisMultiLineString|GisLineString $gis_obj - */ - $gis_obj = GisFactory::factory($type); + $wkt_type = strtoupper(mb_substr($wkt_geometry, 0, $type_pos)); + $gis_obj = GisFactory::factory($wkt_type); if (! $gis_obj) { continue; } - $params = array_merge($params, $gis_obj->generateParams($sub_part, $i)); - $i++; + $params[$i++] = [ + 'gis_type' => $wkt_type, + $wkt_type => $gis_obj->getCoordinateParams($wkt_geometry), + ]; } return $params; diff --git a/libraries/classes/Gis/GisLineString.php b/libraries/classes/Gis/GisLineString.php index e15ecf9787..d2a121c083 100644 --- a/libraries/classes/Gis/GisLineString.php +++ b/libraries/classes/Gis/GisLineString.php @@ -270,37 +270,27 @@ class GisLineString extends GisGeometry } /** - * Generate parameters for the GIS data editor from the value of the GIS column. + * Generate coordinate parameters for the GIS data editor from the value of the GIS column. * - * @param string $value of the GIS column - * @param int $index of the geometry + * @param string $wkt Value of the GIS column * - * @return array params for the GIS data editor from the value of the GIS column + * @return array Coordinate params for the GIS data editor from the value of the GIS column */ - public function generateParams($value, $index = -1): array + protected function getCoordinateParams(string $wkt): array { - $params = []; - if ($index == -1) { - $index = 0; - $data = GisGeometry::generateParams($value); - $params['srid'] = $data['srid']; - $wkt = $data['wkt']; - } else { - $params[$index]['gis_type'] = 'LINESTRING'; - $wkt = $value; - } - // Trim to remove leading 'LINESTRING(' and trailing ')' $linestring = mb_substr($wkt, 11, -1); $points_arr = $this->extractPoints($linestring, null); $no_of_points = count($points_arr); - $params[$index]['LINESTRING']['no_of_points'] = $no_of_points; + $coords = ['no_of_points' => $no_of_points]; for ($i = 0; $i < $no_of_points; $i++) { - $params[$index]['LINESTRING'][$i]['x'] = $points_arr[$i][0]; - $params[$index]['LINESTRING'][$i]['y'] = $points_arr[$i][1]; + $coords[$i] = [ + 'x' => $points_arr[$i][0], + 'y' => $points_arr[$i][1], + ]; } - return $params; + return $coords; } } diff --git a/libraries/classes/Gis/GisMultiLineString.php b/libraries/classes/Gis/GisMultiLineString.php index 3922ccd4f3..a1b6c997f5 100644 --- a/libraries/classes/Gis/GisMultiLineString.php +++ b/libraries/classes/Gis/GisMultiLineString.php @@ -341,45 +341,31 @@ class GisMultiLineString extends GisGeometry } /** - * Generate parameters for the GIS data editor from the value of the GIS column. + * Generate coordinate parameters for the GIS data editor from the value of the GIS column. * - * @param string $value Value of the GIS column - * @param int $index Index of the geometry + * @param string $wkt Value of the GIS column * - * @return array params for the GIS data editor from the value of the GIS column + * @return array Coordinate params for the GIS data editor from the value of the GIS column */ - public function generateParams($value, $index = -1): array + protected function getCoordinateParams(string $wkt): array { - $params = []; - if ($index == -1) { - $index = 0; - $data = GisGeometry::generateParams($value); - $params['srid'] = $data['srid']; - $wkt = $data['wkt']; - } else { - $params[$index]['gis_type'] = 'MULTILINESTRING'; - $wkt = $value; - } - // Trim to remove leading 'MULTILINESTRING((' and trailing '))' - $multilinestirng = mb_substr($wkt, 17, -2); - // Separate each linestring - $linestirngs = explode('),(', $multilinestirng); - $params[$index]['MULTILINESTRING']['no_of_lines'] = count($linestirngs); + $wkt_multilinestring = mb_substr($wkt, 17, -2); + $wkt_linestrings = explode('),(', $wkt_multilinestring); + $coords = ['no_of_lines' => count($wkt_linestrings)]; - $j = 0; - foreach ($linestirngs as $linestring) { - $points_arr = $this->extractPoints($linestring, null); - $no_of_points = count($points_arr); - $params[$index]['MULTILINESTRING'][$j]['no_of_points'] = $no_of_points; + foreach ($wkt_linestrings as $j => $wkt_linestring) { + $points = $this->extractPoints($wkt_linestring, null); + $no_of_points = count($points); + $coords[$j] = ['no_of_points' => $no_of_points]; for ($i = 0; $i < $no_of_points; $i++) { - $params[$index]['MULTILINESTRING'][$j][$i]['x'] = $points_arr[$i][0]; - $params[$index]['MULTILINESTRING'][$j][$i]['y'] = $points_arr[$i][1]; + $coords[$j][$i] = [ + 'x' => $points[$i][0], + 'y' => $points[$i][1], + ]; } - - $j++; } - return $params; + return $coords; } } diff --git a/libraries/classes/Gis/GisMultiPoint.php b/libraries/classes/Gis/GisMultiPoint.php index c1d6e75a8a..292c118632 100644 --- a/libraries/classes/Gis/GisMultiPoint.php +++ b/libraries/classes/Gis/GisMultiPoint.php @@ -317,38 +317,28 @@ class GisMultiPoint extends GisGeometry } /** - * Generate parameters for the GIS data editor from the value of the GIS column. + * Generate coordinate parameters for the GIS data editor from the value of the GIS column. * - * @param string $value Value of the GIS column - * @param int $index Index of the geometry + * @param string $wkt Value of the GIS column * - * @return array params for the GIS data editor from the value of the GIS column + * @return array Coordinate params for the GIS data editor from the value of the GIS column */ - public function generateParams($value, $index = -1): array + protected function getCoordinateParams(string $wkt): array { - $params = []; - if ($index == -1) { - $index = 0; - $data = GisGeometry::generateParams($value); - $params['srid'] = $data['srid']; - $wkt = $data['wkt']; - } else { - $params[$index]['gis_type'] = 'MULTIPOINT'; - $wkt = $value; - } - // Trim to remove leading 'MULTIPOINT(' and trailing ')' - $points = mb_substr($wkt, 11, -1); - $points_arr = $this->extractPoints($points, null); + $wkt_points = mb_substr($wkt, 11, -1); + $points = $this->extractPoints($wkt_points, null); - $no_of_points = count($points_arr); - $params[$index]['MULTIPOINT']['no_of_points'] = $no_of_points; + $no_of_points = count($points); + $coords = ['no_of_points' => $no_of_points]; for ($i = 0; $i < $no_of_points; $i++) { - $params[$index]['MULTIPOINT'][$i]['x'] = $points_arr[$i][0]; - $params[$index]['MULTIPOINT'][$i]['y'] = $points_arr[$i][1]; + $coords[$i] = [ + 'x' => $points[$i][0], + 'y' => $points[$i][1], + ]; } - return $params; + return $coords; } /** diff --git a/libraries/classes/Gis/GisMultiPolygon.php b/libraries/classes/Gis/GisMultiPolygon.php index a9ad4b1f87..5a9e6be033 100644 --- a/libraries/classes/Gis/GisMultiPolygon.php +++ b/libraries/classes/Gis/GisMultiPolygon.php @@ -448,54 +448,35 @@ class GisMultiPolygon extends GisGeometry } /** - * Generate parameters for the GIS data editor from the value of the GIS column. + * Generate coordinate parameters for the GIS data editor from the value of the GIS column. * - * @param string $value Value of the GIS column - * @param int $index Index of the geometry + * @param string $wkt Value of the GIS column * - * @return array params for the GIS data editor from the value of the GIS column + * @return array Coordinate params for the GIS data editor from the value of the GIS column */ - public function generateParams($value, $index = -1): array + protected function getCoordinateParams(string $wkt): array { - $params = []; - if ($index == -1) { - $index = 0; - $data = GisGeometry::generateParams($value); - $params['srid'] = $data['srid']; - $wkt = $data['wkt']; - } else { - $params[$index]['gis_type'] = 'MULTIPOLYGON'; - $wkt = $value; - } - // Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))' - $multipolygon = mb_substr($wkt, 15, -3); - // Separate each polygon - $wkt_polygons = explode(')),((', $multipolygon); + $wkt_multipolygon = mb_substr($wkt, 15, -3); + $wkt_polygons = explode(')),((', $wkt_multipolygon); + $coords = ['no_of_polygons' => count($wkt_polygons)]; - $param_row =& $params[$index]['MULTIPOLYGON']; - $param_row['no_of_polygons'] = count($wkt_polygons); - - $k = 0; - foreach ($wkt_polygons as $wkt_polygon) { + foreach ($wkt_polygons as $k => $wkt_polygon) { $wkt_rings = explode('),(', $wkt_polygon); - $param_row[$k]['no_of_lines'] = count($wkt_rings); - $j = 0; - foreach ($wkt_rings as $wkt_ring) { - $points_arr = $this->extractPoints($wkt_ring, null); - $no_of_points = count($points_arr); - $param_row[$k][$j]['no_of_points'] = $no_of_points; + $coords[$k] = ['no_of_lines' => count($wkt_rings)]; + foreach ($wkt_rings as $j => $wkt_ring) { + $points = $this->extractPoints($wkt_ring, null); + $no_of_points = count($points); + $coords[$k][$j] = ['no_of_points' => $no_of_points]; for ($i = 0; $i < $no_of_points; $i++) { - $param_row[$k][$j][$i]['x'] = $points_arr[$i][0]; - $param_row[$k][$j][$i]['y'] = $points_arr[$i][1]; + $coords[$k][$j][$i] = [ + 'x' => $points[$i][0], + 'y' => $points[$i][1], + ]; } - - $j++; } - - $k++; } - return $params; + return $coords; } } diff --git a/libraries/classes/Gis/GisPoint.php b/libraries/classes/Gis/GisPoint.php index 5038bd0a21..84eebfff04 100644 --- a/libraries/classes/Gis/GisPoint.php +++ b/libraries/classes/Gis/GisPoint.php @@ -288,33 +288,21 @@ class GisPoint extends GisGeometry } /** - * Generate parameters for the GIS data editor from the value of the GIS column. + * Generate coordinate parameters for the GIS data editor from the value of the GIS column. * - * @param string $value of the GIS column - * @param int $index of the geometry + * @param string $wkt Value of the GIS column * - * @return array params for the GIS data editor from the value of the GIS column + * @return array Coordinate params for the GIS data editor from the value of the GIS column */ - public function generateParams($value, $index = -1): array + protected function getCoordinateParams(string $wkt): array { - $params = []; - if ($index == -1) { - $index = 0; - $data = GisGeometry::generateParams($value); - $params['srid'] = $data['srid']; - $wkt = $data['wkt']; - } else { - $params[$index]['gis_type'] = 'POINT'; - $wkt = $value; - } - // Trim to remove leading 'POINT(' and trailing ')' - $point = mb_substr($wkt, 6, -1); - $points_arr = $this->extractPoints($point, null); + $wkt_point = mb_substr($wkt, 6, -1); + $points = $this->extractPoints($wkt_point, null); - $params[$index]['POINT']['x'] = $points_arr[0][0]; - $params[$index]['POINT']['y'] = $points_arr[0][1]; - - return $params; + return [ + 'x' => $points[0][0], + 'y' => $points[0][1], + ]; } } diff --git a/libraries/classes/Gis/GisPolygon.php b/libraries/classes/Gis/GisPolygon.php index eb76de4060..a96dc3f8ed 100644 --- a/libraries/classes/Gis/GisPolygon.php +++ b/libraries/classes/Gis/GisPolygon.php @@ -471,45 +471,31 @@ class GisPolygon extends GisGeometry } /** - * Generate parameters for the GIS data editor from the value of the GIS column. + * Generate coordinate parameters for the GIS data editor from the value of the GIS column. * - * @param string $value Value of the GIS column - * @param int $index Index of the geometry + * @param string $wkt Value of the GIS column * - * @return array params for the GIS data editor from the value of the GIS column + * @return array Coordinate params for the GIS data editor from the value of the GIS column */ - public function generateParams($value, $index = -1): array + protected function getCoordinateParams(string $wkt): array { - $params = []; - if ($index == -1) { - $index = 0; - $data = GisGeometry::generateParams($value); - $params['srid'] = $data['srid']; - $wkt = $data['wkt']; - } else { - $params[$index]['gis_type'] = 'POLYGON'; - $wkt = $value; - } - // Trim to remove leading 'POLYGON((' and trailing '))' - $polygon = mb_substr($wkt, 9, -2); - // Separate each linestring - $linerings = explode('),(', $polygon); - $params[$index]['POLYGON']['no_of_lines'] = count($linerings); + $wkt_polygon = mb_substr($wkt, 9, -2); + $wkt_rings = explode('),(', $wkt_polygon); + $coords = ['no_of_lines' => count($wkt_rings)]; - $j = 0; - foreach ($linerings as $linering) { - $points_arr = $this->extractPoints($linering, null); - $no_of_points = count($points_arr); - $params[$index]['POLYGON'][$j]['no_of_points'] = $no_of_points; + foreach ($wkt_rings as $j => $wkt_ring) { + $points = $this->extractPoints($wkt_ring, null); + $no_of_points = count($points); + $coords[$j] = ['no_of_points' => $no_of_points]; for ($i = 0; $i < $no_of_points; $i++) { - $params[$index]['POLYGON'][$j][$i]['x'] = $points_arr[$i][0]; - $params[$index]['POLYGON'][$j][$i]['y'] = $points_arr[$i][1]; + $coords[$j][$i] = [ + 'x' => $points[$i][0], + 'y' => $points[$i][1], + ]; } - - $j++; } - return $params; + return $coords; } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 751777e2d4..066d773f1b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4250,6 +4250,11 @@ parameters: count: 1 path: libraries/classes/Gis/GisGeometry.php + - + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisGeometry\\:\\:getCoordinateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: libraries/classes/Gis/GisGeometry.php + - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisGeometry\\:\\:getLineArrayForOpenLayers\\(\\) has parameter \\$lines with no value type specified in iterable type array\\.$#" count: 1 @@ -4320,6 +4325,11 @@ parameters: count: 1 path: libraries/classes/Gis/GisGeometryCollection.php + - + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisGeometryCollection\\:\\:getCoordinateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: libraries/classes/Gis/GisGeometryCollection.php + - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisGeometryCollection\\:\\:prepareRowAsOl\\(\\) has parameter \\$scale_data with no value type specified in iterable type array\\.$#" count: 1 @@ -4340,23 +4350,18 @@ parameters: count: 1 path: libraries/classes/Gis/GisGeometryCollection.php - - - message: "#^Negated boolean expression is always false\\.$#" - count: 1 - path: libraries/classes/Gis/GisGeometryCollection.php - - message: "#^Static property PhpMyAdmin\\\\Gis\\\\GisGeometryCollection\\:\\:\\$instance \\(PhpMyAdmin\\\\Gis\\\\GisGeometryCollection\\) in isset\\(\\) is not nullable\\.$#" count: 1 path: libraries/classes/Gis/GisGeometryCollection.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisLineString\\:\\:generateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisLineString\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisLineString.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisLineString\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisLineString\\:\\:getCoordinateParams\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisLineString.php @@ -4396,7 +4401,7 @@ parameters: path: libraries/classes/Gis/GisLineString.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiLineString\\:\\:generateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'no_of_points'\\|int\\<0, max\\>, array\\{x\\: mixed, y\\: mixed\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" count: 1 path: libraries/classes/Gis/GisMultiLineString.php @@ -4405,6 +4410,11 @@ parameters: count: 1 path: libraries/classes/Gis/GisMultiLineString.php + - + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiLineString\\:\\:getCoordinateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: libraries/classes/Gis/GisMultiLineString.php + - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiLineString\\:\\:getShape\\(\\) has parameter \\$row_data with no value type specified in iterable type array\\.$#" count: 1 @@ -4446,12 +4456,12 @@ parameters: path: libraries/classes/Gis/GisMultiLineString.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPoint\\:\\:generateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPoint\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisMultiPoint.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPoint\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPoint\\:\\:getCoordinateParams\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisMultiPoint.php @@ -4500,18 +4510,28 @@ parameters: count: 1 path: libraries/classes/Gis/GisMultiPoint.php + - + message: "#^Cannot access offset int on non\\-empty\\-array\\<'no_of_lines'\\|int, array\\{no_of_points\\: int\\<0, max\\>, 0\\?\\: array\\{x\\: mixed, y\\: mixed\\}\\}\\|int\\<1, max\\>\\>\\|int\\<1, max\\>\\.$#" + count: 1 + path: libraries/classes/Gis/GisMultiPolygon.php + + - + message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'no_of_points'\\|int\\<0, max\\>, array\\{x\\: mixed, y\\: mixed\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" + count: 1 + path: libraries/classes/Gis/GisMultiPolygon.php + - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPolygon\\:\\:drawPath\\(\\) has parameter \\$scale_data with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisMultiPolygon.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPolygon\\:\\:generateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPolygon\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisMultiPolygon.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPolygon\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisMultiPolygon\\:\\:getCoordinateParams\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisMultiPolygon.php @@ -4561,12 +4581,12 @@ parameters: path: libraries/classes/Gis/GisMultiPolygon.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPoint\\:\\:generateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPoint\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisPoint.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPoint\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPoint\\:\\:getCoordinateParams\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisPoint.php @@ -4610,6 +4630,11 @@ parameters: count: 1 path: libraries/classes/Gis/GisPoint.php + - + message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<'no_of_points'\\|int\\<0, max\\>, array\\{x\\: mixed, y\\: mixed\\}\\|int\\<0, max\\>\\>\\|int\\<1, max\\>\\.$#" + count: 1 + path: libraries/classes/Gis/GisPolygon.php + - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPolygon\\:\\:area\\(\\) has parameter \\$ring with no value type specified in iterable type array\\.$#" count: 1 @@ -4621,12 +4646,12 @@ parameters: path: libraries/classes/Gis/GisPolygon.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPolygon\\:\\:generateParams\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPolygon\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisPolygon.php - - message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPolygon\\:\\:generateWkt\\(\\) has parameter \\$gis_data with no value type specified in iterable type array\\.$#" + message: "#^Method PhpMyAdmin\\\\Gis\\\\GisPolygon\\:\\:getCoordinateParams\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Gis/GisPolygon.php @@ -10330,11 +10355,6 @@ parameters: count: 1 path: test/classes/Gis/GisGeometryTest.php - - - message: "#^Method PhpMyAdmin\\\\Tests\\\\Gis\\\\GisGeometryTest\\:\\:providerForTestGenerateParams\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: test/classes/Gis/GisGeometryTest.php - - message: "#^Method PhpMyAdmin\\\\Tests\\\\Gis\\\\GisGeometryTest\\:\\:providerForTestGetBoundsForOl\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -10345,6 +10365,11 @@ parameters: count: 1 path: test/classes/Gis/GisGeometryTest.php + - + message: "#^Method PhpMyAdmin\\\\Tests\\\\Gis\\\\GisGeometryTest\\:\\:providerForTestParseWktAndSrid\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: test/classes/Gis/GisGeometryTest.php + - message: "#^Method PhpMyAdmin\\\\Tests\\\\Gis\\\\GisGeometryTest\\:\\:providerForTestSetMinMax\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -10360,11 +10385,6 @@ parameters: count: 1 path: test/classes/Gis/GisGeometryTest.php - - - message: "#^Method PhpMyAdmin\\\\Tests\\\\Gis\\\\GisGeometryTest\\:\\:testGenerateParams\\(\\) has parameter \\$output with no value type specified in iterable type array\\.$#" - count: 1 - path: test/classes/Gis/GisGeometryTest.php - - message: "#^Method PhpMyAdmin\\\\Tests\\\\Gis\\\\GisGeometryTest\\:\\:testGetBoundsForOl\\(\\) has parameter \\$scale_data with no value type specified in iterable type array\\.$#" count: 1 @@ -10375,6 +10395,11 @@ parameters: count: 1 path: test/classes/Gis/GisGeometryTest.php + - + message: "#^Method PhpMyAdmin\\\\Tests\\\\Gis\\\\GisGeometryTest\\:\\:testParseWktAndSrid\\(\\) has parameter \\$output with no value type specified in iterable type array\\.$#" + count: 1 + path: test/classes/Gis/GisGeometryTest.php + - message: "#^Method PhpMyAdmin\\\\Tests\\\\Gis\\\\GisLineStringTest\\:\\:providerForPrepareRowAsOl\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 43ea7983cf..1cf217887a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7870,19 +7870,12 @@ - - ! $gis_obj - $gis_obj - $type - $wkt $geom_count - $type - $wkt isset(self::$instance) @@ -7902,7 +7895,6 @@ $temp_point[0] $temp_point[1] $temp_point[1] - $wkt @@ -7923,27 +7915,13 @@ $temp_point[1] $temp_point[1] - - - - - - - - - - $no_of_points - - - $point $point $point $temp_point $temp_point - $wkt $point[0] @@ -7977,7 +7955,6 @@ $temp_point[0] $temp_point[1] $temp_point[1] - $wkt $data_row[$i] @@ -7992,8 +7969,8 @@ $point[1] $point[1] $point[1] - $points_arr[$i][0] - $points_arr[$i][1] + $points[$i][0] + $points[$i][1] $points_arr[1][0] $points_arr[1][0] $points_arr[1][1] @@ -8005,35 +7982,16 @@ $temp_point[1] $temp_point[1] - - - - - - - - - - - - - - - $data_row $no_of_lines $no_of_points - - - $point $point $point $point $temp_point $temp_point - $wkt @@ -8066,7 +8024,6 @@ $points_arr[0][0] $points_arr[0][1] $points_arr[0][1] - $wkt @@ -8084,8 +8041,8 @@ $point[1] $point[1] $point[1] - $points_arr[$i][0] - $points_arr[$i][1] + $points[$i][0] + $points[$i][1] $points_arr[0][0] $points_arr[0][0] $points_arr[0][1] @@ -8095,26 +8052,12 @@ - - - - - - - - - - $no_of_points - - - $point $point $point $point - $wkt $point[0] @@ -8149,7 +8092,6 @@ - $wkt $data_row[$k] @@ -8165,16 +8107,12 @@ $label_point[0] $label_point[1] $label_point[1] - $param_row[$k] - $param_row[$k][$j] - $param_row[$k][$j][$i] - $point[0] $point[1] - $points_arr[$i][0] - $points_arr[$i][1] + $points[$i][0] + $points[$i][1] $points_arr[0][0] $points_arr[0][1] @@ -8191,20 +8129,6 @@ - $param_row[$k] - $param_row[$k] - $param_row[$k] - $param_row[$k] - $param_row[$k][$j] - $param_row[$k][$j] - $param_row[$k][$j] - $param_row[$k][$j][$i] - $param_row[$k][$j][$i] - - - - - @@ -8232,9 +8156,6 @@ $no_of_lines $no_of_points $no_of_polygons - - - $point $point $ring @@ -8243,7 +8164,6 @@ $ring1 $ring2 - $wkt @@ -8280,38 +8200,25 @@ $points_arr[0][1] $points_arr[0][1] $points_arr[0][1] - $wkt + $points[0][0] + $points[0][1] $points_arr[0][0] $points_arr[0][0] $points_arr[0][0] $points_arr[0][0] $points_arr[0][0] - $points_arr[0][0] - $points_arr[0][1] $points_arr[0][1] $points_arr[0][1] $points_arr[0][1] $points_arr[0][1] $points_arr[0][1] - - - - - - - - - - - $wkt - $points_arr[0][0] $points_arr[0][1] @@ -8341,7 +8248,6 @@ $points_arr[2] $points_arr[3] $points_arr[3] - $wkt ($y1 - $y0) ** 2 + ($x0 - $x1) ** 2 @@ -8367,8 +8273,8 @@ $point[0] $point[1] - $points_arr[$i][0] - $points_arr[$i][1] + $points[$i][0] + $points[$i][1] $points_arr[0][0] $points_arr[0][1] @@ -8390,21 +8296,6 @@ - - - - - - - - - - - - - - - $area $area @@ -8417,15 +8308,11 @@ $p1 $p1 $p2 - - - $point - $wkt $x0 $x1 $x2 diff --git a/test/classes/Gis/GisGeomTestCase.php b/test/classes/Gis/GisGeomTestCase.php index 187cf9cb67..4486d9a450 100644 --- a/test/classes/Gis/GisGeomTestCase.php +++ b/test/classes/Gis/GisGeomTestCase.php @@ -8,7 +8,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Gis; use PhpMyAdmin\Gis\GisGeometry; -use PhpMyAdmin\Gis\GisPolygon; use PhpMyAdmin\Gis\ScaleData; use PhpMyAdmin\Tests\AbstractTestCase; use ReflectionProperty; @@ -50,28 +49,16 @@ abstract class GisGeomTestCase extends AbstractTestCase /** * test generateParams method * - * @param string $wkt point in WKT form - * @param int|null $index index - * @param array $params expected output array + * @param string $wkt point in WKT form + * @param array $params expected output array * * @dataProvider providerForTestGenerateParams */ - public function testGenerateParams(string $wkt, int|null $index, array $params): void + public function testGenerateParams(string $wkt, array $params): void { - if ($index === null) { - $this->assertEquals( - $params, - $this->object->generateParams($wkt) - ); - - return; - } - - /** @var GisPolygon $obj or another GisGeometry that supports this definition */ - $obj = $this->object; $this->assertEquals( $params, - $obj->generateParams($wkt, $index) + $this->object->generateParams($wkt) ); } diff --git a/test/classes/Gis/GisGeometryCollectionTest.php b/test/classes/Gis/GisGeometryCollectionTest.php index d71b7ec2ac..9896ea0a7b 100644 --- a/test/classes/Gis/GisGeometryCollectionTest.php +++ b/test/classes/Gis/GisGeometryCollectionTest.php @@ -115,25 +115,210 @@ class GisGeometryCollectionTest extends GisGeomTestCase { return [ [ - 'GEOMETRYCOLLECTION(LINESTRING(5.02 8.45,6.14 0.15))', - 0, + 'GEOMETRYCOLLECTION(' + . 'LINESTRING(5.02 8.45,6.14 0.15)' + . ',MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))' + . ',MULTIPOINT(5.02 8.45,6.14 0.15)' + . ',MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)' + . ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))' + . ',POINT(5.02 8.45)' + . ',POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))' + . ')', [ 'srid' => 0, - 'GEOMETRYCOLLECTION' => ['geom_count' => 1], - '0' => [ + 'GEOMETRYCOLLECTION' => ['geom_count' => 6], + 0 => [ 'gis_type' => 'LINESTRING', 'LINESTRING' => [ 'no_of_points' => 2, - '0' => [ + 0 => [ 'x' => 5.02, 'y' => 8.45, ], - '1' => [ + 1 => [ 'x' => 6.14, 'y' => 0.15, ], ], ], + 1 => [ + 'gis_type' => 'MULTILINESTRING', + 'MULTILINESTRING' => [ + 'no_of_lines' => 2, + 0 => [ + 'no_of_points' => 3, + 0 => [ + 'x' => 36.0, + 'y' => 14.0, + ], + 1 => [ + 'x' => 47.0, + 'y' => 23.0, + ], + 2 => [ + 'x' => 62.0, + 'y' => 75.0, + ], + ], + 1 => [ + 'no_of_points' => 3, + 0 => [ + 'x' => 36.0, + 'y' => 10.0, + ], + 1 => [ + 'x' => 17.0, + 'y' => 23.0, + ], + 2 => [ + 'x' => 178.0, + 'y' => 53.0, + ], + ], + ], + ], + 2 => [ + 'gis_type' => 'MULTIPOINT', + 'MULTIPOINT' => [ + 'no_of_points' => 2, + 0 => [ + 'x' => 5.02, + 'y' => 8.45, + ], + 1 => [ + 'x' => 6.14, + 'y' => 0.15, + ], + ], + ], + 3 => [ + 'gis_type' => 'MULTIPOLYGON', + 'MULTIPOLYGON' => [ + 'no_of_polygons' => 2, + 0 => [ + 'no_of_lines' => 2, + 0 => [ + 'no_of_points' => 5, + 0 => [ + 'x' => 35.0, + 'y' => 10.0, + ], + 1 => [ + 'x' => 10.0, + 'y' => 20.0, + ], + 2 => [ + 'x' => 15.0, + 'y' => 40.0, + ], + 3 => [ + 'x' => 45.0, + 'y' => 45.0, + ], + 4 => [ + 'x' => 35.0, + 'y' => 10.0, + ], + ], + 1 => [ + 'no_of_points' => 4, + 0 => [ + 'x' => 20.0, + 'y' => 30.0, + ], + 1 => [ + 'x' => 35.0, + 'y' => 32.0, + ], + 2 => [ + 'x' => 30.0, + 'y' => 20.0, + ], + 3 => [ + 'x' => 20.0, + 'y' => 30.0, + ], + ], + ], + 1 => [ + 'no_of_lines' => 1, + 0 => [ + 'no_of_points' => 4, + 0 => [ + 'x' => 123.0, + 'y' => 0.0, + ], + 1 => [ + 'x' => 23.0, + 'y' => 30.0, + ], + 2 => [ + 'x' => 17.0, + 'y' => 63.0, + ], + 3 => [ + 'x' => 123.0, + 'y' => 0.0, + ], + ], + ], + ], + ], + 4 => [ + 'gis_type' => 'POINT', + 'POINT' => [ + 'x' => 5.02, + 'y' => 8.45, + ], + ], + 5 => [ + 'gis_type' => 'POLYGON', + 'POLYGON' => [ + 'no_of_lines' => 2, + 0 => [ + 'no_of_points' => 5, + 0 => [ + 'x' => 35.0, + 'y' => 10.0, + ], + 1 => [ + 'x' => 10.0, + 'y' => 20.0, + ], + 2 => [ + 'x' => 15.0, + 'y' => 40.0, + ], + 3 => [ + 'x' => 45.0, + 'y' => 45.0, + ], + 4 => [ + 'x' => 35.0, + 'y' => 10.0, + ], + ], + 1 => [ + 'no_of_points' => 4, + 0 => [ + 'x' => 20.0, + 'y' => 30.0, + ], + 1 => [ + 'x' => 35.0, + 'y' => 32.0, + ], + 2 => [ + 'x' => 30.0, + 'y' => 20.0, + ], + 3 => [ + 'x' => 20.0, + 'y' => 30.0, + ], + ], + ], + ], ], ], ]; diff --git a/test/classes/Gis/GisGeometryTest.php b/test/classes/Gis/GisGeometryTest.php index 972f5ee1ee..f4c0314a0d 100644 --- a/test/classes/Gis/GisGeometryTest.php +++ b/test/classes/Gis/GisGeometryTest.php @@ -84,32 +84,32 @@ class GisGeometryTest extends AbstractTestCase } /** - * tests generateParams method + * tests parseWktAndSrid method * * @param string $value Geometry data * @param array $output Expected output * - * @dataProvider providerForTestGenerateParams + * @dataProvider providerForTestParseWktAndSrid */ - public function testGenerateParams(string $value, array $output): void + public function testParseWktAndSrid(string $value, array $output): void { $this->assertEquals( $output, $this->callFunction( $this->object, GisGeometry::class, - 'generateParams', + 'parseWktAndSrid', [$value] ) ); } /** - * data provider for testGenerateParams + * data provider for testParseWktAndSrid * - * @return array data for testGenerateParams + * @return array data for testParseWktAndSrid */ - public static function providerForTestGenerateParams(): array + public static function providerForTestParseWktAndSrid(): array { return [ [ diff --git a/test/classes/Gis/GisLineStringTest.php b/test/classes/Gis/GisLineStringTest.php index 8296f68a6d..6f4ae2cc19 100644 --- a/test/classes/Gis/GisLineStringTest.php +++ b/test/classes/Gis/GisLineStringTest.php @@ -111,36 +111,26 @@ class GisLineStringTest extends GisGeomTestCase */ public static function providerForTestGenerateParams(): array { - $temp = [ - 'LINESTRING' => [ - 'no_of_points' => 2, - 0 => [ - 'x' => '5.02', - 'y' => '8.45', - ], - 1 => [ - 'x' => '6.14', - 'y' => '0.15', - ], - ], - ]; - $temp1 = $temp; - $temp1['gis_type'] = 'LINESTRING'; - return [ [ "'LINESTRING(5.02 8.45,6.14 0.15)',124", - null, [ 'srid' => 124, - 0 => $temp, + 0 => [ + 'LINESTRING' => [ + 'no_of_points' => 2, + 0 => [ + 'x' => 5.02, + 'y' => 8.45, + ], + 1 => [ + 'x' => 6.14, + 'y' => 0.15, + ], + ], + ], ], ], - [ - 'LINESTRING(5.02 8.45,6.14 0.15)', - 2, - [2 => $temp1], - ], ]; } diff --git a/test/classes/Gis/GisMultiLineStringTest.php b/test/classes/Gis/GisMultiLineStringTest.php index 600ea44374..a27b701e9b 100644 --- a/test/classes/Gis/GisMultiLineStringTest.php +++ b/test/classes/Gis/GisMultiLineStringTest.php @@ -178,51 +178,40 @@ class GisMultiLineStringTest extends GisGeomTestCase */ public static function providerForTestGenerateParams(): array { - $temp = [ - 'MULTILINESTRING' => [ - 'no_of_lines' => 2, - 0 => [ - 'no_of_points' => 2, - 0 => [ - 'x' => 5.02, - 'y' => 8.45, - ], - 1 => [ - 'x' => 6.14, - 'y' => 0.15, - ], - ], - 1 => [ - 'no_of_points' => 2, - 0 => [ - 'x' => 1.23, - 'y' => 4.25, - ], - 1 => [ - 'x' => 9.15, - 'y' => 0.47, - ], - ], - ], - ]; - - $temp1 = $temp; - $temp1['gis_type'] = 'MULTILINESTRING'; - return [ [ "'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))',124", - null, [ 'srid' => 124, - 0 => $temp, + 0 => [ + 'MULTILINESTRING' => [ + 'no_of_lines' => 2, + 0 => [ + 'no_of_points' => 2, + 0 => [ + 'x' => 5.02, + 'y' => 8.45, + ], + 1 => [ + 'x' => 6.14, + 'y' => 0.15, + ], + ], + 1 => [ + 'no_of_points' => 2, + 0 => [ + 'x' => 1.23, + 'y' => 4.25, + ], + 1 => [ + 'x' => 9.15, + 'y' => 0.47, + ], + ], + ], + ], ], ], - [ - 'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))', - 2, - [2 => $temp1], - ], ]; } diff --git a/test/classes/Gis/GisMultiPointTest.php b/test/classes/Gis/GisMultiPointTest.php index 8c8d6b29af..74d54e3bc7 100644 --- a/test/classes/Gis/GisMultiPointTest.php +++ b/test/classes/Gis/GisMultiPointTest.php @@ -115,36 +115,26 @@ class GisMultiPointTest extends GisGeomTestCase */ public static function providerForTestGenerateParams(): array { - $temp1 = [ - 'MULTIPOINT' => [ - 'no_of_points' => 2, - 0 => [ - 'x' => '5.02', - 'y' => '8.45', - ], - 1 => [ - 'x' => '6.14', - 'y' => '0.15', - ], - ], - ]; - $temp2 = $temp1; - $temp2['gis_type'] = 'MULTIPOINT'; - return [ [ "'MULTIPOINT(5.02 8.45,6.14 0.15)',124", - null, [ 'srid' => 124, - 0 => $temp1, + 0 => [ + 'MULTIPOINT' => [ + 'no_of_points' => 2, + 0 => [ + 'x' => 5.02, + 'y' => 8.45, + ], + 1 => [ + 'x' => 6.14, + 'y' => 0.15, + ], + ], + ], ], ], - [ - 'MULTIPOINT(5.02 8.45,6.14 0.15)', - 2, - [2 => $temp2], - ], ]; } diff --git a/test/classes/Gis/GisMultiPolygonTest.php b/test/classes/Gis/GisMultiPolygonTest.php index 71b661f755..f7d6c12524 100644 --- a/test/classes/Gis/GisMultiPolygonTest.php +++ b/test/classes/Gis/GisMultiPolygonTest.php @@ -181,27 +181,15 @@ class GisMultiPolygonTest extends GisGeomTestCase */ public static function providerForTestGenerateParams(): array { - $temp = self::getData(); - - $temp1 = self::getData(); - $temp1['gis_type'] = 'MULTIPOLYGON'; - return [ [ "'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)," . "(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))',124", - null, [ 'srid' => 124, - 0 => $temp, + 0 => self::getData(), ], ], - [ - 'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)' - . ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))', - 2, - [2 => $temp1], - ], ]; } diff --git a/test/classes/Gis/GisPointTest.php b/test/classes/Gis/GisPointTest.php index 787d3dfb85..f61dccdc7b 100644 --- a/test/classes/Gis/GisPointTest.php +++ b/test/classes/Gis/GisPointTest.php @@ -137,26 +137,12 @@ class GisPointTest extends GisGeomTestCase return [ [ "'POINT(5.02 8.45)',124", - null, [ 'srid' => 124, 0 => [ 'POINT' => [ - 'x' => '5.02', - 'y' => '8.45', - ], - ], - ], - ], - [ - 'POINT(5.02 8.45)', - 2, - [ - 2 => [ - 'gis_type' => 'POINT', - 'POINT' => [ - 'x' => '5.02', - 'y' => '8.45', + 'x' => 5.02, + 'y' => 8.45, ], ], ], diff --git a/test/classes/Gis/GisPolygonTest.php b/test/classes/Gis/GisPolygonTest.php index 4b767699ce..121f47c3a8 100644 --- a/test/classes/Gis/GisPolygonTest.php +++ b/test/classes/Gis/GisPolygonTest.php @@ -167,25 +167,14 @@ class GisPolygonTest extends GisGeomTestCase */ public static function providerForTestGenerateParams(): array { - $temp = self::getData(); - - $temp1 = $temp; - $temp1['gis_type'] = 'POLYGON'; - return [ [ '\'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))\',124', - null, [ 'srid' => 124, - 0 => $temp, + 0 => self::getData(), ], ], - [ - 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))', - 2, - [2 => $temp1], - ], ]; }