11<?php
22
3+ declare (strict_types=1 );
4+
35namespace MatanYadaev \EloquentSpatial \Objects ;
46
57use Illuminate \Database \Query \Expression ;
@@ -18,7 +20,8 @@ class GeometryCollection extends Geometry
1820 protected int $ minimumGeometries = 0 ;
1921
2022 /**
21- * @param Collection<Geometry>|Geometry[] $geometries
23+ * @param Collection<Geometry>|array<Geometry> $geometries
24+ *
2225 * @throws InvalidArgumentException
2326 */
2427 public function __construct (Collection | array $ geometries )
@@ -33,51 +36,13 @@ public function __construct(Collection | array $geometries)
3336 $ this ->validateGeometriesType ();
3437 }
3538
36- /**
37- * @throws InvalidArgumentException
38- */
39- protected function validateGeometriesCount (): void
40- {
41- $ geometriesCount = $ this ->geometries ->count ();
42- if ($ geometriesCount < $ this ->minimumGeometries ) {
43- $ className = self ::class;
44-
45- throw new InvalidArgumentException ("{$ className } must contain at least {$ this ->minimumGeometries } " .Str::plural ('entries ' , $ geometriesCount ));
46- }
47- }
48-
49- /**
50- * @throws InvalidArgumentException
51- */
52- protected function validateGeometriesType (): void
53- {
54- $ this ->geometries ->each (function (Geometry $ geometry ): void {
55- if (! ($ geometry instanceof $ this ->collectionOf )) {
56- $ className = self ::class;
57-
58- throw new InvalidArgumentException ("{$ className } must be a collection of {$ this ->collectionOf }" );
59- }
60- });
61- }
62-
6339 public function toWkt (): Expression
6440 {
6541 return new Expression ("GEOMETRYCOLLECTION( {$ this ->toCollectionWkt ()}) " );
6642 }
6743
68- protected function toCollectionWkt (): Expression
69- {
70- $ wkb = $ this ->geometries
71- ->map (static function (Geometry $ geometry ): string {
72- return $ geometry ->toWkt ();
73- })
74- ->join (', ' );
75-
76- return DB ::raw ($ wkb );
77- }
78-
7944 /**
80- * @return mixed[]
45+ * @return array< mixed>
8146 */
8247 public function getCoordinates (): array
8348 {
@@ -89,7 +54,7 @@ public function getCoordinates(): array
8954 }
9055
9156 /**
92- * @return mixed[]
57+ * @return array< mixed>
9358 */
9459 public function toArray (): array
9560 {
@@ -106,10 +71,48 @@ public function toArray(): array
10671 }
10772
10873 /**
109- * @return Geometry[]
74+ * @return array< Geometry>
11075 */
11176 public function getGeometries (): array
11277 {
11378 return $ this ->geometries ->all ();
11479 }
80+
81+ /**
82+ * @throws InvalidArgumentException
83+ */
84+ protected function validateGeometriesCount (): void
85+ {
86+ $ geometriesCount = $ this ->geometries ->count ();
87+ if ($ geometriesCount < $ this ->minimumGeometries ) {
88+ $ className = self ::class;
89+
90+ throw new InvalidArgumentException ("{$ className } must contain at least {$ this ->minimumGeometries } " .Str::plural ('entries ' , $ geometriesCount ));
91+ }
92+ }
93+
94+ /**
95+ * @throws InvalidArgumentException
96+ */
97+ protected function validateGeometriesType (): void
98+ {
99+ $ this ->geometries ->each (function (Geometry $ geometry ): void {
100+ if (! ($ geometry instanceof $ this ->collectionOf )) {
101+ $ className = self ::class;
102+
103+ throw new InvalidArgumentException ("{$ className } must be a collection of {$ this ->collectionOf }" );
104+ }
105+ });
106+ }
107+
108+ protected function toCollectionWkt (): Expression
109+ {
110+ $ wkb = $ this ->geometries
111+ ->map (static function (Geometry $ geometry ): string {
112+ return $ geometry ->toWkt ();
113+ })
114+ ->join (', ' );
115+
116+ return DB ::raw ($ wkb );
117+ }
115118}
0 commit comments