Skip to content

Commit 53e9971

Browse files
committed
auto fix
1 parent db0bef3 commit 53e9971

15 files changed

+104
-56
lines changed

phpinsights.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
declare(strict_types=1);
44

5+
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
6+
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff;
7+
58
return [
69

710
/*
@@ -61,7 +64,8 @@
6164
],
6265

6366
'remove' => [
64-
// ExampleInsight::class,
67+
ParameterTypeHintSniff::class,
68+
ReturnTypeHintSniff::class,
6569
],
6670

6771
'config' => [

src/Builders/SpatialBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial\Builders;
46

57
use Illuminate\Database\Eloquent\Builder;

src/Exceptions/InvalidTypeException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial\Exceptions;
46

57
use Exception;

src/Exceptions/UnsupportedDatabaseDriverException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial\Exceptions;
46

57
use Exception;

src/Factory.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial;
46

57
use Collection as geoPHPGeometryCollection;
@@ -39,7 +41,7 @@ public static function parse(string $value): Geometry
3941
protected static function create(geoPHPGeometry $geometry): Geometry
4042
{
4143
if ($geometry instanceof geoPHPGeometryCollection) {
42-
$components = collect($geometry->components)->map(function (geoPHPGeometry $geometryComponent): Geometry {
44+
$components = collect($geometry->components)->map(static function (geoPHPGeometry $geometryComponent): Geometry {
4345
return self::create($geometryComponent);
4446
});
4547

@@ -75,6 +77,7 @@ protected static function createPoint(float $latitude, float $longitude): Point
7577

7678
/**
7779
* @param Collection<Point> $points
80+
*
7881
* @return MultiPoint
7982
*/
8083
protected static function createMultiPoint(Collection $points): MultiPoint
@@ -84,6 +87,7 @@ protected static function createMultiPoint(Collection $points): MultiPoint
8487

8588
/**
8689
* @param Collection<Point> $points
90+
*
8791
* @return LineString
8892
*/
8993
protected static function createLineString(Collection $points): LineString
@@ -93,6 +97,7 @@ protected static function createLineString(Collection $points): LineString
9397

9498
/**
9599
* @param Collection<LineString> $lineStrings
100+
*
96101
* @return Polygon
97102
*/
98103
protected static function createPolygon(Collection $lineStrings): Polygon
@@ -102,15 +107,17 @@ protected static function createPolygon(Collection $lineStrings): Polygon
102107

103108
/**
104109
* @param Collection<LineString> $lineStrings
110+
*
105111
* @return MultiLineString
106112
*/
107-
protected static function createMultiLineString(Collection $lineStrings):MultiLineString
113+
protected static function createMultiLineString(Collection $lineStrings): MultiLineString
108114
{
109115
return new MultiLineString($lineStrings);
110116
}
111117

112118
/**
113119
* @param Collection<Polygon> $polygons
120+
*
114121
* @return MultiPolygon
115122
*/
116123
protected static function createMultiPolygon(Collection $polygons): MultiPolygon
@@ -120,6 +127,7 @@ protected static function createMultiPolygon(Collection $polygons): MultiPolygon
120127

121128
/**
122129
* @param Collection<Geometry> $geometries
130+
*
123131
* @return GeometryCollection
124132
*/
125133
protected static function createGeometryCollection(Collection $geometries): GeometryCollection

src/Objects/Geometry.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial\Objects;
46

57
use Illuminate\Contracts\Database\Eloquent\Castable;
@@ -18,7 +20,9 @@ abstract public function toWkt(): Expression;
1820

1921
/**
2022
* @param string $wkt
23+
*
2124
* @return static
25+
*
2226
* @throws InvalidTypeException
2327
*/
2428
public static function fromWkt(string $wkt): static
@@ -40,7 +44,9 @@ public function toJson($options = 0): string
4044

4145
/**
4246
* @param string $geoJson
47+
*
4348
* @return static
49+
*
4450
* @throws InvalidTypeException
4551
*/
4652
public static function fromJson(string $geoJson): static
@@ -55,15 +61,15 @@ public static function fromJson(string $geoJson): static
5561
}
5662

5763
/**
58-
* @return mixed[]
64+
* @return array<mixed>
5965
*/
6066
public function jsonSerialize(): array
6167
{
6268
return $this->toArray();
6369
}
6470

6571
/**
66-
* @return array{type: string, coordinates: mixed[]}
72+
* @return array{type: string, coordinates: array<mixed>}
6773
*/
6874
public function toArray(): array
6975
{
@@ -74,12 +80,13 @@ public function toArray(): array
7480
}
7581

7682
/**
77-
* @return mixed[]
83+
* @return array<mixed>
7884
*/
7985
abstract public function getCoordinates(): array;
8086

8187
/**
82-
* @param string[] $arguments
88+
* @param array<string> $arguments
89+
*
8390
* @return CastsAttributes
8491
*/
8592
public static function castUsing(array $arguments): CastsAttributes
@@ -99,6 +106,7 @@ public function __construct(string $className)
99106
* @param string $key
100107
* @param string|null $wkt
101108
* @param array<string, mixed> $attributes
109+
*
102110
* @return Geometry|null
103111
*/
104112
public function get($model, string $key, $wkt, array $attributes): ?Geometry
@@ -107,14 +115,15 @@ public function get($model, string $key, $wkt, array $attributes): ?Geometry
107115
return null;
108116
}
109117

110-
return ($this->className)::fromWkt($wkt);
118+
return $this->className::fromWkt($wkt);
111119
}
112120

113121
/**
114122
* @param Model $model
115123
* @param string $key
116124
* @param Geometry|null $geometry
117125
* @param array<string, mixed> $attributes
126+
*
118127
* @return Expression|string|null
119128
*/
120129
public function set($model, string $key, $geometry, array $attributes): Expression | string | null

src/Objects/GeometryCollection.php

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial\Objects;
46

57
use 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
}

src/Objects/LineString.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial\Objects;
46

57
use Illuminate\Database\Query\Expression;

src/Objects/MultiLineString.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial\Objects;
46

57
use Illuminate\Database\Query\Expression;
68
use Illuminate\Support\Collection;
79
use Illuminate\Support\Facades\DB;
810

911
/**
10-
* @method LineString[] getGeometries()
12+
* @method array<LineString> getGeometries()
1113
*/
1214
class MultiLineString extends GeometryCollection
1315
{
@@ -19,7 +21,7 @@ class MultiLineString extends GeometryCollection
1921
protected int $minimumGeometries = 1;
2022

2123
/**
22-
* @param Collection<LineString>|LineString[] $geometries
24+
* @param Collection<LineString>|array<LineString> $geometries
2325
*/
2426
public function __construct(Collection | array $geometries)
2527
{

src/Objects/MultiPoint.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MatanYadaev\EloquentSpatial\Objects;
46

57
use Illuminate\Database\Query\Expression;

0 commit comments

Comments
 (0)