Skip to content

fix: Add complete Request class methods to prevent Intelephense conflicts #1695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/ide-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@

'include_fluent' => false,

/*
|--------------------------------------------------------------------------
| Request stub generation
|--------------------------------------------------------------------------
|
| Set to true to generate complete Request class stubs including all methods.
| This helps prevent conflicts with PHP Intelephense extension.
|
*/

'include_complete_request_stubs' => true,

/*
|--------------------------------------------------------------------------
| Factory builders
Expand Down
66 changes: 66 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public function __construct(
public function generate()
{
$app = app();
$aliases = $this->getAliases();

// Handle Request class specially if complete stubs are enabled
if ($this->config->get('ide-helper.include_complete_request_stubs', true)) {
foreach ($aliases as $alias) {
if ($alias->getExtends() === 'Illuminate\Http\Request') {
$this->addCompleteRequestMethods($alias);
}
}
}

return $this->view->make('ide-helper::helper')
->with('namespaces_by_extends_ns', $this->getAliasesByExtendsNamespace())
->with('namespaces_by_alias_ns', $this->getAliasesByAliasNamespace())
Expand Down Expand Up @@ -404,4 +415,59 @@ protected function getMacroableClasses(Collection $aliases)
});
});
}

/**
* Add complete Request class methods to the alias
*
* @param Alias $alias
* @return void
*/
protected function addCompleteRequestMethods(Alias $alias)
{
$methods = [
'input' => 'mixed',
'route' => 'mixed',
'file' => 'mixed',
'hasFile' => 'bool',
'all' => 'array',
'only' => 'array',
'except' => 'array',
'query' => 'mixed',
'cookie' => 'mixed',
'header' => 'mixed',
'server' => 'mixed',
'session' => 'mixed',
'old' => 'mixed',
'flash' => 'void',
'flashOnly' => 'void',
'flashExcept' => 'void',
'flush' => 'void',
'merge' => 'void',
'replace' => 'void',
'json' => 'mixed',
'isJson' => 'bool',
'wantsJson' => 'bool',
'is' => 'bool',
'routeIs' => 'bool',
'fullUrl' => 'string',
'url' => 'string',
'path' => 'string',
'decodedPath' => 'string',
'root' => 'string',
'method' => 'string',
'isMethod' => 'bool',
'bearerToken' => 'string',
'ip' => 'string',
'ips' => 'array',
'userAgent' => 'string',
'secure' => 'bool',
'ajax' => 'bool',
'pjax' => 'bool',
'prefetch' => 'bool',
];

foreach ($methods as $method => $returnType) {
$alias->addMethod($method, [], $returnType);
}
}
}