Skip to content

Commit 7006c90

Browse files
committed
improve types
Fix styling
1 parent 80dd489 commit 7006c90

11 files changed

+45
-91
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Call to an undefined method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface\\:\\:getSrid\\(\\)\\.$#"
5-
count: 1
6-
path: src/Eloquent/SpatialExpression.php
7-
83
-
94
message: "#^PHPDoc type Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface of property Grimzy\\\\LaravelMysqlSpatial\\\\Eloquent\\\\SpatialExpression\\:\\:\\$value is not covariant with PHPDoc type float\\|int\\|string of overridden property Illuminate\\\\Database\\\\Query\\\\Expression\\:\\:\\$value\\.$#"
105
count: 1
@@ -30,11 +25,6 @@ parameters:
3025
count: 1
3126
path: src/Schema/Grammars/MySqlGrammar.php
3227

33-
-
34-
message: "#^Call to an undefined method GeoJson\\\\GeoJson\\:\\:getGeometry\\(\\)\\.$#"
35-
count: 1
36-
path: src/Types/Geometry.php
37-
3828
-
3929
message: "#^Method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\Geometry\\:\\:fromWKT\\(\\) should return static\\(Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\Geometry\\) but returns Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface\\.$#"
4030
count: 1
@@ -45,61 +35,21 @@ parameters:
4535
count: 2
4636
path: src/Types/GeometryCollection.php
4737

48-
-
49-
message: "#^Method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface\\:\\:jsonSerialize\\(\\) has no return type specified\\.$#"
50-
count: 1
51-
path: src/Types/GeometryInterface.php
52-
53-
-
54-
message: "#^Return type \\(GeoJson\\\\Geometry\\\\LineString\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\LineString\\:\\:jsonSerialize\\(\\) should be compatible with return type \\(GeoJson\\\\Geometry\\\\GeometryCollection\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryCollection\\:\\:jsonSerialize\\(\\)$#"
55-
count: 1
56-
path: src/Types/LineString.php
57-
5838
-
5939
message: "#^Unsafe usage of new static\\(\\)\\.$#"
6040
count: 1
6141
path: src/Types/LineString.php
6242

63-
-
64-
message: "#^Return type \\(GeoJson\\\\Geometry\\\\MultiLineString\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\MultiLineString\\:\\:jsonSerialize\\(\\) should be compatible with return type \\(GeoJson\\\\Geometry\\\\GeometryCollection\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryCollection\\:\\:jsonSerialize\\(\\)$#"
65-
count: 1
66-
path: src/Types/MultiLineString.php
67-
6843
-
6944
message: "#^Unsafe usage of new static\\(\\)\\.$#"
7045
count: 1
7146
path: src/Types/MultiLineString.php
7247

73-
-
74-
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface\\)\\: mixed\\)\\|null, Closure\\(Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\Point\\)\\: non\\-falsy\\-string given\\.$#"
75-
count: 1
76-
path: src/Types/MultiPoint.php
77-
78-
-
79-
message: "#^Return type \\(GeoJson\\\\Geometry\\\\MultiPoint\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\MultiPoint\\:\\:jsonSerialize\\(\\) should be compatible with return type \\(GeoJson\\\\Geometry\\\\GeometryCollection\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryCollection\\:\\:jsonSerialize\\(\\)$#"
80-
count: 1
81-
path: src/Types/MultiPoint.php
82-
8348
-
8449
message: "#^Unsafe usage of new static\\(\\)\\.$#"
8550
count: 1
8651
path: src/Types/MultiPoint.php
8752

88-
-
89-
message: "#^Method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\MultiPolygon\\:\\:getPolygons\\(\\) should return array\\<Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\Polygon\\> but returns array\\<Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface\\>\\.$#"
90-
count: 1
91-
path: src/Types/MultiPolygon.php
92-
93-
-
94-
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface\\)\\: mixed\\)\\|null, Closure\\(Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\Polygon\\)\\: non\\-falsy\\-string given\\.$#"
95-
count: 1
96-
path: src/Types/MultiPolygon.php
97-
98-
-
99-
message: "#^Return type \\(GeoJson\\\\Geometry\\\\MultiPolygon\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\MultiPolygon\\:\\:jsonSerialize\\(\\) should be compatible with return type \\(GeoJson\\\\Geometry\\\\GeometryCollection\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryCollection\\:\\:jsonSerialize\\(\\)$#"
100-
count: 1
101-
path: src/Types/MultiPolygon.php
102-
10353
-
10454
message: "#^Unsafe usage of new static\\(\\)\\.$#"
10555
count: 1
@@ -110,17 +60,3 @@ parameters:
11060
count: 1
11161
path: src/Types/Point.php
11262

