Skip to content

Commit 2fbfbf1

Browse files
authored
removed ignoreErrors from phpstan-configuration (#26)
* removed ignoreErrors from phpstan-configuration. applied corresponding changes * applied changes from feedback * using JSON_THROW_ON_ERROR instead of manually throwing exception
1 parent d58e17c commit 2fbfbf1

File tree

4 files changed

+64
-22
lines changed

4 files changed

+64
-22
lines changed

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ parameters:
66
- tests
77
level: max
88
ignoreErrors:
9-
- '#Method MatanYadaev\\EloquentSpatial\\Objects\\(Geometry|GeometryCollection)::(toJson|toFeatureCollectionJson)\(\) should return string but returns string\|false\.#'
10-
-
11-
message: '#Call to an undefined method .+#'
12-
path: ./src/SpatialBuilder.php
139
excludePaths:
1410
- ./src/Factory.php
1511
checkMissingIterableValueType: true

src/Objects/Geometry.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Contracts\Support\Jsonable;
1111
use Illuminate\Database\Query\Expression;
1212
use InvalidArgumentException;
13+
use JsonException;
1314
use JsonSerializable;
1415
use MatanYadaev\EloquentSpatial\Factory;
1516
use MatanYadaev\EloquentSpatial\GeometryCast;
@@ -18,9 +19,16 @@ abstract class Geometry implements Castable, Arrayable, Jsonable, JsonSerializab
1819
{
1920
abstract public function toWkt(): Expression;
2021

22+
/**
23+
* @param int $options
24+
*
25+
* @return string
26+
*
27+
* @throws JsonException
28+
*/
2129
public function toJson($options = 0): string
2230
{
23-
return json_encode($this, $options);
31+
return json_encode($this, $options | JSON_THROW_ON_ERROR);
2432
}
2533

2634
/**
@@ -80,10 +88,15 @@ public function toArray(): array
8088
];
8189
}
8290

91+
/**
92+
* @return string
93+
*
94+
* @throws JsonException
95+
*/
8396
public function toFeatureCollectionJson(): string
8497
{
8598
if (static::class === GeometryCollection::class) {
86-
/** @var GeometryCollection $this */
99+
/** @var GeometryCollection<Geometry> $this */
87100
$geometries = $this->geometries;
88101
} else {
89102
$geometries = collect([$this]);
@@ -97,10 +110,13 @@ public function toFeatureCollectionJson(): string
97110
];
98111
});
99112

100-
return json_encode([
113+
return json_encode(
114+
[
101115
'type' => 'FeatureCollection',
102116
'features' => $features,
103-
]);
117+
],
118+
JSON_THROW_ON_ERROR
119+
);
104120
}
105121

