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
This commit is contained in:
netpok
2024-02-07 21:06:31 +01:00
committed by GitHub
parent cc9ed4423b
commit f4656256fc
2 changed files with 14 additions and 14 deletions
+10 -13
View File
@@ -23,15 +23,12 @@
*/ */
<?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?> <?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?>
<?php if ($namespace == '\Illuminate\Database\Eloquent') : namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
continue;
endif; ?>
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
<?php foreach ($aliases as $alias) : ?> <?php foreach ($aliases as $alias) : ?>
<?= trim($alias->getDocComment(' ')) ?> <?= trim($alias->getDocComment(' ')) ?>
<?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> { <?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
<?php foreach ($alias->getMethods() as $method) : ?> <?php foreach ($alias->getMethods() as $method) : ?>
<?= trim($method->getDocComment(' ')) ?> <?= trim($method->getDocComment(' ')) ?>
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>) public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?> {<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>
//Method inherited from <?= $method->getDeclaringClass() ?> //Method inherited from <?= $method->getDeclaringClass() ?>
@@ -42,19 +39,19 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
<?php endif?> <?php endif?>
<?= $method->shouldReturn() ? 'return ' : '' ?><?= $method->getRootMethodCall() ?>; <?= $method->shouldReturn() ? 'return ' : '' ?><?= $method->getRootMethodCall() ?>;
} }
<?php endforeach; ?> <?php endforeach; ?>
} }
<?php endforeach; ?> <?php endforeach; ?>
} }
<?php endforeach; ?> <?php endforeach; ?>
<?php foreach ($namespaces_by_alias_ns as $namespace => $aliases) : ?> <?php foreach ($namespaces_by_alias_ns as $namespace => $aliases) : ?>
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> { namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
<?php foreach ($aliases as $alias) : ?> <?php foreach ($aliases as $alias) : ?>
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> extends <?= $alias->getExtends() ?> {<?php if ($alias->getExtendsNamespace() == '\Illuminate\Database\Eloquent') : ?> <?= $alias->getClassType() ?> <?= $alias->getShortName() ?> extends <?= $alias->getExtends() ?> {<?php if ($alias->getExtendsNamespace() == '\Illuminate\Database\Eloquent') : ?>
<?php foreach ($alias->getMethods() as $method) : ?> <?php foreach ($alias->getMethods() as $method) : ?>
<?= trim($method->getDocComment(' ')) ?> <?= trim($method->getDocComment(' ')) ?>
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>) public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?> {<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>
//Method inherited from <?= $method->getDeclaringClass() ?> //Method inherited from <?= $method->getDeclaringClass() ?>
@@ -67,14 +64,14 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
} }
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?>} <?php endif; ?>}
<?php endforeach; ?> <?php endforeach; ?>
} }
<?php endforeach; ?> <?php endforeach; ?>
<?php if ($helpers) : ?> <?php if ($helpers) : ?>
namespace { namespace {
<?= $helpers ?> <?= $helpers ?>
} }
<?php endif; ?> <?php endif; ?>
+4 -1
View File
@@ -13,6 +13,7 @@ namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Foundation\AliasLoader; use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Macroable;
use ReflectionClass; use ReflectionClass;
@@ -175,7 +176,9 @@ class Generator
*/ */
protected function getAliasesByExtendsNamespace() 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); $this->addMacroableClasses($aliases);