Skip to content

Commit 570bb4c

Browse files
committed
Require PHP8
1 parent 223d481 commit 570bb4c

39 files changed

+1144
-1029
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/build
22
/vendor
3+
.phpunit.result.cache
34
composer.lock
45
composer.phar
56
phpunit.xml

composer.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=5.3.3",
18-
"geo-io/interface": "~1.0"
17+
"php": "^8.0",
18+
"geo-io/interface": "2.x-dev"
19+
},
20+
"require-dev": {
21+
"phpunit/phpunit": "^9.5"
1922
},
2023
"autoload": {
2124
"psr-4": {
2225
"GeoIO\\Geometry\\": "src/"
2326
}
2427
},
25-
"extra": {
26-
"branch-alias": {
27-
"dev-master": "1.0-dev"
28+
"autoload-dev": {
29+
"psr-4": {
30+
"GeoIO\\Geometry\\": "tests/"
2831
}
2932
}
3033
}

phpunit.xml.dist

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false"
12-
bootstrap="tests/bootstrap.php"
3+
<phpunit
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
138
>
149
<testsuites>
1510
<testsuite name="Geo I/O Geometry Test Suite">
1611
<directory>./tests/</directory>
1712
</testsuite>
1813
</testsuites>
1914

20-
<filter>
21-
<whitelist>
15+
<coverage>
16+
<include>
2217
<directory>./src/</directory>
23-
</whitelist>
24-
</filter>
18+
</include>
19+
</coverage>
2520
</phpunit>

src/BaseGeometry.php

+7-30
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,29 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIO\Geometry;
46

5-
use GeoIO\Dimension;
6-
use GeoIO\Geometry\Exception\InvalidDimensionException;
7-
use GeoIO\Geometry\Exception\InvalidGeometryException;
8-
use GeoIO\Geometry\Exception\InvalidGeometryTypeException;
97
use GeoIO\Geometry\Exception\MixedDimensionalityException;
108
use GeoIO\Geometry\Exception\MixedSridsException;
119

1210
abstract class BaseGeometry implements Geometry
1311
{
14-
protected $dimension;
15-
protected $srid;
12+
protected string $dimension;
13+
protected ?int $srid;
1614

17-
public function getDimension()
15+
public function getDimension(): string
1816
{
1917
return $this->dimension;
2018
}
2119

22-
public function getSrid()
20+
public function getSrid(): ?int
2321
{
2422
return $this->srid;
2523
}
2624

27-
protected function assertDimension($dimension)
28-
{
29-
switch ($dimension) {
30-
case Dimension::DIMENSION_4D:
31-
case Dimension::DIMENSION_3DZ:
32-
case Dimension::DIMENSION_3DM:
33-
case Dimension::DIMENSION_2D:
34-
break;
35-
default:
36-
throw InvalidDimensionException::create($dimension);
37-
}
38-
}
39-
40-
protected function assertGeometry($geometry, $type = null)
25+
protected function assertGeometry(Geometry $geometry): void
4126
{
42-
if (!$geometry instanceof Geometry) {
43-
throw InvalidGeometryException::create($geometry);
44-
}
45-
46-
if (null !== $type && !$geometry instanceof $type) {
47-
throw InvalidGeometryTypeException::create($type, $geometry);
48-
}
49-
5027
if ($geometry->getDimension() !== $this->getDimension()) {
5128
throw MixedDimensionalityException::create($this, $geometry);
5229
}

src/Coordinates.php

-70
This file was deleted.

src/Exception/Exception.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIO\Geometry\Exception;
46

5-
interface Exception {}
7+
interface Exception
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIO\Geometry\Exception;
46

5-
class InsufficientNumberOfGeometriesException extends \InvalidArgumentException implements Exception
7+
use InvalidArgumentException;
8+
9+
class InsufficientNumberOfGeometriesException extends InvalidArgumentException implements Exception
610
{
7-
public static function create($expected, $given, $type)
11+
public static function create(int $expected, int $given, string $type): self
812
{
913
return new self(sprintf(
1014
'Expected at least %d geometries of type %s, got %d.',
1115
$expected,
1216
$type,
13-
$given
17+
$given,
1418
));
1519
}
1620
}

src/Exception/InvalidCoordinateException.php

-22
This file was deleted.

src/Exception/InvalidDimensionException.php

-14
This file was deleted.
+16-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIO\Geometry\Exception;
46

5-
class InvalidGeometryException extends \InvalidArgumentException implements Exception
7+
use InvalidArgumentException;
8+
9+
class InvalidGeometryException extends InvalidArgumentException implements Exception
610
{
7-
public static function create($value)
11+
public static function create(mixed $value): self
812
{
913
return new self(sprintf(
1014
'Expected valid Geometry object, got %s.',
11-
is_object($value) ? get_class($value) : gettype($value)
15+
get_debug_type($value),
16+
));
17+
}
18+
19+
public static function createForWrongType(string $expected, mixed $value): self
20+
{
21+
return new self(sprintf(
22+
'Expected Geometry object of type %s, got %s.',
23+
$expected,
24+
get_debug_type($value),
1225
));
1326
}
1427
}

src/Exception/InvalidGeometryTypeException.php

-17
This file was deleted.

src/Exception/LinearRingNotClosedException.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIO\Geometry\Exception;
46

5-
class LinearRingNotClosedException extends \InvalidArgumentException implements Exception
7+
use InvalidArgumentException;
8+
9+
class LinearRingNotClosedException extends InvalidArgumentException implements Exception
610
{
7-
public static function create()
11+
public static function create(): self
812
{
913
return new self('LinearRing requires the first and last positions to be equivalent.');
1014
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIO\Geometry\Exception;
46

5-
class MissingCoordinateException extends \InvalidArgumentException implements Exception
7+
use InvalidArgumentException;
8+
9+
class MissingCoordinateException extends InvalidArgumentException implements Exception
610
{
7-
public static function create($coordinate, $dimension)
11+
public static function create(string $coordinate, string $dimension): self
812
{
913
return new self(sprintf(
1014
'%s-coordinate must not be null for dimension %s.',
1115
strtoupper($coordinate),
12-
$dimension
16+
$dimension,
1317
));
1418
}
1519
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeoIO\Geometry\Exception;
46

57
use GeoIO\Geometry\Geometry;
8+
use InvalidArgumentException;
9+
use function get_class;
610

7-
class MixedDimensionalityException extends \InvalidArgumentException implements Exception
11+
class MixedDimensionalityException extends InvalidArgumentException implements Exception
812
{
9-
public static function create(Geometry $geometry, Geometry $subGeometry)
13+
public static function create(Geometry $geometry, Geometry $subGeometry): self
1014
{
1115
return new self(sprintf(
1216
'Can not mix dimensionality in a geometry: %s(%s) vs. %s(%s).',
1317
get_class($geometry),
1418
$geometry->getDimension(),
1519
get_class($subGeometry),
16-
$subGeometry->getDimension()
20+
$subGeometry->getDimension(),
1721
));
1822
}
1923
}

0 commit comments

Comments
 (0)