From f4656256fc8f41dc7bbfafda307da4a37b8caaf3 Mon Sep 17 00:00:00 2001 From: netpok Date: Wed, 7 Feb 2024 21:06:31 +0100 Subject: [PATCH 1/5] Fix non-facade classes will result in no autocomplete (#841) * Filter out non-facade base classes * Remove Model as it is already skipped because it's not a facade --- resources/views/helper.php | 23 ++++++++++------------- src/Generator.php | 5 ++++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/resources/views/helper.php b/resources/views/helper.php index 4a925bc..90b7413 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -23,15 +23,12 @@ */ $aliases) : ?> - -namespace { +namespace { - getDocComment(' ')) ?> + getDocComment(' ')) ?> getClassType() ?> getExtendsClass() ?> { getMethods() as $method) : ?> - getDocComment(' ')) ?> + getDocComment(' ')) ?> public static function getName() ?>(getParamsWithDefault() ?>) {getDeclaringClass() !== $method->getRoot()) : ?> //Method inherited from getDeclaringClass() ?> @@ -42,19 +39,19 @@ namespace { shouldReturn() ? 'return ' : '' ?>getRootMethodCall() ?>; } - + } - + } $aliases) : ?> -namespace { +namespace { getClassType() ?> getShortName() ?> extends getExtends() ?> {getExtendsNamespace() == '\Illuminate\Database\Eloquent') : ?> - getMethods() as $method) : ?> - getDocComment(' ')) ?> + getMethods() as $method) : ?> + getDocComment(' ')) ?> public static function getName() ?>(getParamsWithDefault() ?>) {getDeclaringClass() !== $method->getRoot()) : ?> //Method inherited from getDeclaringClass() ?> @@ -67,14 +64,14 @@ namespace { } } - + } namespace { - + } diff --git a/src/Generator.php b/src/Generator.php index abad534..9df9291 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -13,6 +13,7 @@ namespace Barryvdh\LaravelIdeHelper; use Illuminate\Foundation\AliasLoader; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Facade; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use ReflectionClass; @@ -175,7 +176,9 @@ class Generator */ protected function getAliasesByExtendsNamespace() { - $aliases = $this->getValidAliases(); + $aliases = $this->getValidAliases()->filter(static function (Alias $alias) { + return is_subclass_of($alias->getExtends(), Facade::class); + }); $this->addMacroableClasses($aliases); From 9d14b019f63d08f7a9742364d2b3c6f469c28785 Mon Sep 17 00:00:00 2001 From: PapaBear Date: Wed, 7 Feb 2024 21:19:43 +0100 Subject: [PATCH 2/5] skip swoole, otherwise fatal error (#1477) Co-authored-by: Timo Frenzel --- src/Generator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Generator.php b/src/Generator.php index 9df9291..4a92d35 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -153,6 +153,11 @@ class Generator if ($facade == 'Illuminate\Support\Facades\Redis' && $name == 'Redis' && !class_exists('Predis\Client')) { continue; } + + // Skip the swoole + if ($facade == 'SwooleTW\Http\Server\Facades\Server' && $name == 'Server' && !class_exists('Swoole\Http\Server')) { + continue; + } $magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : []; $alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces); From f3ad1342426e4c964063e7bf24d65749b2ad8f1a Mon Sep 17 00:00:00 2001 From: Allan Laal Date: Wed, 7 Feb 2024 22:24:42 +0200 Subject: [PATCH 3/5] FIX vulnerability CVE-2021-43608 (#1392) Doctrine DBAL 3.x before 3.1.4 allows SQL Injection: https://www.cve.org/CVERecord?id=CVE-2021-43608 Co-authored-by: Barry vd. Heuvel --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 537d760..18e3902 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "ext-json": "*", "barryvdh/reflection-docblock": "^2.0.6", "composer/class-map-generator": "^1.0", - "doctrine/dbal": "^2.6 || ^3", + "doctrine/dbal": "^2.6 || ^3.1.4", "illuminate/console": "^9 || ^10", "illuminate/filesystem": "^9 || ^10", "illuminate/support": "^9 || ^10", From f64ff9c0b1fa12dff9d79fadb118019b062a512e Mon Sep 17 00:00:00 2001 From: Ruben Robles Date: Wed, 7 Feb 2024 21:27:30 +0100 Subject: [PATCH 4/5] Add support for enum default arguments using enum cases (#1464) * add case when default value is of type enum * Update CHANGELOG.md * add tests for enum arguments default values * ignore psalm issue (built-in `\UnitEnum` class does not exists in PHP7) * Update run-static-analysis.yml to use PHP8.1 --------- Co-authored-by: Barry vd. Heuvel Co-authored-by: Barry vd. Heuvel --- .github/workflows/run-static-analysis.yml | 2 +- CHANGELOG.md | 4 + psalm-baseline.xml | 5 + src/Console/ModelsCommand.php | 2 + .../Enums/PostStatus.php | 12 ++ .../Models/Post.php | 17 ++ .../Test.php | 30 +++ .../__snapshots__/Test__test__1.php | 172 ++++++++++++++++++ 8 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/Enums/PostStatus.php create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/Models/Post.php create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/Test.php create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/__snapshots__/Test__test__1.php diff --git a/.github/workflows/run-static-analysis.yml b/.github/workflows/run-static-analysis.yml index 1085dfe..c8c29bb 100644 --- a/.github/workflows/run-static-analysis.yml +++ b/.github/workflows/run-static-analysis.yml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: none extensions: pdo_sqlite diff --git a/CHANGELOG.md b/CHANGELOG.md index 16fa904..d638d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. ### Changed - Removed support for Laravel 8 and therefore for PHP < 8.0 [#1504 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1504) + +### Added +- Add support for enum default arguments using enum cases. [#1464 / d8vjork](https://github.com/barryvdh/laravel-ide-helper/pull/1464) + 2024-02-05, 2.14.0 ------------------ diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f6a5b14..84de223 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -16,4 +16,9 @@ \Storage + + + \UnitEnum + + diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index c2ce4a6..13735c2 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1099,6 +1099,8 @@ class ModelsCommand extends Command $default = 'null'; } elseif (is_int($default)) { //$default = $default; + } elseif ($default instanceof \UnitEnum) { + $default = '\\' . get_class($default) . '::' . $default->name; } else { $default = "'" . trim($default) . "'"; } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/Enums/PostStatus.php b/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/Enums/PostStatus.php new file mode 100644 index 0000000..afe6b9b --- /dev/null +++ b/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/Enums/PostStatus.php @@ -0,0 +1,12 @@ +=')) { + $this->markTestSkipped( + 'This test only works in PHP >= 8.1' + ); + } + + $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->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..b4229da --- /dev/null +++ b/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/__snapshots__/Test__test__1.php @@ -0,0 +1,172 @@ + Date: Thu, 8 Feb 2024 05:31:12 +0900 Subject: [PATCH 5/5] reset foreignKeyConstraintsColumns on model loop start (#1461) --- src/Console/ModelsCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 13735c2..fd34432 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -266,6 +266,7 @@ class ModelsCommand extends Command } $this->properties = []; $this->methods = []; + $this->foreignKeyConstraintsColumns = []; if (class_exists($name)) { try { // handle abstract classes, interfaces, ...