113-
-
114-
message: "#^Method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\PointCollection\\:\\:getPoints\\(\\) should return array\\<Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\Point\\> but returns array\\<Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface\\>\\.$#"
115-
count: 1
116-
path: src/Types/PointCollection.php
117-
118-
-
119-
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\GeometryInterface\\)\\: mixed\\)\\|null, Closure\\(Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\Point\\)\\: string given\\.$#"
120-
count: 1
121-
path: src/Types/PointCollection.php
122-
123-
-
124-
message: "#^Return type \\(GeoJson\\\\Geometry\\\\Polygon\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\Polygon\\:\\:jsonSerialize\\(\\) should be compatible with return type \\(GeoJson\\\\Geometry\\\\MultiLineString\\) of method Grimzy\\\\LaravelMysqlSpatial\\\\Types\\\\MultiLineString\\:\\:jsonSerialize\\(\\)$#"
125-
count: 1
126-
path: src/Types/Polygon.php

src/Types/Geometry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public static function fromJson(string|GeoJson $geoJson): self
9898
return GeometryCollection::fromJson($geoJson);
9999
}
100100

101+
/** @var Feature $geoJson */
101102
if ($geoJson->getType() === 'Feature') {
102-
/** @var Feature $geoJson */
103103
$geoJson = $geoJson->getGeometry();
104104
}
105105

src/Types/GeometryCollection.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
use InvalidArgumentException;
1313
use IteratorAggregate;
1414

15-
class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAccess, Arrayable, Countable
15+
/**
16+
* @template G
17+
*
18+
* @implements GeometryInterface<FeatureCollection>
19+
*/
20+
class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAccess, Arrayable, Countable, GeometryInterface
1621
{
1722
/**
1823
* The minimum number of items required to create this collection.
@@ -27,7 +32,7 @@ class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAcc
2732
/**
2833
* The items contained in the spatial collection.
2934
*
30-
* @var GeometryInterface[]
35+
* @var G[]
3136
*/
3237
protected array $items = [];
3338

@@ -46,7 +51,7 @@ public function __construct(array $geometries, ?int $srid = 0)
4651
}
4752

