Skip to content

Commit 8029a11

Browse files
committed
move toFeatureCollectionJson to Geometry
1 parent 5189c67 commit 8029a11

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

phpinsights.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
InlineDocCommentDeclarationSniff::class => [
9797
'exclude' => [
9898
'src/Factory.php',
99+
'src/Objects/Geometry.php',
99100
],
100101
],
101102
UnusedParameterSniff::class => [

src/Objects/Geometry.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,27 @@ public function toArray(): array
8282
];
8383
}
8484

85-
/**
86-
* @return array{
87-
* type: string, properties: array<mixed>, geometry: array{type: string, coordinates: array<mixed>}
88-
* }
89-
*/
90-
public function toFeature(): array
85+
public function toFeatureCollectionJson(): string
9186
{
92-
return [
93-
'type' => 'Feature',
94-
'properties' => [],
95-
'geometry' => $this->toArray(),
96-
];
87+
if (static::class === GeometryCollection::class) {
88+
/** @var GeometryCollection $this */
89+
$geometries = $this->geometries;
90+
} else {
91+
$geometries = collect([$this]);
92+
}
93+
94+
$features = $geometries->map(static function (self $geometry): array {
95+
return [
96+
'type' => 'Feature',
97+
'properties' => [],
98+
'geometry' => $geometry->toArray(),
99+
];
100+
});
101+
102+
return json_encode([
103+
'type' => 'FeatureCollection',
104+
'features' => $features,
105+
]);
97106
}
98107

99108
/**

src/Objects/GeometryCollection.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,6 @@ public function getGeometries(): array
7878
return $this->geometries->all();
7979
}
8080

81-
public function toFeatureCollectionJson(): string
82-
{
83-
/** @var Collection<Geometry> $geometries */
84-
$geometries = static::class === self::class
85-
? $this->geometries
86-
: collect([$this]);
87-
88-
$features = $geometries->map(static function (Geometry $geometry): array {
89-
return $geometry->toFeature();
90-
});
91-
92-
return json_encode([
93-
'type' => 'FeatureCollection',
94-
'features' => $features,
95-
]);
96-
}
97-
9881
/**
9982
* @throws InvalidArgumentException
10083
*/

0 commit comments

Comments
 (0)