diff --git a/config/ide-helper.php b/config/ide-helper.php index 374eacb..7748139 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -13,7 +13,7 @@ return array( 'filename' => '_ide_helper', 'format' => 'php', - + 'meta_filename' => '.phpstorm.meta.php', /* @@ -95,6 +95,18 @@ return array( 'app', ), + /* + |-------------------------------------------------------------------------- + | Models to ignore + |-------------------------------------------------------------------------- + | + | Define which models should be ignored. + | + */ + + 'ignored_models' => array( + + ), /* |-------------------------------------------------------------------------- diff --git a/readme.md b/readme.md index 704d10c..5fec144 100644 --- a/readme.md +++ b/readme.md @@ -149,6 +149,14 @@ Models can be ignored using the `--ignore (-I)` option php artisan ide-helper:models --ignore="Post,User" ``` +Or can be ignored by setting the `ignored_models` config +```php +'ignored_models' => array( + Post::class, + Api\User::class +), +``` + Note: With namespaces, wrap your model name in double-quotes (`"`): `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`) For properly recognition of `Model` methods (i.e. `paginate`, `findOrFail`) you should extend `\Eloquent` or add diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index dd7a06c..7e3b9ba 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -185,7 +185,10 @@ class ModelsCommand extends Command } } - $ignore = explode(',', $ignore); + $ignore = array_merge( + explode(',', $ignore), + $this->laravel['config']->get('ide-helper.ignored_models', array()) + ); foreach ($models as $name) { if (in_array($name, $ignore)) { diff --git a/tests/Console/ModelsCommand/Ignored/Models/Ignored.php b/tests/Console/ModelsCommand/Ignored/Models/Ignored.php new file mode 100644 index 0000000..df4c7d2 --- /dev/null +++ b/tests/Console/ModelsCommand/Ignored/Models/Ignored.php @@ -0,0 +1,10 @@ +set('ide-helper', [ + 'model_locations' => [ + // This is calculated from the base_path() which points to + // vendor/orchestra/testbench-core/laravel + '/../../../../tests/Console/ModelsCommand/Ignored/Models', + ], + 'ignored_models' => [ + Ignored::class + ] + ]); + } + + public function test(): void + { + $actualContent = null; + $mockFilesystem = Mockery::mock(Filesystem::class); + $mockFilesystem + ->shouldReceive('get') + ->andReturn(file_get_contents(__DIR__ . '/Models/Ignored.php')) + ->andReturn(file_get_contents(__DIR__ . '/Models/NotIgnored.php')) + ->once(); + $mockFilesystem + ->shouldReceive('put') + ->with( + Mockery::any(), + Mockery::capture($actualContent) + ) + ->andReturn(1) // Simulate we wrote _something_ to the file + ->once(); + + $this->instance(Filesystem::class, $mockFilesystem); + + $command = $this->app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertEmpty($tester->getDisplay()); + + $expectedContent = <<<'PHP' +assertSame($expectedContent, $actualContent); + } +}