4853
/**
49-
* @return GeometryInterface[]
54+
* @return G[]
5055
*/
5156
public function getGeometries(): array
5257
{
@@ -140,8 +145,6 @@ public static function fromJson(string|GeoJson $geoJson): self
140145

141146
/**
142147
* Convert to GeoJson GeometryCollection that is jsonable to GeoJSON.
143-
*
144-
* @return \GeoJson\Geometry\GeometryCollection
145148
*/
146149
#[\ReturnTypeWillChange]
147150
public function jsonSerialize()

src/Types/GeometryInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use GeoJson\GeoJson;
66

7+
/**
8+
* @template T
9+
*/
710
interface GeometryInterface
811
{
912
public function toWKT(): string;
@@ -16,5 +19,10 @@ public static function fromString(string $wktArgument, int $srid = 0): self;
1619

1720
public static function fromJson(string|GeoJson $geoJson): self;
1821

22+
/**
23+
* @return T
24+
*/
1925
public function jsonSerialize();
26+
27+
public function getSrid(): int;
2028
}

src/Types/LineString.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ public static function fromJson(string|GeoJson $geoJson): self
5858

5959
/**
6060
* Convert to GeoJson LineString that is jsonable to GeoJSON.
61-
*
62-
* @return \GeoJson\Geometry\LineString
6361
*/
6462
#[\ReturnTypeWillChange]
6563
public function jsonSerialize()

src/Types/MultiLineString.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
use GeoJson\Geometry\MultiLineString as GeoJsonMultiLineString;
77
use Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException;
88

9-
class MultiLineString extends GeometryCollection
9+
/**
10+
* @implements GeometryInterface<LineString>
11+
*
12+
* @extends GeometryCollection<LineString>
13+
*/
14+
class MultiLineString extends GeometryCollection implements GeometryInterface
1015
{
1116
/**
1217
* The minimum number of items required to create this collection.
@@ -72,8 +77,6 @@ public static function fromJson(string|GeoJson $geoJson): self
7277

7378
/**
7479
* Convert to GeoJson Point that is jsonable to GeoJSON.
75-
*
76-
* @return \GeoJson\Geometry\MultiLineString
7780
*/
7881
#[\ReturnTypeWillChange]
7982
public function jsonSerialize()

src/Types/MultiPoint.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
use GeoJson\Geometry\MultiPoint as GeoJsonMultiPoint;
77
use Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException;
88

9-
class MultiPoint extends PointCollection
9+
/**
10+
* @implements GeometryInterface<Point>
11+
*/
12+
class MultiPoint extends PointCollection implements GeometryInterface
1013
{
1114
/**
1215
* The minimum number of items required to create this collection.
@@ -61,7 +64,7 @@ public static function fromJson(string|GeoJson $geoJson): self
6164
/**
6265
* Convert to GeoJson MultiPoint that is jsonable to GeoJSON.
6366
*/
64-
public function jsonSerialize(): GeoJsonMultiPoint
67+
public function jsonSerialize()
6568
{
6669
$points = [];
6770
foreach ($this->items as $point) {

src/Types/MultiPolygon.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
use GeoJson\Geometry\MultiPolygon as GeoJsonMultiPolygon;
77
use Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException;
88

9-
class MultiPolygon extends GeometryCollection
9+
/**
10+
* @implements GeometryInterface<MultiPolygon>
11+
*
12+
* @extends GeometryCollection<Polygon>
13+
*/
14+
class MultiPolygon extends GeometryCollection implements GeometryInterface
1015
{
1116
/**
1217
* The minimum number of items required to create this collection.
@@ -38,8 +43,6 @@ public static function fromString(string $wktArgument, int $srid = 0): static
3843

3944
/**
4045
* Get the polygons that make up this MultiPolygon.
41-
*
42-
* @return array|Polygon[]
4346
*/
4447
public function getPolygons(): array
4548
{
@@ -112,8 +115,6 @@ public static function fromJson(string|GeoJson $geoJson): self
112115

113116
/**
114117
* Convert to GeoJson MultiPolygon that is jsonable to GeoJSON.
115-
*
116-
* @return \GeoJson\Geometry\MultiPolygon
117118
*/
118119
#[\ReturnTypeWillChange]
119120
public function jsonSerialize()

src/Types/Point.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
use GeoJson\Geometry\Point as GeoJsonPoint;
77
use Grimzy\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException;
88

9-
class Point extends Geometry
9+
/**
10+
* @implements GeometryInterface<GeoJsonPoint>
11+
*/
12+
class Point extends Geometry implements GeometryInterface
1013
{
1114
protected float $lat;
1215

@@ -88,8 +91,6 @@ public static function fromJson(string|GeoJson $geoJson): self
8891

8992
/**
9093
* Convert to GeoJson Point that is jsonable to GeoJSON.
91-
*
92-
* @return \GeoJson\Geometry\Point
9394
*/
9495
#[\ReturnTypeWillChange]
9596
public function jsonSerialize()

src/Types/PointCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Grimzy\LaravelMysqlSpatial\Types;
44

5+
/**
6+
* @extends GeometryCollection<Point>
7+
*/
58
abstract class PointCollection extends GeometryCollection
69
{
710
/**
@@ -21,9 +24,6 @@ public function offsetSet($offset, $value): void
2124
parent::offsetSet($offset, $value);
2225
}
2326

24-
/**
25-
* @return array|\Grimzy\LaravelMysqlSpatial\Types\Point[]
26-
*/
2727
public function getPoints(): array
2828
{
2929
return $this->items;

0 commit comments

Comments
 (0)