Skip to content

Commit 4e41315

Browse files
authored
Support PHP 8.1 & Laravel 9 (#25)
* support php 8.1 and laravel 9; fix github actions * fix github actions * improve phpstan types; update php-cs-fixer * use builder generics * remove phpinsights from ci * fix ci * fix dep conflicts
1 parent 5bae080 commit 4e41315

17 files changed

+103
-114
lines changed

.github/workflows/php-cs-fixer.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ jobs:
1515
- name: Setup PHP
1616
uses: shivammathur/setup-php@v2
1717
with:
18-
php-version: 8.0
19-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
18+
php-version: 8.1
2019
coverage: none
2120

2221
- name: Install dependencies

.github/workflows/phpinsights.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
- name: Setup PHP
1616
uses: shivammathur/setup-php@v2
1717
with:
18-
php-version: 8.0
19-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
18+
php-version: 8.1
2019
coverage: none
2120

2221
- name: Install dependencies
2322
run: composer install --prefer-dist --no-interaction
2423

25-
- name: Run PHPInsights
26-
run: ./vendor/bin/phpinsights --no-interaction --ansi --format=github-action
24+
# Package is broken
25+
# - name: Run PHPInsights
26+
# run: ./vendor/bin/phpinsights --no-interaction --ansi --format=github-action

.github/workflows/phpstan.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ jobs:
88

99
runs-on: ubuntu-latest
1010

11+
strategy:
12+
fail-fast: true
13+
matrix:
14+
php: [8.1, 8.0]
15+
1116
steps:
1217
- name: Checkout code
1318
uses: actions/checkout@v2
1419

1520
- name: Setup PHP
1621
uses: shivammathur/setup-php@v2
1722
with:
18-
php-version: 8.0
19-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
23+
php-version: ${{ matrix.php }}
2024
coverage: none
2125

2226
- name: Install dependencies

.github/workflows/phpunit.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ on: [push]
44

55
jobs:
66
test:
7-
name: PHPUnit
7+
name: PHPUnit - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }}
88

99
runs-on: ubuntu-latest
1010

11+
strategy:
12+
fail-fast: true
13+
matrix:
14+
php: [8.1, 8.0]
15+
laravel: [9.*, 8.*]
16+
dependency-version: [prefer-lowest, prefer-stable]
17+
include:
18+
- laravel: 8.*
19+
testbench: ^6.23
20+
- laravel: 9.*
21+
testbench: 7.*
22+
1123
services:
1224
mysql:
1325
image: mysql:8.0
@@ -25,12 +37,13 @@ jobs:
2537
- name: Setup PHP
2638
uses: shivammathur/setup-php@v2
2739
with:
28-
php-version: 8.0
29-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
40+
php-version: ${{ matrix.php }}
3041
coverage: none
3142

3243
- name: Install dependencies
33-
run: composer install --prefer-dist --no-interaction
44+
run: |
45+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
46+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
3447
3548
- name: Execute tests
3649
env:

.php-cs-fixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
return (new MattAllan\LaravelCodeStyle\Config())
3+
return (new Jubeki\LaravelCodeStyle\Config())
44
->setFinder(
55
PhpCsFixer\Finder::create()
66
->in(__DIR__)

composer.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"require": {
1313
"php": "^8.0",
1414
"ext-json": "*",
15-
"laravel/framework": "^8.0",
15+
"laravel/framework": "^8.0|^9.0",
1616
"phayes/geophp": "^1.2"
1717
},
1818
"require-dev": {
19-
"friendsofphp/php-cs-fixer": "^3.0.0",
20-
"matt-allan/laravel-code-style": "dev-main",
21-
"nunomaduro/larastan": "^0.7.0",
22-
"nunomaduro/phpinsights": "dev-master",
23-
"orchestra/testbench": "^6.0",
19+
"friendsofphp/php-cs-fixer": "^3.0",
20+
"jubeki/laravel-code-style": "^1.0",
21+
"nunomaduro/phpinsights": "^1.0|^2.0",
22+
"nunomaduro/larastan": "^1.0|^2.0",
23+
"orchestra/testbench": "^6.23|^7.0",
2424
"phpunit/phpunit": "^9.3"
2525
},
2626
"autoload": {
@@ -43,7 +43,10 @@
4343
"phpinsights-fix": "./vendor/bin/phpinsights fix"
4444
},
4545
"config": {
46-
"sort-packages": true
46+
"sort-packages": true,
47+
"allow-plugins": {
48+
"dealerdirect/phpcodesniffer-composer-installer": false
49+
}
4750
},
4851
"minimum-stability": "dev",
4952
"prefer-stable": true

phpstan.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ parameters:
88
ignoreErrors:
99
- '#Method MatanYadaev\\EloquentSpatial\\Objects\\(Geometry|GeometryCollection)::(toJson|toFeatureCollectionJson)\(\) should return string but returns string\|false\.#'
1010
-
11-
message: '#Call to private method .+\(\) of parent class Illuminate\\Database\\Eloquent\\Builder\<Illuminate\\Database\\Eloquent\\Model\>.#'
11+
message: '#Call to an undefined method .+#'
1212
path: ./src/SpatialBuilder.php
1313
excludePaths:
1414
- ./src/Factory.php
1515
checkMissingIterableValueType: true
16+
checkGenericClassInNonGenericObjectType: false
17+

src/GeometryCast.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ class GeometryCast implements CastsAttributes
1616
private string $className;
1717

1818
/**
19-
* @param class-string<Geometry> $className
19+
* @param class-string<Geometry> $className
2020
*/
2121
public function __construct(string $className)
2222
{
2323
$this->className = $className;
2424
}
2525

2626
/**
27-
* @param Model $model
28-
* @param string $key
29-
* @param string|null $wkb
30-
* @param array<string, mixed> $attributes
31-
*
27+
* @param Model $model
28+
* @param string $key
29+
* @param string|null $wkb
30+
* @param array<string, mixed> $attributes
3231
* @return Geometry|null
3332
*/
3433
public function get($model, string $key, $wkb, array $attributes): ?Geometry
@@ -41,16 +40,15 @@ public function get($model, string $key, $wkb, array $attributes): ?Geometry
4140
}
4241

