Skip to content

Commit 30a14b4

Browse files
committed
wip
1 parent 53e9971 commit 30a14b4

File tree

7 files changed

+59
-33
lines changed

7 files changed

+59
-33
lines changed

.php_cs.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
return (new MattAllan\LaravelCodeStyle\Config())
44
->setFinder(
55
PhpCsFixer\Finder::create()
6-
->in('src')
7-
->in('tests')
6+
->in('**.php')
87
)
98
->setRules([
109
'@Laravel' => true,

composer.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,20 @@
3333
"psr-4": {
3434
"MatanYadaev\\EloquentSpatial\\": "src",
3535
"MatanYadaev\\EloquentSpatial\\Database\\Factories\\": "database/factories"
36-
},
37-
"files": [
38-
"src/helpers.php"
39-
]
36+
}
4037
},
4138
"autoload-dev": {
4239
"psr-4": {
4340
"MatanYadaev\\EloquentSpatial\\Tests\\": "tests"
4441
}
4542
},
4643
"scripts": {
47-
"style-fix": "./vendor/bin/php-cs-fixer fix --allow-risky=yes",
44+
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --allow-risky=yes",
4845
"phpstan": "./vendor/bin/phpstan analyse --memory-limit=2G",
4946
"phpunit": "./vendor/bin/phpunit --colors=always",
5047
"phpunit-coverage": "./vendor/bin/phpunit --coverage-html coverage",
51-
"phpinsights": "./vendor/bin/phpinsights"
48+
"phpinsights": "./vendor/bin/phpinsights",
49+
"phpinsights-fix": "./vendor/bin/phpinsights fix"
5250
},
5351
"config": {
5452
"sort-packages": true

phpinsights.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
declare(strict_types=1);
44

5+
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses;
6+
use ObjectCalisthenics\Sniffs\Metrics\MaxNestingLevelSniff;
7+
use ObjectCalisthenics\Sniffs\Metrics\MethodPerClassLimitSniff;
8+
use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UselessOverridingMethodSniff;
9+
use SlevomatCodingStandard\Sniffs\Classes\SuperfluousExceptionNamingSniff;
10+
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
11+
use SlevomatCodingStandard\Sniffs\Functions\UnusedParameterSniff;
12+
use SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff;
513
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
614
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff;
715

@@ -66,12 +74,34 @@
6674
'remove' => [
6775
ParameterTypeHintSniff::class,
6876
ReturnTypeHintSniff::class,
77+
UselessOverridingMethodSniff::class,
78+
DisallowMixedTypeHintSniff::class,
79+
ForbiddenNormalClasses::class,
80+
SuperfluousExceptionNamingSniff::class,
6981
],
7082

7183
'config' => [
72-
// ExampleInsight::class => [
73-
// 'key' => 'value',
74-
// ],
84+
MaxNestingLevelSniff::class => [
85+
'exclude' => [
86+
'src/Objects/Geometry.php',
87+
]
88+
],
89+
UnusedParameterSniff::class => [
90+
'exclude' => [
91+
'src/Objects/Geometry.php',
92+
]
93+
],
94+
MethodPerClassLimitSniff::class => [
95+
'exclude' => [
96+
'src/Builders/SpatialBuilder.php',
97+
'src/Objects/Geometry.php',
98+
]
99+
],
100+
LineLengthSniff::class => [
101+
'lineLimit' => 110,
102+
'absoluteLineLimit' => 150,
103+
'ignoreComments' => false,
104+
]
75105
],
76106

77107
/*

src/Builders/SpatialBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ public function whereDistanceSphere(string $column, Geometry | string $geometryO
5959
return $this->whereRaw("ST_DISTANCE_SPHERE(`{$column}`, {$geometryOrColumn}) {$operator} {$distance}");
6060
}
6161

62-
public function orderByDistanceSphere(string $column, Geometry | string $geometryOrColumn, string $direction = 'asc'): self
63-
{
62+
public function orderByDistanceSphere(
63+
string $column,
64+
Geometry | string $geometryOrColumn,
65+
string $direction = 'asc'
66+
): self {
6467
$geometryOrColumn = $this->toExpression($geometryOrColumn);
6568

6669
return $this->orderByRaw("ST_DISTANCE_SPHERE(`{$column}`, {$geometryOrColumn}) {$direction}");

src/Factory.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class Factory
2727
{
2828
public static function parse(string $value): Geometry
2929
{
30-
if (! is_json($value)) {
30+
$isJson = (bool) is_object(json_decode($value));
31+
32+
if (! $isJson) {
3133
// MySQL adds 4 NULL bytes at the start of the WKB
3234
$value = substr($value, 4);
3335
}
@@ -41,11 +43,12 @@ public static function parse(string $value): Geometry
4143
protected static function create(geoPHPGeometry $geometry): Geometry
4244
{
4345
if ($geometry instanceof geoPHPGeometryCollection) {
44-
$components = collect($geometry->components)->map(static function (geoPHPGeometry $geometryComponent): Geometry {
45-
return self::create($geometryComponent);
46-
});
46+
$components = collect($geometry->components)
47+
->map(static function (geoPHPGeometry $geometryComponent): Geometry {
48+
return self::create($geometryComponent);
49+
});
4750

48-
$className = get_class($geometry);
51+
$className = $geometry::class;
4952

5053
if ($className === geoPHPMultiPoint::class) {
5154
return self::createMultiPoint($components);

src/Objects/GeometryCollection.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ protected function validateGeometriesCount(): void
8787
if ($geometriesCount < $this->minimumGeometries) {
8888
$className = self::class;
8989

90-
throw new InvalidArgumentException("{$className} must contain at least {$this->minimumGeometries} ".Str::plural('entries', $geometriesCount));
90+
throw new InvalidArgumentException(
91+
"{$className} must contain at least {$this->minimumGeometries} "
92+
.Str::plural('entries', $geometriesCount)
93+
);
9194
}
9295
}
9396

@@ -100,7 +103,9 @@ protected function validateGeometriesType(): void
100103
if (! ($geometry instanceof $this->collectionOf)) {
101104
$className = self::class;
102105

103-
throw new InvalidArgumentException("{$className} must be a collection of {$this->collectionOf}");
106+
throw new InvalidArgumentException(
107+
"{$className} must be a collection of {$this->collectionOf}"
108+
);
104109
}
105110
});
106111
}
@@ -109,7 +114,7 @@ protected function toCollectionWkt(): Expression
109114
{
110115
$wkb = $this->geometries
111116
->map(static function (Geometry $geometry): string {
112-
return $geometry->toWkt();
117+
return (string) $geometry->toWkt();
113118
})
114119
->join(',');
115120

src/helpers.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)