Skip to content

Commit

Permalink
Add meta override for user return types (#1642)
Browse files Browse the repository at this point in the history
* Add meta override for user return types

* composer fix-style

---------

Co-authored-by: laravel-ide-helper <laravel-ide-helper@users.noreply.github.com>
  • Loading branch information
barryvdh and laravel-ide-helper authored Dec 30, 2024
1 parent c324438 commit 791ba55
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions resources/views/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
]));
<?php endforeach; ?>

<?php foreach ($userMethods as $method) : ?>
override(<?= $method ?>, map([
'' => \<?= $userModel ?>::class,
]));
<?php endforeach; ?>

<?php foreach ($configMethods as $method) : ?>
override(<?= $method ?>, map([
<?php foreach ($configValues as $name => $value) : ?>
Expand Down
13 changes: 13 additions & 0 deletions src/Console/MetaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class MetaCommand extends Command
'\Illuminate\Support\Facades\Config::set()',
];

protected $userMethods = [
'\auth()->user()',
'\Illuminate\Contracts\Auth\Guard::user()',
'\Illuminate\Support\Facades\Auth::user()',
'\request()->user()',
'\Illuminate\Http\Request::user()',
'\Illuminate\Support\Facades\Request::user()',
];

protected $templateCache = [];

/**
Expand Down Expand Up @@ -135,6 +144,8 @@ public function handle()
return gettype($value);
});

$defaultUserModel = $this->config->get('auth.providers.users.model', $this->config->get('auth.model', 'App\User'));

$content = $this->view->make('ide-helper::meta', [
'bindings' => $bindings,
'methods' => $this->methods,
Expand All @@ -143,6 +154,8 @@ public function handle()
'configValues' => $configValues,
'expectedArgumentSets' => $this->getExpectedArgumentSets(),
'expectedArguments' => $this->getExpectedArguments(),
'userModel' => $defaultUserModel,
'userMethods' => $this->userMethods,
])->render();

$filename = $this->option('filename');
Expand Down

0 comments on commit 791ba55

Please sign in to comment.