Skip to content

Commit fab9050

Browse files
committed
Add ECS
1 parent 723b6a2 commit fab9050

File tree

5 files changed

+88
-15
lines changed

5 files changed

+88
-15
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Coding Standard
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
coding-standard:
9+
name: Coding Standard
10+
uses: brick/coding-standard/.github/workflows/coding-standard.yml@main

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
/vendor
22
/composer.lock
33
/.phpunit.cache
4+
5+
/tools/*
6+
!/tools/ecs/composer.json
7+
!/tools/ecs/ecs.php

src/CompoundCurve.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@
1111
use Brick\Geo\Exception\InvalidGeometryException;
1212
use Brick\Geo\Exception\NoSuchGeometryException;
1313
use Brick\Geo\Projector\Projector;
14+
use Countable;
15+
use IteratorAggregate;
1416
use Override;
1517

18+
use function array_map;
19+
use function array_reduce;
20+
use function array_values;
21+
use function count;
22+
1623
/**
1724
* A CompoundCurve is a collection of zero or more continuous CircularString or LineString instances.
1825
*
1926
* @template-implements \IteratorAggregate<int<0, max>, LineString|CircularString>
27+
*
2028
* @final
2129
*/
22-
class CompoundCurve extends Curve implements \Countable, \IteratorAggregate
30+
class CompoundCurve extends Curve implements Countable, IteratorAggregate
2331
{
2432
/**
2533
* The Curves that compose this CompoundCurve.
@@ -33,7 +41,7 @@ class CompoundCurve extends Curve implements \Countable, \IteratorAggregate
3341
/**
3442
* The coordinate system of each of the curves must match the one of the CompoundCurve.
3543
*
36-
* @param CoordinateSystem $cs The coordinate system of the CompoundCurve.
44+
* @param CoordinateSystem $cs The coordinate system of the CompoundCurve.
3745
* @param LineString|CircularString ...$curves The curves that compose the CompoundCurve.
3846
*
3947
* @throws EmptyGeometryException If any of the input curves is empty.
@@ -71,20 +79,20 @@ public function __construct(CoordinateSystem $cs, LineString|CircularString ...$
7179
/**
7280
* Creates a non-empty CompoundCurve composed of the given curves.
7381
*
74-
* @param LineString|CircularString $curve1 The first curve.
82+
* @param LineString|CircularString $curve1 The first curve.
7583
* @param LineString|CircularString ...$curveN The subsequent curves, if any.
7684
*
7785
* @throws EmptyGeometryException If any of the input curves is empty.
7886
* @throws InvalidGeometryException If the compound curve is not continuous.
7987
* @throws CoordinateSystemException If the curves use different coordinate systems.
8088
*/
81-
public static function of(LineString|CircularString $curve1, LineString|CircularString ...$curveN) : CompoundCurve
89+
public static function of(LineString|CircularString $curve1, LineString|CircularString ...$curveN): CompoundCurve
8290
{
8391
return new CompoundCurve($curve1->coordinateSystem(), $curve1, ...$curveN);
8492
}
8593

8694
#[Override]
87-
public function startPoint() : Point
95+
public function startPoint(): Point
8896
{
8997
if (count($this->curves) === 0) {
9098
throw new EmptyGeometryException('The CompoundCurve is empty and has no start point.');
@@ -94,7 +102,7 @@ public function startPoint() : Point
94102
}
95103

96104
#[Override]
97-
public function endPoint() : Point
105+
public function endPoint(): Point
98106
{
99107
$count = count($this->curves);
100108

@@ -108,7 +116,7 @@ public function endPoint() : Point
108116
/**
109117
* Returns the number of Curves in this CompoundCurve.
110118
*/
111-
public function numCurves() : int
119+
public function numCurves(): int
112120
{
113121
return count($this->curves);
114122
}
@@ -120,7 +128,7 @@ public function numCurves() : int
120128
*
121129
* @throws NoSuchGeometryException If there is no Curve at this index.
122130
*/
123-
public function curveN(int $n) : LineString|CircularString
131+
public function curveN(int $n): LineString|CircularString
124132
{
125133
if (! isset($this->curves[$n - 1])) {
126134
throw new NoSuchGeometryException('There is no Curve in this CompoundCurve at index ' . $n);
@@ -134,25 +142,25 @@ public function curveN(int $n) : LineString|CircularString
134142
*
135143
* @return list<LineString|CircularString>
136144
*/
137-
public function curves() : array
145+
public function curves(): array
138146
{
139147
return $this->curves;
140148
}
141149

142150
#[NoProxy, Override]
143-
public function geometryType() : string
151+
public function geometryType(): string
144152
{
145153
return 'CompoundCurve';
146154
}
147155

148156
#[NoProxy, Override]
149-
public function geometryTypeBinary() : int
157+
public function geometryTypeBinary(): int
150158
{
151159
return Geometry::COMPOUNDCURVE;
152160
}
153161

154162
#[Override]
155-
public function getBoundingBox() : BoundingBox
163+
public function getBoundingBox(): BoundingBox
156164
{
157165
return array_reduce(
158166
$this->curves,
@@ -165,7 +173,7 @@ public function getBoundingBox() : BoundingBox
165173
* @return list<list<list<float>>>
166174
*/
167175
#[Override]
168-
public function toArray() : array
176+
public function toArray(): array
169177
{
170178
return array_map(
171179
fn (Curve $curve) => $curve->toArray(),
@@ -189,7 +197,7 @@ public function project(Projector $projector): CompoundCurve
189197
* Returns the number of curves in this CompoundCurve.
190198
*/
191199
#[Override]
192-
public function count() : int
200+
public function count(): int
193201
{
194202
return count($this->curves);
195203
}
@@ -200,7 +208,7 @@ public function count() : int
200208
* @return ArrayIterator<int<0, max>, LineString|CircularString>
201209
*/
202210
#[Override]
203-
public function getIterator() : ArrayIterator
211+
public function getIterator(): ArrayIterator
204212
{
205213
return new ArrayIterator($this->curves);
206214
}

tools/ecs/composer.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"require": {
3+
"brick/coding-standard": "dev-main"
4+
},
5+
"config": {
6+
"allow-plugins": {
7+
"dealerdirect/phpcodesniffer-composer-installer": true
8+
}
9+
}
10+
}

tools/ecs/ecs.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Fixer\ClassNotation\OrderedTypesFixer;
6+
use PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer;
7+
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer;
8+
use PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer;
9+
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
10+
use Symplify\EasyCodingStandard\Config\ECSConfig;
11+
12+
return static function (ECSConfig $ecsConfig): void {
13+
$ecsConfig->import(__DIR__ . '/vendor/brick/coding-standard/ecs.php');
14+
15+
$libRootPath = __DIR__ . '/../../';
16+
17+
$ecsConfig->paths(
18+
[
19+
$libRootPath . '/src',
20+
$libRootPath . '/tests',
21+
__FILE__,
22+
],
23+
);
24+
25+
$ecsConfig->skip([
26+
$libRootPath . '/src/Proxy',
27+
28+
// We want to keep LineString|CircularString order
29+
OrderedTypesFixer::class => null,
30+
PhpdocTypesOrderFixer::class => null,
31+
32+
// CompoundCurve uses loose comparison intentionally when comparing points
33+
StrictComparisonFixer::class => $libRootPath . '/src/CompoundCurve.php',
34+
35+
// AbstractWktReader uses WKT syntax in summaries, which should not be considered a sentence
36+
PhpdocSummaryFixer::class => $libRootPath . '/src/Io/Internal/AbstractWktReader.php',
37+
38+
// GeoJsonReaderTest uses assertEquals() intentionally when comparing feature properties
39+
PhpUnitStrictFixer::class => $libRootPath . '/tests/IO/GeoJsonReaderTest.php',
40+
]);
41+
};

0 commit comments

Comments
 (0)