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/composer.json b/composer.json
index 034bd9a..13a61ce 100644
--- a/composer.json
+++ b/composer.json
@@ -24,7 +24,7 @@
"ext-json": "*",
"barryvdh/reflection-docblock": "^2.1.1",
"composer/class-map-generator": "^1.0",
- "doctrine/dbal": "^3.1",
+ "doctrine/dbal": "^3.1.4",
"illuminate/console": "^9 || ^10",
"illuminate/filesystem": "^9 || ^10",
"illuminate/support": "^9 || ^10",
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/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 == '__root' ? '' : trim($namespace, '\\') ?> {
+namespace = $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
- = trim($alias->getDocComment(' ')) ?>
+ = trim($alias->getDocComment(' ')) ?>
= $alias->getClassType() ?> = $alias->getExtendsClass() ?> {
getMethods() as $method) : ?>
- = trim($method->getDocComment(' ')) ?>
+ = trim($method->getDocComment(' ')) ?>
public static function = $method->getName() ?>(= $method->getParamsWithDefault() ?>)
{getDeclaringClass() !== $method->getRoot()) : ?>
//Method inherited from = $method->getDeclaringClass() ?>
@@ -42,19 +39,19 @@ namespace = $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
= $method->shouldReturn() ? 'return ' : '' ?>= $method->getRootMethodCall() ?>;
}
-
+
}
-
+
}
$aliases) : ?>
-namespace = $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
+namespace = $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
= $alias->getClassType() ?> = $alias->getShortName() ?> extends = $alias->getExtends() ?> {getExtendsNamespace() == '\Illuminate\Database\Eloquent') : ?>
- getMethods() as $method) : ?>
- = trim($method->getDocComment(' ')) ?>
+ getMethods() as $method) : ?>
+ = trim($method->getDocComment(' ')) ?>
public static function = $method->getName() ?>(= $method->getParamsWithDefault() ?>)
{getDeclaringClass() !== $method->getRoot()) : ?>
//Method inherited from = $method->getDeclaringClass() ?>
@@ -67,14 +64,14 @@ namespace = $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
}
}
-
+
}
namespace {
- = $helpers ?>
+ = $helpers ?>
}
diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php
index c2ce4a6..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, ...
@@ -1099,6 +1100,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/src/Generator.php b/src/Generator.php
index abad534..4a92d35 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;
@@ -152,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);
@@ -175,7 +181,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);
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 @@
+