Skip to content

Commit f899fcd

Browse files
committed
fixes
1 parent 162a929 commit f899fcd

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

phpinsights.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
'exclude' => [
110110
'src/SpatialBuilder.php',
111111
'src/Objects/Geometry.php',
112+
'src/Objects/GeometryCollection.php',
112113
],
113114
],
114115
ClassTraitAndInterfaceLengthSniff::class => [

src/Factory.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525

2626
class Factory
2727
{
28-
public static function parse(string $value): Geometry
28+
public static function parse(string $value, bool $isWkb): Geometry
2929
{
30-
$isJson = (bool) is_object(json_decode($value));
31-
32-
if (! $isJson) {
30+
if ($isWkb) {
3331
// MySQL adds 4 NULL bytes at the start of the WKB
3432
$value = substr($value, 4);
3533
}

src/Objects/Geometry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function toJson($options = 0): string
3232
*/
3333
public static function fromWkb(string $wkb): static
3434
{
35-
$geometry = Factory::parse($wkb);
35+
$geometry = Factory::parse($wkb, true);
3636

3737
if (! ($geometry instanceof static)) {
3838
throw new InvalidArgumentException(
@@ -52,7 +52,7 @@ public static function fromWkb(string $wkb): static
5252
*/
5353
public static function fromJson(string $geoJson): static
5454
{
55-
$geometry = Factory::parse($geoJson);
55+
$geometry = Factory::parse($geoJson, false);
5656

5757
if (! ($geometry instanceof static)) {
5858
throw new InvalidArgumentException(

src/Objects/GeometryCollection.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,45 @@ public function getGeometries(): Collection
7979
return $this->geometries->collect();
8080
}
8181

82+
/**
83+
* @param mixed $offset
84+
*
85+
* @return bool
86+
*/
87+
public function offsetExists($offset): bool
88+
{
89+
return isset($this->geometries[$offset]);
90+
}
91+
92+
/**
93+
* @param mixed $offset
94+
*
95+
* @return Geometry
96+
*/
97+
public function offsetGet($offset): Geometry
98+
{
99+
return $this->geometries[$offset];
100+
}
101+
102+
/**
103+
* @param mixed $offset
104+
* @param Geometry $geometry
105+
*/
106+
public function offsetSet($offset, $geometry): void
107+
{
108+
$this->geometries[$offset] = $geometry;
109+
$this->validateGeometriesType();
110+
}
111+
112+
/**
113+
* @param mixed $offset
114+
*/
115+
public function offsetUnset($offset): void
116+
{
117+
$this->geometries->splice($offset, 1);
118+
$this->validateGeometriesCount();
119+
}
120+
82121
/**
83122
* @throws InvalidArgumentException
84123
*/
@@ -121,41 +160,4 @@ protected function toCollectionWkt(): Expression
121160

122161
return DB::raw($wkb);
123162
}
124-
125-
/**
126-
* @param mixed $offset
127-
* @return bool
128-
*/
129-
public function offsetExists($offset): bool
130-
{
131-
return isset($this->geometries[$offset]);
132-
}
133-
134-
/**
135-
* @param mixed $offset
136-
* @return Geometry
137-
*/
138-
public function offsetGet($offset): Geometry
139-
{
140-
return $this->geometries[$offset];
141-
}
142-
143-
/**
144-
* @param mixed $offset
145-
* @param Geometry $geometry
146-
*/
147-
public function offsetSet($offset, $geometry): void
148-
{
149-
$this->geometries[$offset] = $geometry;
150-
$this->validateGeometriesType();
151-
}
152-
153-
/**
154-
* @param mixed $offset
155-
*/
156-
public function offsetUnset($offset): void
157-
{
158-
$this->geometries->splice($offset, 1);
159-
$this->validateGeometriesCount();
160-
}
161163
}

0 commit comments

Comments
 (0)