1313use Limenet \LaravelMysqlSpatial \Exceptions \InvalidGeoJsonException ;
1414
1515/**
16- * @template G
16+ * @template GeoType of GeometryInterface
1717 *
1818 * @implements GeometryInterface<FeatureCollection>
1919 */
@@ -32,12 +32,12 @@ class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAcc
3232 /**
3333 * The items contained in the spatial collection.
3434 *
35- * @var G []
35+ * @var GeoType []
3636 */
3737 protected array $ items = [];
3838
3939 /**
40- * @param GeometryInterface [] $geometries
40+ * @param GeoType [] $geometries
4141 *
4242 * @throws InvalidArgumentException
4343 */
@@ -51,7 +51,7 @@ public function __construct(array $geometries, ?int $srid = 0)
5151 }
5252
5353 /**
54- * @return G []
54+ * @return GeoType []
5555 */
5656 public function getGeometries (): array
5757 {
@@ -75,12 +75,11 @@ public static function fromString(string $wktArgument, int $srid = 0): static
7575 }
7676
7777 $ geometry_strings = preg_split ('/,\s*(?=[A-Za-z])/ ' , $ wktArgument );
78+ if ($ geometry_strings === false ) {
79+ return new static ([]);
80+ }
7881
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 );
8483 }
8584
8685 public function toArray ()
@@ -159,6 +158,8 @@ public function jsonSerialize()
159158
160159 /**
161160 * Checks whether the items are valid to create this collection.
161+ *
162+ * @param GeoType[] $items
162163 */
163164 protected function validateItems (array $ items ): void
164165 {
@@ -172,7 +173,7 @@ protected function validateItems(array $items): void
172173 /**
173174 * Checks whether the array has enough items to generate a valid WKT.
174175 *
175- * @param GeometryInterface [] $items
176+ * @param GeoType [] $items
176177 *
177178 * @see $minimumCollectionItems
178179 */
0 commit comments