Skip to content

Commit 55119fb

Browse files
MatanYadaevMatan Yadaev
andauthored
Refactor tests (#45)
* Refactor MultiPointTest * Refactor LineStringTest * Refactor GeometryCollectionTest * Make GeometryCollection not generic * Refactor PolygonTest * Refactor MultiLineStringTest * Refactor MultiPolygonTest * Refactor GeometryCastTest Co-authored-by: Matan Yadaev <[email protected]>
1 parent de5e04c commit 55119fb

15 files changed

+609
-873
lines changed

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ parameters:
66
- tests
77
level: max
88
ignoreErrors:
9-
-
10-
message: '#^Undefined variable\: \$this$#'
11-
path: tests/*.php
129
-
1310
message: '#^Call to an undefined method Pest\\Expectation\|Pest\\Support\\Extendable\:\:.+\(\)\.$#'
1411
path: tests/*.php

src/Objects/Geometry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function toArray(): array
123123
public function toFeatureCollectionJson(): string
124124
{
125125
if (static::class === GeometryCollection::class) {
126-
/** @var GeometryCollection<Geometry> $this */
126+
/** @var GeometryCollection $this */
127127
$geometries = $this->geometries;
128128
} else {
129129
$geometries = collect([$this]);

src/Objects/GeometryCollection.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@
99
use Illuminate\Support\Str;
1010
use InvalidArgumentException;
1111

12-
/**
13-
* @template TGeometry of Geometry
14-
*
15-
* @implements ArrayAccess<int, TGeometry>
16-
*/
1712
class GeometryCollection extends Geometry implements ArrayAccess
1813
{
19-
/** @var Collection<int, TGeometry> */
14+
/** @var Collection<int, Geometry> */
2015
protected Collection $geometries;
2116

22-
/** @var class-string<TGeometry> */
2317
protected string $collectionOf = Geometry::class;
2418

2519
protected int $minimumGeometries = 0;
2620

2721
/**
28-
* @param Collection<int, TGeometry>|array<int, TGeometry> $geometries
22+
* @param Collection<int, Geometry>|array<int, Geometry> $geometries
2923
*
3024
* @throws InvalidArgumentException
3125
*/
@@ -41,12 +35,6 @@ public function __construct(Collection|array $geometries)
4135
$this->validateGeometriesCount();
4236
}
4337

44-
/**
45-
* @param bool $withFunction
46-
* @return string
47-
*
48-
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter
49-
*/
5038
public function toWkt(bool $withFunction = true): string
5139
{
5240
$wkt = $this->toCollectionWkt(withFunction: true);
@@ -84,7 +72,7 @@ public function toArray(): array
8472
}
8573

8674
/**
87-
* @return Collection<int, TGeometry>
75+
* @return Collection<int, Geometry>
8876
*/
8977
public function getGeometries(): Collection
9078
{
@@ -102,20 +90,21 @@ public function offsetExists($offset): bool
10290

10391
/**
10492
* @param int $offset
105-
* @return TGeometry|null
93+
* @return Geometry
10694
*/
107-
public function offsetGet($offset): ?Geometry
95+
public function offsetGet($offset): Geometry
10896
{
97+
// @phpstan-ignore-next-line
10998
return $this->geometries[$offset];
11099
}
111100

112101
/**
113102
* @param int $offset
114-
* @param TGeometry $geometry
103+
* @param Geometry $value
115104
*/
116-
public function offsetSet($offset, $geometry): void
105+
public function offsetSet($offset, $value): void
117106
{
118-
$this->geometries[$offset] = $geometry;
107+
$this->geometries[$offset] = $value;
119108
$this->validateGeometriesType();
120109
}
121110

src/Objects/MultiLineString.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
namespace MatanYadaev\EloquentSpatial\Objects;
66

7+
use Illuminate\Support\Collection;
8+
use InvalidArgumentException;
9+
710
/**
8-
* @method array<LineString> getGeometries()
9-
* @method LineString offsetGet(mixed $offset)
11+
* @property Collection<int, LineString> $geometries
1012
*
11-
* @extends GeometryCollection<LineString>
13+
* @method Collection<int, LineString> getGeometries()
14+
* @method LineString offsetGet(int $offset)
15+
* @method void offsetSet(int $offset, LineString $value)
1216
*/
1317
class MultiLineString extends GeometryCollection
1418
{
@@ -17,11 +21,16 @@ class MultiLineString extends GeometryCollection
1721
protected int $minimumGeometries = 1;
1822

1923
/**
20-
* @param bool $withFunction
21-
* @return string
24+
* @param Collection<int, LineString>|array<int, LineString> $geometries
2225
*
23-
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter
26+
* @throws InvalidArgumentException
2427
*/
28+
public function __construct(Collection|array $geometries)
29+
{
30+
// @phpstan-ignore-next-line
31+
parent::__construct($geometries);
32+
}
33+
2534
public function toWkt(bool $withFunction = true): string
2635
{
2736
$wkt = $this->toCollectionWkt(withFunction: false);

src/Objects/MultiPoint.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ class MultiPoint extends PointCollection
88
{
99
protected int $minimumGeometries = 1;
1010

11-
/**
12-
* @param bool $withFunction
13-
* @return string
14-
*
15-
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter
16-
*/
1711
public function toWkt(bool $withFunction = true): string
1812
{
1913
$wkt = $this->toCollectionWkt(withFunction: false);

src/Objects/MultiPolygon.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
namespace MatanYadaev\EloquentSpatial\Objects;
66

7+
use Illuminate\Support\Collection;
8+
use InvalidArgumentException;
9+
710
/**
8-
* @method array<Polygon> getGeometries()
9-
* @method Polygon offsetGet(mixed $offset)
11+
* @property Collection<int, Polygon> $geometries
1012
*
11-
* @extends GeometryCollection<Polygon>
13+
* @method Collection<int, Polygon> getGeometries()
14+
* @method Polygon offsetGet(int $offset)
15+
* @method void offsetSet(int $offset, Polygon $value)
1216
*/
1317
class MultiPolygon extends GeometryCollection
1418
{
@@ -17,11 +21,16 @@ class MultiPolygon extends GeometryCollection
1721
protected int $minimumGeometries = 1;
1822

1923
/**
20-
* @param bool $withFunction
21-
* @return string
24+
* @param Collection<int, Polygon>|array<int, Polygon> $geometries
2225
*
23-
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter
26+
* @throws InvalidArgumentException
2427
*/
28+
public function __construct(Collection|array $geometries)
29+
{
30+
// @phpstan-ignore-next-line
31+
parent::__construct($geometries);
32+
}
33+
2534
public function toWkt(bool $withFunction = true): string
2635
{
2736
$wkt = $this->toCollectionWkt(withFunction: false);

src/Objects/PointCollection.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@
44

55
namespace MatanYadaev\EloquentSpatial\Objects;
66

7+
use Illuminate\Support\Collection;
8+
use InvalidArgumentException;
9+
710
/**
8-
* @method array<Point> getGeometries()
9-
* @method Point offsetGet(mixed $offset)
11+
* @property Collection<int, Point> $geometries
1012
*
11-
* @extends GeometryCollection<Point>
13+
* @method Collection<int, Point> getGeometries()
14+
* @method Point offsetGet(int $offset)
15+
* @method void offsetSet(int $offset, Point $value)
1216
*/
1317
abstract class PointCollection extends GeometryCollection
1418
{
1519
protected string $collectionOf = Point::class;
20+
21+
/**
22+
* @param Collection<int, Point>|array<int, Point> $geometries
23+
*
24+
* @throws InvalidArgumentException
25+
*/
26+
public function __construct(Collection|array $geometries)
27+
{
28+
// @phpstan-ignore-next-line
29+
parent::__construct($geometries);
30+
}
1631
}

0 commit comments

Comments
 (0)