From f4656256fc8f41dc7bbfafda307da4a37b8caaf3 Mon Sep 17 00:00:00 2001 From: netpok Date: Wed, 7 Feb 2024 21:06:31 +0100 Subject: [PATCH] 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);