4342
/**
44-
* @param Model $model
45-
* @param string $key
46-
* @param Geometry|mixed|null $geometry
47-
* @param array<string, mixed> $attributes
48-
*
43+
* @param Model $model
44+
* @param string $key
45+
* @param Geometry|mixed|null $geometry
46+
* @param array<string, mixed> $attributes
4947
* @return Expression|string|null
5048
*
5149
* @throws InvalidArgumentException
5250
*/
53-
public function set($model, string $key, $geometry, array $attributes): Expression | string | null
51+
public function set($model, string $key, $geometry, array $attributes): Expression|string|null
5452
{
5553
if (! $geometry) {
5654
return null;

src/Objects/Geometry.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public function toJson($options = 0): string
2424
}
2525

2626
/**
27-
* @param string $wkb
28-
*
27+
* @param string $wkb
2928
* @return static
3029
*
3130
* @throws InvalidArgumentException
@@ -44,8 +43,7 @@ public static function fromWkb(string $wkb): static
4443
}
4544

4645
/**
47-
* @param string $geoJson
48-
*
46+
* @param string $geoJson
4947
* @return static
5048
*
5149
* @throws InvalidArgumentException
@@ -111,8 +109,7 @@ public function toFeatureCollectionJson(): string
111109
abstract public function getCoordinates(): array;
112110

113111
/**
114-
* @param array<string> $arguments
115-
*
112+
* @param array<string> $arguments
116113
* @return CastsAttributes
117114
*/
118115
public static function castUsing(array $arguments): CastsAttributes

src/Objects/GeometryCollection.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@
1111
use Illuminate\Support\Str;
1212
use InvalidArgumentException;
1313

14+
/**
15+
* @template TGeometry of Geometry
16+
*/
1417
class GeometryCollection extends Geometry implements ArrayAccess
1518
{
16-
/** @var Collection<Geometry> */
19+
/** @var Collection<int, TGeometry> */
1720
protected Collection $geometries;
1821

22+
/** @var class-string<TGeometry> */
1923
protected string $collectionOf = Geometry::class;
2024

2125
protected int $minimumGeometries = 0;
2226

2327
/**
24-
* @param Collection<Geometry>|array<Geometry> $geometries
28+
* @param Collection<int, TGeometry>|array<int, TGeometry> $geometries
2529
*
2630
* @throws InvalidArgumentException
2731
*/
28-
public function __construct(Collection | array $geometries)
32+
public function __construct(Collection|array $geometries)
2933
{
3034
if (is_array($geometries)) {
3135
$geometries = collect($geometries);
@@ -59,6 +63,7 @@ public function getCoordinates(): array
5963
*/
6064
public function toArray(): array
6165
{
66+
// @phpstan-ignore-next-line
6267
if (static::class === self::class) {
6368
return [
6469
'type' => class_basename(static::class),
@@ -72,16 +77,15 @@ public function toArray(): array
7277
}
7378

7479
/**
75-
* @return Collection<Geometry>
80+
* @return Collection<int, TGeometry>
7681
*/
7782
public function getGeometries(): Collection
7883
{
79-
return $this->geometries->collect();
84+
return new Collection($this->geometries->all());
8085
}
8186

8287
/**
83-
* @param mixed $offset
84-
*
88+
* @param int $offset
8589
* @return bool
8690
*/
8791
public function offsetExists($offset): bool
@@ -90,18 +94,17 @@ public function offsetExists($offset): bool
9094
}
9195

9296
/**
93-
* @param mixed $offset
94-
*
95-
* @return Geometry
97+
* @param int $offset
98+
* @return TGeometry|null
9699
*/
97-
public function offsetGet($offset): Geometry
100+
public function offsetGet($offset): ?Geometry
98101
{
99102
return $this->geometries[$offset];
100103
}
101104

102105
/**
103-
* @param mixed $offset
104-
* @param Geometry $geometry
106+
* @param int $offset
107+
* @param TGeometry $geometry
105108
*/
106109
public function offsetSet($offset, $geometry): void
107110
{
@@ -110,7 +113,7 @@ public function offsetSet($offset, $geometry): void
110113
}
111114

112115
/**
113-
* @param mixed $offset
116+
* @param int $offset
114117
*/
115118
public function offsetUnset($offset): void
116119
{
@@ -141,7 +144,8 @@ protected function validateGeometriesCount(): void
141144
*/
142145
protected function validateGeometriesType(): void
143146
{
144-
$this->geometries->each(function (mixed $geometry): void {
147+
$this->geometries->each(function (mixed $geometry, $a): void {
148+
/** @var mixed $geometry */
145149
if (! is_object($geometry) || ! ($geometry instanceof $this->collectionOf)) {
146150
throw new InvalidArgumentException(
147151
sprintf('%s must be a collection of %s', static::class, $this->collectionOf)

0 commit comments

Comments
 (0)