Removed support for Laravel 8 and therefore for PHP < 8.0 (#1504)

* Removed support for Laravel 8 and therefore for PHP < 8.0

* Update php-cs-fixer to v3

* composer fix-style
This commit is contained in:
Markus Podar
2024-02-05 13:25:08 +01:00
committed by GitHub
parent 485c756f6c
commit a8b34ad228
27 changed files with 63 additions and 242 deletions
+2 -14
View File
@@ -19,25 +19,13 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.3, 8.2, 8.1, 8.0, 7.4, 7.3]
laravel: [10.*, 9.*, 8.*]
php: [8.3, 8.2, 8.1, 8.0]
laravel: [10.*, 9.*]
exclude:
- php: 8.0
laravel: 10.*
- php: 7.4
laravel: 10.*
- php: 7.3
laravel: 10.*
- php: 8.3
laravel: 9.*
- php: 7.4
laravel: 9.*
- php: 7.3
laravel: 9.*
- php: 8.3
laravel: 8.*
- php: 8.2
laravel: 8.*
name: P${{ matrix.php }} - Laravel${{ matrix.laravel }}
steps:
- name: Checkout code
+2 -14
View File
@@ -20,26 +20,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, windows-2019]
php: [8.3, 8.2, 8.1, 8.0, 7.4, 7.3]
laravel: [8.*, 9.*, 10.*]
php: [8.3, 8.2, 8.1, 8.0]
laravel: [9.*, 10.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- php: 8.0
laravel: 10.*
- php: 7.4
laravel: 10.*
- php: 7.3
laravel: 10.*
- php: 8.0
dependency-version: prefer-lowest
- php: 7.4
laravel: 9.*
- php: 7.3
laravel: 9.*
- os: windows-2019
php: 7.4
- os: windows-2019
php: 7.3
steps:
- name: Set git to use LF
if: ${{ matrix.os == 'windows-2019' }}
+3 -3
View File
@@ -1,8 +1,8 @@
.phpunit.result.cache
/.idea
/.php_cs
/.php_cs.cache
/.php_cs.tests.cache
/.php-cs-fixer.cache
/.php-cs-fixer.php
/.php-cs-fixer.tests.cache
/composer.lock
/vendor
@@ -30,7 +30,6 @@ return [
],
'return_type_declaration' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_trait_insert_per_statement' => true,
'ternary_operator_spaces' => true,
'visibility_required' => [
@@ -56,7 +55,7 @@ return [
'no_unused_imports' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
+3 -3
View File
@@ -5,10 +5,10 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('tests');
$config = require __DIR__ . '/.php_cs.common.php';
$config = require __DIR__ . '/.php-cs-fixer.common.php';
return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setFinder($finder)
->setRules($config)
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.php_cs.cache');
->setCacheFile(__DIR__ . '/.php-cs-fixer.cache');
@@ -5,7 +5,7 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/tests')
->exclude('__snapshots__');
$config = require __DIR__ . '/.php_cs.common.php';
$config = require __DIR__ . '/.php-cs-fixer.common.php';
// Additional rules for tests
$config = array_merge(
@@ -15,8 +15,8 @@ $config = array_merge(
]
);
return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setFinder($finder)
->setRules($config)
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.php_cs.tests.cache');
->setCacheFile(__DIR__ . '/.php-cs-fixer.tests.cache');
+3
View File
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.14.0...master)
--------------
### Changed
- Removed support for Laravel 8 and therefore for PHP < 8.0 [#1504 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1504)
2024-02-05, 2.14.0
------------------
+1 -1
View File
@@ -11,7 +11,7 @@
This package generates helper files that enable your IDE to provide accurate autocompletion.
Generation is done based on the files in your project, so they are always up-to-date.
It supports Laravel 8+ and PHP 7.3+
It supports Laravel 9+ and PHP 8.0+
- [Installation](#installation)
- [Usage](#usage)
+9 -9
View File
@@ -20,24 +20,24 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.0",
"ext-json": "*",
"barryvdh/reflection-docblock": "^2.0.6",
"composer/class-map-generator": "^1.0",
"doctrine/dbal": "^2.6 || ^3",
"illuminate/console": "^8 || ^9 || ^10",
"illuminate/filesystem": "^8 || ^9 || ^10",
"illuminate/support": "^8 || ^9 || ^10",
"illuminate/console": "^9 || ^10",
"illuminate/filesystem": "^9 || ^10",
"illuminate/support": "^9 || ^10",
"nikic/php-parser": "^4.18 || ^5",
"phpdocumentor/type-resolver": "^1.1.0"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"friendsofphp/php-cs-fixer": "^2",
"illuminate/config": "^8 || ^9 || ^10",
"illuminate/view": "^8 || ^9 || ^10",
"friendsofphp/php-cs-fixer": "^3",
"illuminate/config": "^9 || ^10",
"illuminate/view": "^9 || ^10",
"mockery/mockery": "^1.4",
"orchestra/testbench": "^6 || ^7 || ^8",
"orchestra/testbench": "^7 || ^8",
"phpunit/phpunit": "^8.5 || ^9",
"spatie/phpunit-snapshot-assertions": "^3 || ^4",
"vimeo/psalm": "^5.4"
@@ -81,7 +81,7 @@
],
"fix-style": [
"php-cs-fixer fix",
"php-cs-fixer fix --config=.php_cs.tests.php"
"php-cs-fixer fix --config=.php-cs-fixer.tests.php"
],
"psalm-set-baseline": "psalm --set-baseline=psalm-baseline.xml",
"test": "phpunit",
+2 -2
View File
@@ -329,7 +329,7 @@ class Alias
continue;
}
$method = new \ReflectionMethod($className, $name);
$class = new \ReflectionClass($className);
$class = new ReflectionClass($className);
if (!in_array($magic, $this->usedMethods)) {
if ($class !== $this->root) {
@@ -348,7 +348,7 @@ class Alias
protected function detectMethods()
{
foreach ($this->classes as $class) {
$reflection = new \ReflectionClass($class);
$reflection = new ReflectionClass($class);
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
if ($methods) {
+2 -2
View File
@@ -42,7 +42,7 @@ class GeneratorCommand extends Command
/** @var \Illuminate\Config\Repository */
protected $config;
/** @var \Illuminate\Filesystem\Filesystem */
/** @var Filesystem */
protected $files;
/** @var \Illuminate\View\Factory */
@@ -54,7 +54,7 @@ class GeneratorCommand extends Command
/**
*
* @param \Illuminate\Config\Repository $config
* @param \Illuminate\Filesystem\Filesystem $files
* @param Filesystem $files
* @param \Illuminate\View\Factory $view
*/
public function __construct(
+12 -16
View File
@@ -354,7 +354,7 @@ class ModelsCommand extends Command
/**
* cast the properties's type from $casts.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*/
public function castPropertiesType($model)
{
@@ -498,7 +498,7 @@ class ModelsCommand extends Command
/**
* Load the properties from the database table.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*
* @throws DBALException If custom field failed to register
*/
@@ -602,7 +602,7 @@ class ModelsCommand extends Command
}
/**
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*/
public function getPropertiesFromMethods($model)
{
@@ -777,7 +777,7 @@ class ModelsCommand extends Command
'int|null',
true,
false
// What kind of comments should be added to the relation count here?
// What kind of comments should be added to the relation count here?
);
}
} elseif (
@@ -1126,7 +1126,7 @@ class ModelsCommand extends Command
return '\Illuminate\Database\Eloquent\Collection';
}
/** @var \Illuminate\Database\Eloquent\Model $model */
/** @var Model $model */
$model = new $className();
return '\\' . get_class($model->newCollection());
}
@@ -1285,7 +1285,7 @@ class ModelsCommand extends Command
/**
* Generates methods provided by the SoftDeletes trait
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*/
protected function getSoftDeleteMethods($model)
{
@@ -1302,7 +1302,7 @@ class ModelsCommand extends Command
/**
* Generate factory method from "HasFactory" trait.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*/
protected function getFactoryMethods($model)
{
@@ -1330,16 +1330,12 @@ class ModelsCommand extends Command
return;
}
if (version_compare($this->laravel->version(), '9', '>=')) {
$this->setMethod('factory', $factory, ['$count = null, $state = []']);
} else {
$this->setMethod('factory', $factory, ['...$parameters']);
}
$this->setMethod('factory', $factory, ['$count = null, $state = []']);
}
/**
* Generates methods that return collections
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*/
protected function getCollectionMethods($model)
{
@@ -1382,7 +1378,7 @@ class ModelsCommand extends Command
return $type;
}
$reflection = new \ReflectionClass($type);
$reflection = new ReflectionClass($type);
if (!$reflection->implementsInterface(Castable::class)) {
return $type;
@@ -1414,7 +1410,7 @@ class ModelsCommand extends Command
return $type;
}
$reflection = new \ReflectionClass($type);
$reflection = new ReflectionClass($type);
if (!$reflection->implementsInterface(CastsAttributes::class)) {
return $type;
@@ -1620,7 +1616,7 @@ class ModelsCommand extends Command
}
/**
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \RuntimeException
*/
+2 -2
View File
@@ -26,7 +26,7 @@ class Generator
/** @var \Illuminate\View\Factory */
protected $view;
/** @var \Symfony\Component\Console\Output\OutputInterface */
/** @var OutputInterface */
protected $output;
protected $extra = [];
@@ -37,7 +37,7 @@ class Generator
/**
* @param \Illuminate\Config\Repository $config
* @param \Illuminate\View\Factory $view
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param OutputInterface $output
* @param string $helpers
*/
public function __construct(
+4 -4
View File
@@ -16,15 +16,15 @@ class GenerateModelHelper
*/
public static $shouldRun = false;
/** @var \Illuminate\Contracts\Console\Kernel */
/** @var Artisan */
protected $artisan;
/** @var \Illuminate\Contracts\Config\Repository */
/** @var Config */
protected $config;
/**
* @param \Illuminate\Contracts\Console\Kernel $artisan
* @param \Illuminate\Contracts\Config\Repository $config
* @param Artisan $artisan
* @param Config $config
*/
public function __construct(Artisan $artisan, Config $config)
{
+1 -1
View File
@@ -22,7 +22,7 @@ use Illuminate\Support\Str;
class Method
{
/** @var \Barryvdh\Reflection\DocBlock */
/** @var DocBlock */
protected $phpdoc;
/** @var \ReflectionMethod */
@@ -27,7 +27,7 @@ class Simple extends Model
* phpdoc is ignored here deliberately due to performance reasons and also
* isn't supported by Laravel itself.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
* @return Attribute
*/
protected function notAnAttribute()
{
@@ -9,15 +9,6 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
class Test extends AbstractModelsCommand
{
protected function setUp(): void
{
parent::setUp();
if (!class_exists('\Illuminate\Database\Eloquent\Casts\Attribute')) {
$this->markTestSkipped('This test requires Laravel 8.77 or newer');
}
}
public function test(): void
{
$command = $this->app->make(ModelsCommand::class);
@@ -38,7 +38,7 @@ class Simple extends Model
* phpdoc is ignored here deliberately due to performance reasons and also
* isn't supported by Laravel itself.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
* @return Attribute
*/
protected function notAnAttribute()
{
@@ -17,19 +17,11 @@ class Test extends AbstractModelsCommand
'--write' => true,
]);
if (PHP_VERSION_ID >= 80000) {
$errors = [
'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',
];
} else {
$errors = [
"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",
];
}
$errors = [
'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',
];
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
+1 -30
View File
@@ -8,41 +8,12 @@ use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Closure;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Foundation\Application;
use Illuminate\Support\Str;
class Test extends AbstractModelsCommand
{
public function test_8(): void
public function testFactory(): void
{
if (!version_compare(Application::VERSION, '8.2', '>=') || !version_compare(Application::VERSION, '9', '<')) {
$this->markTestSkipped(
'This test only works in Laravel >= 8.2 and < 9'
);
}
Factory::guessFactoryNamesUsing(static::getFactoryNameResolver());
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
'--write' => true,
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertStringNotContainsString('not found', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
public function test_9(): void
{
if (!version_compare(Application::VERSION, '9', '>=')) {
$this->markTestSkipped(
'This test only works in Laravel >= 9'
);
}
Factory::guessFactoryNamesUsing(static::getFactoryNameResolver());
$command = $this->app->make(ModelsCommand::class);
@@ -1,94 +0,0 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithCustomNamespace
*
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace query()
* @mixin \Eloquent
*/
class ModelWithCustomNamespace extends Model
{
use HasFactory;
/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
protected static function newFactory()
{
return ModelWithCustomNamespaceFactory::new();
}
}
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithFactory
*
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithFactoryFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory query()
* @mixin \Eloquent
*/
class ModelWithFactory extends Model
{
use HasFactory;
}
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithNestedFactory
*
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithNestedFactoryFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory query()
* @mixin \Eloquent
*/
class ModelWithNestedFactory extends ModelWithFactory
{
}
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithoutFactory
*
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory query()
* @mixin \Eloquent
*/
class ModelWithoutFactory extends Model
{
use HasFactory;
}
@@ -11,7 +11,7 @@ class CastableReturnsAnonymousCaster implements Castable
{
public static function castUsing(array $arguments)
{
return new class() implements CastsAttributes {
return new class () implements CastsAttributes {
/**
* @inheritDoc
* @return CastedProperty
@@ -11,7 +11,7 @@ class CastableWithoutReturnType implements Castable
{
public static function castUsing(array $arguments)
{
return new class() implements CastsAttributes {
return new class () implements CastsAttributes {
public function get($model, string $key, $value, array $attributes)
{
return new CastedProperty();
@@ -10,7 +10,7 @@ class CustomCasterWithDocblockReturnFqn implements CastsAttributes
{
/**
* @inheritDoc
* @return \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty
* @return CastedProperty
*/
public function get($model, string $key, $value, array $attributes)
{
@@ -9,15 +9,6 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
class Test extends AbstractModelsCommand
{
protected function setUp(): void
{
parent::setUp();
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('This test requires PHP 8.0 or higher');
}
}
public function test(): void
{
$command = $this->app->make(ModelsCommand::class);
+2 -6
View File
@@ -190,10 +190,6 @@ class MacroTest extends TestCase
public function testInitPhpDocParamsWithUnionTypes(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('This test requires PHP 8.0 or higher');
}
$phpdoc = (new MacroMock())->getPhpDoc(eval(<<<'PHP'
return new ReflectionFunction(
/**
@@ -231,7 +227,7 @@ class MacroTest extends TestCase
{
$reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke');
$macro = new Macro($reflectionMethod, UrlGenerator::class, new \ReflectionClass(UrlGenerator::class), 'macroName');
$macro = new Macro($reflectionMethod, UrlGenerator::class, new ReflectionClass(UrlGenerator::class), 'macroName');
$this->assertInstanceOf(Macro::class, $macro);
}
@@ -243,7 +239,7 @@ class MacroTest extends TestCase
{
$reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke');
$macro = new Macro($reflectionMethod, 'URL', new \ReflectionClass(UrlGenerator::class), 'macroName');
$macro = new Macro($reflectionMethod, 'URL', new ReflectionClass(UrlGenerator::class), 'macroName');
$output = <<<'DOC'
/**
*