@@ -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,32 @@ 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{0: float, 1: float} }
140140 */
141141 public function toArray (): array
142142 {
143+ if (str_starts_with (static ::class, __NAMESPACE__ )) {
144+ $ type = class_basename (static ::class);
145+ } else {
146+ $ parents = class_parents ($ this );
147+ if ($ parents === false ) { // @codeCoverageIgnore
148+ throw new LaravelSpatialException ('No parents ' ); // @codeCoverageIgnore
149+ } // @codeCoverageIgnore
150+
151+ $ types = array_values (array_filter ($ parents , fn (string $ cl ) => str_starts_with ($ cl , __NAMESPACE__ )));
152+ $ type = class_basename ($ types [0 ]);
153+ }
154+
143155 return [
144- 'type ' => class_basename ( static ::class) ,
156+ 'type ' => $ type ,
145157 'coordinates ' => $ this ->getCoordinates (),
146158 ];
147159 }
@@ -173,7 +185,7 @@ public function toFeatureCollectionJson(): string
173185 }
174186
175187 /**
176- * @return array<mixed >
188+ * @return array{0: float, 1: float}|array<int, array{0: float, 1: float} >
177189 */
178190 abstract public function getCoordinates (): array ;
179191
0 commit comments