diff --git a/config/ide-helper.php b/config/ide-helper.php index 6eb5b85a8..bf53ff610 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 fed9e0acb..e31b368a8 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]); $this->app['config']->set('ide-helper.macro_default_return_types', [Arr::class => 'Custom_Fake_Class']); $command = $this->app->make(GeneratorCommand::class); @@ -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