13
13
use Limenet \LaravelMysqlSpatial \Exceptions \InvalidGeoJsonException ;
14
14
15
15
/**
16
- * @template G
16
+ * @template GeoType of GeometryInterface
17
17
*
18
18
* @implements GeometryInterface<FeatureCollection>
19
19
*/
@@ -32,12 +32,12 @@ class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAcc
32
32
/**
33
33
* The items contained in the spatial collection.
34
34
*
35
- * @var G []
35
+ * @var GeoType []
36
36
*/
37
37
protected array $ items = [];
38
38
39
39
/**
40
- * @param GeometryInterface [] $geometries
40
+ * @param GeoType [] $geometries
41
41
*
42
42
* @throws InvalidArgumentException
43
43
*/
@@ -51,7 +51,7 @@ public function __construct(array $geometries, ?int $srid = 0)
51
51
}
52
52
53
53
/**
54
- * @return G []
54
+ * @return GeoType []
55
55
*/
56
56
public function getGeometries (): array
57
57
{
@@ -75,12 +75,11 @@ public static function fromString(string $wktArgument, int $srid = 0): static
75
75
}
76
76
77
77
$ geometry_strings = preg_split ('/,\s*(?=[A-Za-z])/ ' , $ wktArgument );
78
+ if ($ geometry_strings === false ) {
79
+ return new static ([]);
80
+ }
78
81
79
- return new static (array_map (function ($ geometry_string ) {
80
- $ klass = Geometry::getWKTClass ($ geometry_string );
81
-
82
- return call_user_func ($ klass .'::fromWKT ' , $ geometry_string );
83
- }, $ geometry_strings ), $ srid );
82
+ return new static (array_map (fn ($ geometry_string ) => call_user_func ([Geometry::getWKTClass ($ geometry_string ), 'fromWKT ' ], $ geometry_string ), $ geometry_strings ), $ srid );
84
83
}
85
84
86
85
public function toArray ()
@@ -159,6 +158,8 @@ public function jsonSerialize()
159
158
160
159
/**
161
160
* Checks whether the items are valid to create this collection.
161
+ *
162
+ * @param GeoType[] $items
162
163
*/
163
164
protected function validateItems (array $ items ): void
164
165
{
@@ -172,7 +173,7 @@ protected function validateItems(array $items): void
172
173
/**
173
174
* Checks whether the array has enough items to generate a valid WKT.
174
175
*
175
- * @param GeometryInterface [] $items
176
+ * @param GeoType [] $items
176
177
*
177
178
* @see $minimumCollectionItems
178
179
*/
0 commit comments