Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 80e63eb

Browse filesBrowse files
committed
upgrade code using rector
1 parent d61e67f commit 80e63eb
Copy full SHA for 80e63eb
Expand file treeCollapse file tree

23 files changed

+96
-79
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"test": "vendor/bin/phpunit",
99
"test-coverage": "vendor/bin/phpunit --coverage",
1010
"format": "vendor/bin/pint",
11-
"post-update-cmd": "@composer bump -D"
11+
"post-update-cmd": "@composer bump -D",
12+
"rector": "./vendor/bin/rector process"
1213
},
1314
"type": "library",
1415
"license": "MIT",
@@ -34,17 +35,19 @@
3435
},
3536
"conflict": {},
3637
"require-dev": {
37-
"laravel/pint": "^1.10.3",
38-
"laravel/laravel": "^10.2.4",
38+
"driftingly/rector-laravel": "^0.21.0",
3939
"laravel/browser-kit-testing": "^7.0",
40+
"laravel/laravel": "^10.2.4",
41+
"laravel/pint": "^1.10.3",
4042
"mockery/mockery": "^1.6.2",
4143
"nunomaduro/collision": "^7.7.0",
4244
"nunomaduro/larastan": "^2.6.3",
4345
"orchestra/testbench": "^8.5.9",
4446
"phpstan/extension-installer": "^1.3.1",
4547
"phpstan/phpstan-deprecation-rules": "^1.1.3",
4648
"phpstan/phpstan-phpunit": "^1.3.13",
47-
"phpunit/phpunit": "^10.2.3"
49+
"phpunit/phpunit": "^10.2.3",
50+
"rector/rector": "^0.17.2"
4851
},
4952
"autoload": {
5053
"psr-4": {

‎rector.php

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\LevelSetList;
7+
use Rector\Set\ValueObject\SetList;
8+
use RectorLaravel\Set\LaravelSetList;
9+
10+
return static function (RectorConfig $rectorConfig): void {
11+
$rectorConfig->paths([
12+
__DIR__.'/src',
13+
]);
14+
15+
$rectorConfig->sets([
16+
LevelSetList::UP_TO_PHP_81,
17+
LaravelSetList::LARAVEL_100,
18+
SetList::CODE_QUALITY,
19+
]);
20+
};

‎src/Doctrine/Geometry.php

Copy file name to clipboardExpand all lines: src/Doctrine/Geometry.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Geometry extends Type
99
{
10-
const GEOMETRY = 'geometry';
10+
final public const GEOMETRY = 'geometry';
1111

1212
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
1313
{

‎src/Doctrine/GeometryCollection.php

Copy file name to clipboardExpand all lines: src/Doctrine/GeometryCollection.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class GeometryCollection extends Type
99
{
10-
const GEOMETRYCOLLECTION = 'geometrycollection';
10+
final public const GEOMETRYCOLLECTION = 'geometrycollection';
1111

1212
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
1313
{

‎src/Doctrine/LineString.php

Copy file name to clipboardExpand all lines: src/Doctrine/LineString.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class LineString extends Type
99
{
10-
const LINESTRING = 'linestring';
10+
final public const LINESTRING = 'linestring';
1111

1212
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
1313
{

‎src/Doctrine/MultiLineString.php

Copy file name to clipboardExpand all lines: src/Doctrine/MultiLineString.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class MultiLineString extends Type
99
{
10-
const MULTILINESTRING = 'multilinestring';
10+
final public const MULTILINESTRING = 'multilinestring';
1111

1212
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
1313
{

‎src/Doctrine/MultiPoint.php

Copy file name to clipboardExpand all lines: src/Doctrine/MultiPoint.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class MultiPoint extends Type
99
{
10-
const MULTIPOINT = 'multipoint';
10+
final public const MULTIPOINT = 'multipoint';
1111

1212
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
1313
{

‎src/Doctrine/MultiPolygon.php

Copy file name to clipboardExpand all lines: src/Doctrine/MultiPolygon.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class MultiPolygon extends Type
99
{
10-
const MULTIPOLYGON = 'multipolygon';
10+
final public const MULTIPOLYGON = 'multipolygon';
1111

1212
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
1313
{

‎src/Doctrine/Point.php

Copy file name to clipboardExpand all lines: src/Doctrine/Point.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Point extends Type
99
{
10-
const POINT = 'point';
10+
final public const POINT = 'point';
1111

1212
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
1313
{

‎src/Doctrine/Polygon.php

Copy file name to clipboardExpand all lines: src/Doctrine/Polygon.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Polygon extends Type
99
{
10-
const POLYGON = 'polygon';
10+
final public const POLYGON = 'polygon';
1111

1212
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
1313
{

‎src/Eloquent/SpatialExpression.php

Copy file name to clipboardExpand all lines: src/Eloquent/SpatialExpression.php
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99

1010
class SpatialExpression extends Expression
1111
{
12-
/**
13-
* @var Geometry|GeometryInterface
14-
*/
15-
protected $value;
16-
1712
/**
1813
* @param Geometry|GeometryInterface $value
1914
* @return void
2015
*/
21-
public function __construct($value)
16+
public function __construct(protected $value)
2217
{
23-
$this->value = $value;
2418
}
2519

2620
public function getValue(Grammar $grammar)

‎src/Eloquent/SpatialTrait.php

Copy file name to clipboardExpand all lines: src/Eloquent/SpatialTrait.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ public function getSpatialFields()
116116
if (property_exists($this, 'spatialFields')) {
117117
return $this->spatialFields;
118118
} else {
119-
throw new SpatialFieldsNotDefinedException(__CLASS__.' has to define $spatialFields');
119+
throw new SpatialFieldsNotDefinedException(self::class.' has to define $spatialFields');
120120
}
121121
}
122122

123-
public function isColumnAllowed($geometryColumn)
123+
public function isColumnAllowed($geometryColumn): bool
124124
{
125125
if (! in_array($geometryColumn, $this->getSpatialFields())) {
126126
throw new SpatialFieldsNotDefinedException();

‎src/Exceptions/InvalidGeoJsonException.php

Copy file name to clipboardExpand all lines: src/Exceptions/InvalidGeoJsonException.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@
44

55
class InvalidGeoJsonException extends \RuntimeException
66
{
7+
/**
8+
* @param class-string $expected
9+
* @param class-string $actual
10+
*/
11+
public function __construct(string $expected, string $actual)
12+
{
13+
parent::__construct(
14+
sprintf('Expected %s, got %s', $expected, $actual)
15+
);
16+
}
717
}

‎src/Schema/Blueprint.php

Copy file name to clipboardExpand all lines: src/Schema/Blueprint.php
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Blueprint extends IlluminateBlueprint
1111
*/
1212
public function geometry($column, ?int $srid = null): \Illuminate\Support\Fluent
1313
{
14-
return $this->addColumn('geometry', $column, compact('srid'));
14+
return $this->addColumn('geometry', $column, ['srid' => $srid]);
1515
}
1616

1717
/**
@@ -21,55 +21,55 @@ public function geometry($column, ?int $srid = null): \Illuminate\Support\Fluent
2121
*/
2222
public function point($column, $srid = null): \Illuminate\Support\Fluent
2323
{
24-
return $this->addColumn('point', $column, compact('srid'));
24+
return $this->addColumn('point', $column, ['srid' => $srid]);
2525
}
2626

2727
/**
2828
* Add a linestring column on the table.
2929
*/
3030
public function lineString($column, ?int $srid = null): \Illuminate\Support\Fluent
3131
{
32-
return $this->addColumn('linestring', $column, compact('srid'));
32+
return $this->addColumn('linestring', $column, ['srid' => $srid]);
3333
}
3434

3535
/**
3636
* Add a polygon column on the table.
3737
*/
3838
public function polygon($column, ?int $srid = null): \Illuminate\Support\Fluent
3939
{
40-
return $this->addColumn('polygon', $column, compact('srid'));
40+
return $this->addColumn('polygon', $column, ['srid' => $srid]);
4141
}
4242

4343
/**
4444
* Add a multipoint column on the table.
4545
*/
4646
public function multiPoint($column, ?int $srid = null): \Illuminate\Support\Fluent
4747
{
48-
return $this->addColumn('multipoint', $column, compact('srid'));
48+
return $this->addColumn('multipoint', $column, ['srid' => $srid]);
4949
}
5050

5151
/**
5252
* Add a multilinestring column on the table.
5353
*/
5454
public function multiLineString($column, ?int $srid = null): \Illuminate\Support\Fluent
5555
{
56-
return $this->addColumn('multilinestring', $column, compact('srid'));
56+
return $this->addColumn('multilinestring', $column, ['srid' => $srid]);
5757
}
5858

5959
/**
6060
* Add a multipolygon column on the table.
6161
*/
6262
public function multiPolygon($column, ?int $srid = null): \Illuminate\Support\Fluent
6363
{
64-
return $this->addColumn('multipolygon', $column, compact('srid'));
64+
return $this->addColumn('multipolygon', $column, ['srid' => $srid]);
6565
}
6666

6767
/**
6868
* Add a geometrycollection column on the table.
6969
*/
7070
public function geometryCollection($column, ?int $srid = null): \Illuminate\Support\Fluent
7171
{
72-
return $this->addColumn('geometrycollection', $column, compact('srid'));
72+
return $this->addColumn('geometrycollection', $column, ['srid' => $srid]);
7373
}
7474

7575
/**

‎src/Schema/Grammars/MySqlGrammar.php

Copy file name to clipboardExpand all lines: src/Schema/Grammars/MySqlGrammar.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class MySqlGrammar extends IlluminateMySqlGrammar
1010
{
11-
const COLUMN_MODIFIER_SRID = 'Srid';
11+
final public const COLUMN_MODIFIER_SRID = 'Srid';
1212

1313
public function __construct()
1414
{

‎src/Types/Geometry.php

Copy file name to clipboardExpand all lines: src/Types/Geometry.php
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ abstract class Geometry implements GeometryInterface, Jsonable, \JsonSerializabl
2121
7 => GeometryCollection::class,
2222
];
2323

24-
protected int $srid;
25-
26-
public function __construct(int $srid = 0)
24+
public function __construct(protected int $srid = 0)
2725
{
28-
$this->srid = $srid;
2926
}
3027

3128
public function getSrid(): int
@@ -103,7 +100,7 @@ public static function fromWKT(string $wkt, int $srid = 0): static
103100
public static function fromJson(string|GeoJson $geoJson): self
104101
{
105102
if (is_string($geoJson)) {
106-
$geoJson = GeoJson::jsonUnserialize(json_decode($geoJson));
103+
$geoJson = GeoJson::jsonUnserialize(json_decode($geoJson, flags: JSON_THROW_ON_ERROR));
107104
}
108105

109106
if ($geoJson->getType() === 'FeatureCollection') {

‎src/Types/GeometryCollection.php

Copy file name to clipboardExpand all lines: src/Types/GeometryCollection.php
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @implements GeometryInterface<FeatureCollection>
1919
*/
20-
class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAccess, Arrayable, Countable, GeometryInterface
20+
class GeometryCollection extends Geometry implements IteratorAggregate, ArrayAccess, Arrayable, Countable, GeometryInterface, \Stringable
2121
{
2222
/**
2323
* The minimum number of items required to create this collection.
@@ -63,14 +63,14 @@ public function toWKT(): string
6363
return sprintf('GEOMETRYCOLLECTION(%s)', (string) $this);
6464
}
6565

66-
public function __toString()
66+
public function __toString(): string
6767
{
6868
return implode(',', array_map(fn (GeometryInterface $geometry) => $geometry->toWKT(), $this->items));
6969
}
7070

7171
public static function fromString(string $wktArgument, int $srid = 0): static
7272
{
73-
if (empty($wktArgument)) {
73+
if ($wktArgument === '') {
7474
return new static([]);
7575
}
7676

@@ -127,11 +127,11 @@ public function count(): int
127127
public static function fromJson(string|GeoJson $geoJson): self
128128
{
129129
if (is_string($geoJson)) {
130-
$geoJson = GeoJson::jsonUnserialize(json_decode($geoJson));
130+
$geoJson = GeoJson::jsonUnserialize(json_decode($geoJson, flags: JSON_THROW_ON_ERROR));
131131
}
132132

133-
if (! is_a($geoJson, FeatureCollection::class)) {
134-
throw new InvalidGeoJsonException('Expected '.FeatureCollection::class.', got '.get_class($geoJson));
133+
if (! $geoJson instanceof FeatureCollection) {
134+
throw new InvalidGeoJsonException(FeatureCollection::class, $geoJson::class);
135135
}
136136

137137
$set = [];
@@ -184,7 +184,7 @@ protected function validateItemCount(array $items): void
184184

185185
throw new InvalidArgumentException(sprintf(
186186
'%s must contain at least %d %s',
187-
get_class($this),
187+
static::class,
188188
$this->minimumCollectionItems,
189189
$entries
190190
));
@@ -202,7 +202,7 @@ protected function validateItemType(mixed $item): void
202202
if (! $item instanceof $this->collectionItemType) {
203203
throw new InvalidArgumentException(sprintf(
204204
'%s must be a collection of %s',
205-
get_class($this),
205+
static::class,
206206
$this->collectionItemType
207207
));
208208
}

‎src/Types/LineString.php

Copy file name to clipboardExpand all lines: src/Types/LineString.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use GeoJson\Geometry\LineString as GeoJsonLineString;
77
use Limenet\LaravelMysqlSpatial\Exceptions\InvalidGeoJsonException;
88

9-
class LineString extends PointCollection
9+
class LineString extends PointCollection implements \Stringable
1010
{
1111
/**
1212
* The minimum number of items required to create this collection.
@@ -33,19 +33,19 @@ public static function fromString(string $wktArgument, int $srid = 0): static
3333
return new static($points, $srid);
3434
}
3535

36-
public function __toString()
36+
public function __toString(): string
3737
{
3838
return $this->toPairList();
3939
}
4040

4141
public static function fromJson(string|GeoJson $geoJson): self
4242
{
4343
if (is_string($geoJson)) {
44-
$geoJson = GeoJson::jsonUnserialize(json_decode($geoJson));
44+
$geoJson = GeoJson::jsonUnserialize(json_decode($geoJson, null, 512, JSON_THROW_ON_ERROR));
4545
}
4646

47-
if (! is_a($geoJson, GeoJsonLineString::class)) {
48-
throw new InvalidGeoJsonException('Expected '.GeoJsonLineString::class.', got '.get_class($geoJson));
47+
if (! $geoJson instanceof GeoJsonLineString) {
48+
throw new InvalidGeoJsonException(GeoJsonLineString::class, $geoJson::class);
4949
}
5050

5151
$set = [];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.