From b4138e5122b0c39ec2fd0989d0c7d497c3ac72a5 Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Fri, 4 Dec 2020 07:28:07 +0100 Subject: [PATCH] [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 --- .github/workflows/run-integration-tests.yml | 6 +++++- .github/workflows/run-tests.yml | 5 ++++- CHANGELOG.md | 1 + composer.json | 4 ++-- src/Console/ModelsCommand.php | 16 +++++++++++++--- .../ModelsCommand/DynamicRelations/Test.php | 10 +++++++++- .../__snapshots__/Test__test__1.php | 2 +- .../__snapshots__/Test__test__1.php | 2 +- 8 files changed, 36 insertions(+), 10 deletions(-) diff --git a/.github/workflows/run-integration-tests.yml b/.github/workflows/run-integration-tests.yml index c4c7fbc..1ed72c7 100644 --- a/.github/workflows/run-integration-tests.yml +++ b/.github/workflows/run-integration-tests.yml @@ -18,9 +18,13 @@ jobs: COMPOSER_NO_INTERACTION: 1 strategy: matrix: - php: [7.4, 7.3, 7.2] + php: [8.0, 7.4, 7.3, 7.2] lumen: [8.*, 7.*, 6.*] exclude: + - lumen: 6.* + php: 8.0 + - lumen: 7.* + php: 8.0 - lumen: 8.* php: 7.2 name: P${{ matrix.php }} - Lumen${{ matrix.lumen }} diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 225b253..9236cc6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,12 +19,14 @@ jobs: strategy: matrix: - php: [7.4, 7.3, 7.2] + php: [8.0, 7.4, 7.3, 7.2] laravel: [8.*, 7.*, 6.*] dependency-version: [prefer-lowest, prefer-stable] exclude: - laravel: 8.* php: 7.2 + - php: 8.0 + dependency-version: prefer-lowest name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} @@ -42,6 +44,7 @@ jobs: - name: Install dependencies run: | composer remove vimeo/psalm --no-update --dev + composer remove friendsofphp/php-cs-fixer --no-update --dev composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d64d1b..c3e4da6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - Fix phpdoc generate for custom cast with parameter [\#986 / artelkr](https://github.com/barryvdh/laravel-ide-helper/pull/986) - Created a possibility to add custom relation type [\#987 / efinder2](https://github.com/barryvdh/laravel-ide-helper/pull/987) - Added `@see` with macro/mixin definition location to PhpDoc [\#1054 / riesjart](https://github.com/barryvdh/laravel-ide-helper/pull/1054) +- Initial compatibility for PHP8 [\#1106 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1106) ### Changed - Implement DeferrableProvider [\#914 / kon-shou](https://github.com/barryvdh/laravel-ide-helper/pull/914) diff --git a/composer.json b/composer.json index 53ee4dd..38c4b1c 100644 --- a/composer.json +++ b/composer.json @@ -35,10 +35,10 @@ "friendsofphp/php-cs-fixer": "^2", "illuminate/config": "^6 || ^7 || ^8", "illuminate/view": "^6 || ^7 || ^8", - "mockery/mockery": "^1.3", + "mockery/mockery": "^1.3.3", "orchestra/testbench": "^4 || ^5 || ^6", "phpunit/phpunit": "^8.5 || ^9", - "spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3", + "spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3 || ^4", "vimeo/psalm": "^3.12" }, "config": { diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index fad4107..a17a5de 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -424,7 +424,7 @@ class ModelsCommand extends Command $database = null; if (strpos($table, '.')) { - list($database, $table) = explode('.', $table); + [$database, $table] = explode('.', $table); } $columns = $schema->listTableColumns($table, $database); @@ -895,8 +895,18 @@ class ModelsCommand extends Command $paramsWithDefault = []; /** @var \ReflectionParameter $param */ foreach ($method->getParameters() as $param) { - $paramClass = $param->getClass(); - $paramStr = (!is_null($paramClass) ? '\\' . $paramClass->getName() . ' ' : '') . '$' . $param->getName(); + $paramType = $param->getType(); + + $paramStr = '$' . $param->getName(); + if ($paramType) { + $paramTypeStr = $paramType->getName(); + if (!$paramType->isBuiltin()) { + $paramTypeStr = '\\' . $paramTypeStr; + } + + $paramStr = $paramTypeStr . ' ' . $paramStr; + } + if ($param->isOptional() && $param->isDefaultValueAvailable()) { $default = $param->getDefaultValue(); if (is_bool($default)) { diff --git a/tests/Console/ModelsCommand/DynamicRelations/Test.php b/tests/Console/ModelsCommand/DynamicRelations/Test.php index bc248b5..a36f8f0 100644 --- a/tests/Console/ModelsCommand/DynamicRelations/Test.php +++ b/tests/Console/ModelsCommand/DynamicRelations/Test.php @@ -17,11 +17,19 @@ class Test extends AbstractModelsCommand '--write' => true, ]); - $errors = <<= 80000) { + $errors = <<assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php index aecb210..2733d99 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php @@ -88,7 +88,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read int|null $posts_count * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newQuery() - * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post null($unusedParam) + * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post null(string $unusedParam) * @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post onlyTrashed() * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post query() * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBigIntegerNotNullable($value) diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php index 5dc83d0..453e933 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php @@ -94,7 +94,7 @@ use Illuminate\Support\Carbon; * @property-read int|null $posts_count * @method static EloquentBuilder|Post newModelQuery() * @method static EloquentBuilder|Post newQuery() - * @method static EloquentBuilder|Post null($unusedParam) + * @method static EloquentBuilder|Post null(string $unusedParam) * @method static QueryBuilder|Post onlyTrashed() * @method static EloquentBuilder|Post query() * @method static EloquentBuilder|Post whereBigIntegerNotNullable($value)