From 14f227c218db04c925ddd59ef6309874fcd1e34b Mon Sep 17 00:00:00 2001 From: erikn69 Date: Wed, 14 May 2025 14:08:50 -0500 Subject: [PATCH 1/2] fix: Add complete class methods to prevent Intelephense conflicts --- config/ide-helper.php | 13 +++++++++++++ src/Alias.php | 7 ++++++- .../GeneratorCommand/GenerateIdeHelper/Test.php | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/config/ide-helper.php b/config/ide-helper.php index 40c58353d..4d231ab03 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -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 diff --git a/src/Alias.php b/src/Alias.php index 245edb472..795ed4cd9 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -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; @@ -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(); @@ -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, diff --git a/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php b/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php index 950cf90c8..6c3877069 100644 --- a/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php +++ b/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php @@ -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]); $command = $this->app->make(GeneratorCommand::class); @@ -28,6 +29,7 @@ public function testGenerator(): void $this->assertStringContainsString('public static function configure($basePath = null)', $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); } public function testFilename(): void From fc8fa602045927e57948dd370a069386e0ae829e Mon Sep 17 00:00:00 2001 From: erikn69 Date: Wed, 14 May 2025 14:46:46 -0500 Subject: [PATCH 2/2] test to contrast the difference --- tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php b/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php index 6c3877069..78598d06c 100644 --- a/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php +++ b/tests/Console/GeneratorCommand/GenerateIdeHelper/Test.php @@ -30,6 +30,7 @@ public function testGenerator(): void $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