Skip to content

Commit

Permalink
[PHP8] Add initial compatibility (#1106)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mfn authored Dec 4, 2020
1 parent c4d1f78 commit b4138e5
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/run-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 13 additions & 3 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ protected function getPropertiesFromTable($model)

$database = null;
if (strpos($table, '.')) {
list($database, $table) = explode('.', $table);
[$database, $table] = explode('.', $table);
}

$columns = $schema->listTableColumns($table, $database);
Expand Down Expand Up @@ -895,8 +895,18 @@ public function getParameters($method)
$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)) {
Expand Down
10 changes: 9 additions & 1 deletion tests/Console/ModelsCommand/DynamicRelations/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ public function test(): void
'--write' => true,
]);

$errors = <<<TXT
if (PHP_VERSION_ID >= 80000) {
$errors = <<<TXT
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Attempt to read property "created_at" on null
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Attempt to read property "created_at" on null
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Attempt to read property "created_at" on null
TXT;
} else {
$errors = <<<TXT
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Trying to get property 'created_at' of non-object
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Trying to get property 'created_at' of non-object
Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Trying to get property 'created_at' of non-object
TXT;
}

$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
* @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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
* @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)
Expand Down

0 comments on commit b4138e5

Please sign in to comment.