Skip to content

Commit b4138e5

Browse files
authored
[PHP8] Add initial compatibility (#1106)
* gha: run on PHP8 too The composer.json constraint is unbound, so it's already "allowed" at least. * gha: remove php-cs-fixer when running unit tests - not necessary anyway - not compatible with PHP8 currently * gha: lumen 6 and 7 don't support PHP8 * composer.json: allow spatie/phpunit-snapshot-assertions 4.* for PHP8 compatibility * php8-compat: Method ReflectionParameter::getClass() is deprecated * php8-compat: adapt expected error message depending on PHP version * composer.json: bump mockery to 1.3.3 minimum This is the minimum version also supporting PHP8 * gha: disable prefer-lowest for PHP8 Some lower version requirements like doctrone/dbal won't work and would require at least dbal 2.12.0, which in turn doesn't support PHP 7.2 anymore. So instead of bumping dbal and excluding PHP 7.2 users, we ignore the lowest version for PHP 8 for the time being. * Update CHANGELOG.md
1 parent c4d1f78 commit b4138e5

File tree

8 files changed

+36
-10
lines changed

8 files changed

+36
-10
lines changed

.github/workflows/run-integration-tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ jobs:
1818
COMPOSER_NO_INTERACTION: 1
1919
strategy:
2020
matrix:
21-
php: [7.4, 7.3, 7.2]
21+
php: [8.0, 7.4, 7.3, 7.2]
2222
lumen: [8.*, 7.*, 6.*]
2323
exclude:
24+
- lumen: 6.*
25+
php: 8.0
26+
- lumen: 7.*
27+
php: 8.0
2428
- lumen: 8.*
2529
php: 7.2
2630
name: P${{ matrix.php }} - Lumen${{ matrix.lumen }}

.github/workflows/run-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ jobs:
1919

2020
strategy:
2121
matrix:
22-
php: [7.4, 7.3, 7.2]
22+
php: [8.0, 7.4, 7.3, 7.2]
2323
laravel: [8.*, 7.*, 6.*]
2424
dependency-version: [prefer-lowest, prefer-stable]
2525
exclude:
2626
- laravel: 8.*
2727
php: 7.2
28+
- php: 8.0
29+
dependency-version: prefer-lowest
2830

2931
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
3032

@@ -42,6 +44,7 @@ jobs:
4244
- name: Install dependencies
4345
run: |
4446
composer remove vimeo/psalm --no-update --dev
47+
composer remove friendsofphp/php-cs-fixer --no-update --dev
4548
composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress
4649
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress
4750

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
99
- Fix phpdoc generate for custom cast with parameter [\#986 / artelkr](https://github.com/barryvdh/laravel-ide-helper/pull/986)
1010
- Created a possibility to add custom relation type [\#987 / efinder2](https://github.com/barryvdh/laravel-ide-helper/pull/987)
1111
- Added `@see` with macro/mixin definition location to PhpDoc [\#1054 / riesjart](https://github.com/barryvdh/laravel-ide-helper/pull/1054)
12+
- Initial compatibility for PHP8 [\#1106 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1106)
1213

1314
### Changed
1415
- Implement DeferrableProvider [\#914 / kon-shou](https://github.com/barryvdh/laravel-ide-helper/pull/914)

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
"friendsofphp/php-cs-fixer": "^2",
3636
"illuminate/config": "^6 || ^7 || ^8",
3737
"illuminate/view": "^6 || ^7 || ^8",
38-
"mockery/mockery": "^1.3",
38+
"mockery/mockery": "^1.3.3",
3939
"orchestra/testbench": "^4 || ^5 || ^6",
4040
"phpunit/phpunit": "^8.5 || ^9",
41-
"spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3",
41+
"spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3 || ^4",
4242
"vimeo/psalm": "^3.12"
4343
},
4444
"config": {

src/Console/ModelsCommand.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ protected function getPropertiesFromTable($model)
424424

425425
$database = null;
426426
if (strpos($table, '.')) {
427-
list($database, $table) = explode('.', $table);
427+
[$database, $table] = explode('.', $table);
428428
}
429429

430430
$columns = $schema->listTableColumns($table, $database);
@@ -895,8 +895,18 @@ public function getParameters($method)
895895
$paramsWithDefault = [];
896896
/** @var \ReflectionParameter $param */
897897
foreach ($method->getParameters() as $param) {
898-
$paramClass = $param->getClass();
899-
$paramStr = (!is_null($paramClass) ? '\\' . $paramClass->getName() . ' ' : '') . '$' . $param->getName();
898+
$paramType = $param->getType();
899+
900+
$paramStr = '$' . $param->getName();
901+
if ($paramType) {
902+
$paramTypeStr = $paramType->getName();
903+
if (!$paramType->isBuiltin()) {
904+
$paramTypeStr = '\\' . $paramTypeStr;
905+
}
906+
907+
$paramStr = $paramTypeStr . ' ' . $paramStr;
908+
}
909+
900910
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
901911
$default = $param->getDefaultValue();
902912
if (is_bool($default)) {

tests/Console/ModelsCommand/DynamicRelations/Test.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ public function test(): void
1717
'--write' => true,
1818
]);
1919

20-
$errors = <<<TXT
20+
if (PHP_VERSION_ID >= 80000) {
21+
$errors = <<<TXT
22+
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Attempt to read property "created_at" on null
23+
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Attempt to read property "created_at" on null
24+
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Attempt to read property "created_at" on null
25+
TXT;
26+
} else {
27+
$errors = <<<TXT
2128
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Trying to get property 'created_at' of non-object
2229
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Trying to get property 'created_at' of non-object
2330
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Trying to get property 'created_at' of non-object
2431
TXT;
32+
}
2533

2634
$this->assertSame(0, $tester->getStatusCode());
2735
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());

tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
* @property-read int|null $posts_count
8989
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newModelQuery()
9090
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newQuery()
91-
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post null($unusedParam)
91+
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post null(string $unusedParam)
9292
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post onlyTrashed()
9393
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post query()
9494
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBigIntegerNotNullable($value)

tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
* @property-read int|null $posts_count
9595
* @method static EloquentBuilder|Post newModelQuery()
9696
* @method static EloquentBuilder|Post newQuery()
97-
* @method static EloquentBuilder|Post null($unusedParam)
97+
* @method static EloquentBuilder|Post null(string $unusedParam)
9898
* @method static QueryBuilder|Post onlyTrashed()
9999
* @method static EloquentBuilder|Post query()
100100
* @method static EloquentBuilder|Post whereBigIntegerNotNullable($value)

0 commit comments

Comments
 (0)