106122
/**

src/Objects/GeometryCollection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
/**
1515
* @template TGeometry of Geometry
16+
* @implements ArrayAccess<int, TGeometry>
1617
*/
1718
class GeometryCollection extends Geometry implements ArrayAccess
1819
{

src/SpatialBuilder.php

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/**
1212
* @template TModel of \Illuminate\Database\Eloquent\Model
1313
* @extends Builder<TModel>
14+
* @mixin \Illuminate\Database\Query\Builder
1415
*/
1516
class SpatialBuilder extends Builder
1617
{
@@ -23,14 +24,16 @@ public function withDistance(
2324
$this->select('*');
2425
}
2526

26-
return $this->selectRaw(
27+
$this->selectRaw(
2728
sprintf(
2829
'ST_DISTANCE(%s, %s) AS %s',
2930
"`{$column}`",
3031
$this->toExpression($geometryOrColumn),
3132
$alias,
3233
)
3334
);
35+
36+
return $this;
3437
}
3538

3639
public function whereDistance(
@@ -39,7 +42,7 @@ public function whereDistance(
3942
string $operator,
4043
int|float $value
4144
): self {
42-
return $this->whereRaw(
45+
$this->whereRaw(
4346
sprintf(
4447
'ST_DISTANCE(%s, %s) %s %s',
4548
"`{$column}`",
@@ -48,21 +51,25 @@ public function whereDistance(
4851
$value,
4952
)
5053
);
54+
55+
return $this;
5156
}
5257

5358
public function orderByDistance(
5459
string $column,
5560
Geometry|string $geometryOrColumn,
5661
string $direction = 'asc'
5762
): self {
58-
return $this->orderByRaw(
63+
$this->orderByRaw(
5964
sprintf(
6065
'ST_DISTANCE(%s, %s) %s',
6166
"`{$column}`",
6267
$this->toExpression($geometryOrColumn),
6368
$direction,
6469
)
6570
);
71+
72+
return $this;
6673
}
6774

6875
public function withDistanceSphere(
@@ -74,14 +81,16 @@ public function withDistanceSphere(
7481
$this->select('*');
7582
}
7683

77-
return $this->selectRaw(
84+
$this->selectRaw(
7885
sprintf(
7986
'ST_DISTANCE_SPHERE(%s, %s) AS %s',
8087
"`{$column}`",
8188
$this->toExpression($geometryOrColumn),
8289
$alias,
8390
)
8491
);
92+
93+
return $this;
8594
}
8695

8796
public function whereDistanceSphere(
@@ -90,7 +99,7 @@ public function whereDistanceSphere(
9099
string $operator,
91100
int|float $value
92101
): self {
93-
return $this->whereRaw(
102+
$this->whereRaw(
94103
sprintf(
95104
'ST_DISTANCE_SPHERE(%s, %s) %s %s',
96105
"`{$column}`",
@@ -99,109 +108,129 @@ public function whereDistanceSphere(
99108
$value
100109
)
101110
);
111+
112+
return $this;
102113
}
103114

104115
public function orderByDistanceSphere(
105116
string $column,
106117
Geometry|string $geometryOrColumn,
107118
string $direction = 'asc'
108119
): self {
109-
return $this->orderByRaw(
120+
$this->orderByRaw(
110121
sprintf(
111122
'ST_DISTANCE_SPHERE(%s, %s) %s',
112123
"`{$column}`",
113124
$this->toExpression($geometryOrColumn),
114125
$direction
115126
)
116127
);
128+
129+
return $this;
117130
}
118131

119132
public function whereWithin(string $column, Geometry|string $geometryOrColumn): self
120133
{
121-
return $this->whereRaw(
134+
$this->whereRaw(
122135
sprintf(
123136
'ST_WITHIN(%s, %s)',
124137
"`{$column}`",
125138
$this->toExpression($geometryOrColumn),
126139
)
127140
);
141+
142+
return $this;
128143
}
129144

130145
public function whereContains(string $column, Geometry|string $geometryOrColumn): self
131146
{
132-
return $this->whereRaw(
147+
$this->whereRaw(
133148
sprintf(
134149
'ST_CONTAINS(%s, %s)',
135150
"`{$column}`",
136151
$this->toExpression($geometryOrColumn),
137152
)
138153
);
154+
155+
return $this;
139156
}
140157

141158
public function whereTouches(string $column, Geometry|string $geometryOrColumn): self
142159
{
143-
return $this->whereRaw(
160+
$this->whereRaw(
144161
sprintf(
145162
'ST_TOUCHES(%s, %s)',
146163
"`{$column}`",
147164
$this->toExpression($geometryOrColumn),
148165
)
149166
);
167+
168+
return $this;
150169
}
151170

152171
public function whereIntersects(string $column, Geometry|string $geometryOrColumn): self
153172
{
154-
return $this->whereRaw(
173+
$this->whereRaw(
155174
sprintf(
156175
'ST_INTERSECTS(%s, %s)',
157176
"`{$column}`",
158177
$this->toExpression($geometryOrColumn),
159178
)
160179
);
180+
181+
return $this;
161182
}
162183

163184
public function whereCrosses(string $column, Geometry|string $geometryOrColumn): self
164185
{
165-
return $this->whereRaw(
186+
$this->whereRaw(
166187
sprintf(
167188
'ST_CROSSES(%s, %s)',
168189
"`{$column}`",
169190
$this->toExpression($geometryOrColumn),
170191
)
171192
);
193+
194+
return $this;
172195
}
173196

174197
public function whereDisjoint(string $column, Geometry|string $geometryOrColumn): self
175198
{
176-
return $this->whereRaw(
199+
$this->whereRaw(
177200
sprintf(
178201
'ST_DISJOINT(%s, %s)',
179202
"`{$column}`",
180203
$this->toExpression($geometryOrColumn),
181204
)
182205
);
206+
207+
return $this;
183208
}
184209

185210
public function whereOverlaps(string $column, Geometry|string $geometryOrColumn): self
186211
{
187-
return $this->whereRaw(
212+
$this->whereRaw(
188213
sprintf(
189214
'ST_OVERLAPS(%s, %s)',
190215
"`{$column}`",
191216
$this->toExpression($geometryOrColumn),
192217
)
193218
);
219+
220+
return $this;
194221
}
195222

196223
public function whereEquals(string $column, Geometry|string $geometryOrColumn): self
197224
{
198-
return $this->whereRaw(
225+
$this->whereRaw(
199226
sprintf(
200227
'ST_EQUALS(%s, %s)',
201228
"`{$column}`",
202229
$this->toExpression($geometryOrColumn),
203230
)
204231
);
232+
233+
return $this;
205234
}
206235

207236
protected function toExpression(Geometry|string $geometryOrColumn): Expression

0 commit comments

Comments
 (0)