diff --git a/config/ide-helper.php b/config/ide-helper.php index 1500783aa..2ad711032 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -61,6 +61,17 @@ 'include_factory_builders' => false, + /* + |-------------------------------------------------------------------------- + | Write model query methods + |-------------------------------------------------------------------------- + | + | Set to false to disable generated docs for the 'query()', 'newQuery()' and 'newModelQuery()' methods. + | + */ + + 'write_query_methods' => true, + /* |-------------------------------------------------------------------------- | Write model magic methods diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index aa389ec9a..fcdf05615 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -689,13 +689,16 @@ public function getPropertiesFromMethods($model) ); $this->setMethod($name, $builder . '|' . $modelName, $args, $comment); } - } elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) { - $builder = $this->getClassNameInDestinationFile($model, get_class($model->newModelQuery())); + } elseif (in_array($method, ['query', 'newQuery', 'newModelQuery']) + ) { + if ($this->laravel['config']->get('ide-helper.write_query_methods', true)) { + $builder = $this->getClassNameInDestinationFile($model, get_class($model->newModelQuery())); - $this->setMethod( - $method, - $builder . '|' . $this->getClassNameInDestinationFile($model, get_class($model)) - ); + $this->setMethod( + $method, + $builder . '|' . $this->getClassNameInDestinationFile($model, get_class($model)) + ); + } if ($this->write_model_external_builder_methods) { $this->writeModelExternalBuilderMethods($model); diff --git a/tests/Console/ModelsCommand/QueryMethods/Models/Post.php b/tests/Console/ModelsCommand/QueryMethods/Models/Post.php new file mode 100644 index 000000000..918f77e41 --- /dev/null +++ b/tests/Console/ModelsCommand/QueryMethods/Models/Post.php @@ -0,0 +1,11 @@ +set('ide-helper.write_query_methods', false); + } + + 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(); + $this->assertStringNotContainsString("@method static \Illuminate\Database\Eloquent\Builder|Post query()", $this->mockFilesystemOutput); + } +} diff --git a/tests/Console/ModelsCommand/QueryMethods/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/QueryMethods/__snapshots__/Test__test__1.php new file mode 100644 index 000000000..5a059be50 --- /dev/null +++ b/tests/Console/ModelsCommand/QueryMethods/__snapshots__/Test__test__1.php @@ -0,0 +1,158 @@ +|Post whereBigIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereBinaryNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereBinaryNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereBooleanNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereBooleanNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereCharNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereCharNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDateNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDateNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimeNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimeNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimetzNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimetzNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDecimalNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDecimalNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDoubleNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereDoubleNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereEnumNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereEnumNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereFloatNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereFloatNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereIpaddressNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereIpaddressNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonbNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonbNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereLongTextNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereLongTextNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereMacaddressNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereMacaddressNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumTextNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumTextNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereSmallIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereSmallIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereStringNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereStringNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTextNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTextNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTimeNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTimeNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestampNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestampNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestamptzNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestamptzNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTimetzNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTimetzNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedSmallIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedSmallIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedTinyIntegerNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedTinyIntegerNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value) + * @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value) + * @mixin \Eloquent + */ +class Post extends Model +{ +}