@@ -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,27 @@ 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+ if (get_parent_class ($ this ) === self ::class) {
144+ $ type = class_basename (static ::class);
145+ } else {
146+ $ types = array_values (class_parents ($ this ));
147+ $ type = class_basename ($ types [count ($ types ) - 2 ]);
148+ }
149+
143150 return [
144- 'type ' => class_basename ( static ::class) ,
151+ 'type ' => $ type ,
145152 'coordinates ' => $ this ->getCoordinates (),
146153 ];
147154 }
@@ -173,7 +180,7 @@ public function toFeatureCollectionJson(): string
173180 }
174181
175182 /**
176- * @return array<mixed>
183+ * @return array{0: float, 1: float}
177184 */
178185 abstract public function getCoordinates (): array ;
179186
0 commit comments