Skip to content

fix: Add complete class methods to prevent Intelephense conflicts #1710

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 3 commits 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
13 changes: 13 additions & 0 deletions config/ide-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@

'include_fluent' => false,

/*
|--------------------------------------------------------------------------
| Complete stub generation
|--------------------------------------------------------------------------
|
| Set to true to generate complete class stubs including all methods,
| can also detail the classes with an array; e.g.
| `[\Illuminate\Http\Request::class]`
|
*/

'include_complete_stubs' => false,

/*
|--------------------------------------------------------------------------
| Factory builders
Expand Down
7 changes: 6 additions & 1 deletion src/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Alias
protected $alias;
/** @psalm-var class-string $facade */
protected $facade;
protected $completeStub = false;
protected $extends = null;
protected $extendsClass = null;
protected $extendsNamespace = null;
Expand Down Expand Up @@ -80,6 +81,10 @@ public function __construct($config, $alias, $facade, $magicMethods = [], $inter
}

$this->valid = true;
$this->completeStub = $config->get('ide-helper.include_complete_stubs', false);
if(is_array($this->completeStub)) {
$this->completeStub = in_array(ltrim($this->root, '\\'), $this->completeStub);
}

$this->addClass($this->root);
$this->detectFake();
Expand Down Expand Up @@ -410,7 +415,7 @@ protected function detectMethods()
if (!in_array($method->name, $this->usedMethods)) {
// Only add the methods to the output when the root is not the same as the class.
// And don't add the __*() methods
if ($this->extends !== $class && substr($method->name, 0, 2) !== '__') {
if (($this->extends !== $class || $this->completeStub) && substr($method->name, 0, 2) !== '__') {
$this->methods[] = new Method(
$method,
$this->alias,
Expand Down
3 changes: 3 additions & 0 deletions tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function testGenerator(): void
});
DB::macro('db_custom_macro', function () {
});
$this->app['config']->set('ide-helper.include_complete_stubs', [Arr::class]);
$this->app['config']->set('ide-helper.macro_default_return_types', [Arr::class => 'Custom_Fake_Class']);

$command = $this->app->make(GeneratorCommand::class);
Expand All @@ -30,6 +31,8 @@ public function testGenerator(): void
$this->assertStringContainsString('* @return \Custom_Fake_Class', $this->mockFilesystemOutput);
$this->assertStringContainsString('public static function arr_custom_macro()', $this->mockFilesystemOutput);
$this->assertStringContainsString('public static function db_custom_macro()', $this->mockFilesystemOutput);
$this->assertStringContainsString('return \Illuminate\Support\Arr::add', $this->mockFilesystemOutput);
$this->assertStringNotContainsString('return \Illuminate\Support\Str::of', $this->mockFilesystemOutput);
}

public function testFilename(): void
Expand Down
Loading