diff --git a/config/ide-helper.php b/config/ide-helper.php index c0b252a..19c520c 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -242,4 +242,16 @@ return array( */ 'include_class_docblocks' => false, + /* + |-------------------------------------------------------------------------- + | Force FQN usage + |-------------------------------------------------------------------------- + | + | Use the fully qualified (class) name in docBlock, + | event if class exists in a given file + | or there is an import (use className) of a given class + | + */ + 'force_fqn' => false, + ); diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 974f705..4a9640f 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1067,8 +1067,9 @@ class ModelsCommand extends Command $className = trim($className, '\\'); $writingToExternalFile = !$this->write; $classIsNotInExternalFile = $reflection->getName() !== $className; + $forceFQCN = $this->laravel['config']->get('ide-helper.force_fqn', false); - if ($writingToExternalFile && $classIsNotInExternalFile) { + if (($writingToExternalFile && $classIsNotInExternalFile) || $forceFQCN) { return '\\' . $className; } diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/Models/Post.php b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/Models/Post.php new file mode 100644 index 0000000..29a50e8 --- /dev/null +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/Models/Post.php @@ -0,0 +1,31 @@ +hasMany(Post::class); + } + + public function scopeNull($query, string $unusedParam) + { + return $query; + } +} diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/Test.php b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/Test.php new file mode 100644 index 0000000..7bd59d8 --- /dev/null +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/Test.php @@ -0,0 +1,31 @@ +set('ide-helper.force_fqn', true); + } + + public function test(): void + { + $command = $this->app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..347e13a --- /dev/null +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php @@ -0,0 +1,191 @@ +hasMany(Post::class); + } + + public function scopeNull($query, string $unusedParam) + { + return $query; + } +}