@@ -112,7 +112,7 @@ public static function fromJson(string $geoJson, int $srid = 0): static
112112 }
113113
114114 /**
115- * @param array<mixed> $geometry
115+ * @param array<string, mixed> $geometry
116116 *
117117 * @throws LaravelSpatialJsonException
118118 */
@@ -128,20 +128,29 @@ public static function fromArray(array $geometry): static
128128 }
129129
130130 /**
131- * @return array<mixed>
131+ * @return array<string, mixed>
132132 */
133133 public function jsonSerialize (): array
134134 {
135135 return $ this ->toArray ();
136136 }
137137
138138 /**
139- * @return array{type: string, coordinates: array<mixed>}
139+ * @return array{type: string, coordinates: array<string, mixed>}
140140 */
141141 public function toArray (): array
142142 {
143+ $ ns = str_replace ('\Geometry\Geometry ' , '\Geometry ' , __CLASS__ );
144+
145+ if (str_starts_with (static ::class, $ ns )) {
146+ $ type = class_basename (static ::class);
147+ } else {
148+ $ types = array_values (array_filter (class_parents ($ this ), fn (string $ cl ) => str_starts_with ($ cl , $ ns )));
149+ $ type = class_basename ($ types [0 ]);
150+ }
151+
143152 return [
144- 'type ' => class_basename ( static ::class) ,
153+ 'type ' => $ type ,
145154 'coordinates ' => $ this ->getCoordinates (),
146155 ];
147156 }
@@ -173,7 +182,7 @@ public function toFeatureCollectionJson(): string
173182 }
174183
175184 /**
176- * @return array<mixed>
185+ * @return array{0: float, 1: float}
177186 */
178187 abstract public function getCoordinates (): array ;
179188
0 commit comments