mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
feat(ModelsCommand): add configuration option to disable model query methods (#1692)
* feat(ModelsCommand): add configuration option to disable model query methods * composer fix-style * update comment * revert whitespace changes * composer fix-style * composer fix-style --------- Co-authored-by: laravel-ide-helper <[email protected]>
This commit is contained in:
co-authored by
laravel-ide-helper
parent
3bd70eafd0
commit
fd3cfbe09d
@@ -47,6 +47,17 @@ return [
|
||||
|
||||
'include_fluent' => 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
|
||||
|
||||
@@ -720,13 +720,16 @@ class ModelsCommand extends Command
|
||||
);
|
||||
$this->setMethod($name, $builder . '<static>|' . $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 . '<static>|' . $this->getClassNameInDestinationFile($model, get_class($model))
|
||||
);
|
||||
$this->setMethod(
|
||||
$method,
|
||||
$builder . '<static>|' . $this->getClassNameInDestinationFile($model, get_class($model))
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->write_model_external_builder_methods) {
|
||||
$this->writeModelExternalBuilderMethods($model);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryMethods\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryMethods;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||
|
||||
class Test extends AbstractModelsCommand
|
||||
{
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
parent::getEnvironmentSetUp($app);
|
||||
|
||||
$app['config']->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<static>|Post query()", $this->mockFilesystemOutput);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryMethods\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $char_nullable
|
||||
* @property string $char_not_nullable
|
||||
* @property string|null $string_nullable
|
||||
* @property string $string_not_nullable
|
||||
* @property string|null $text_nullable
|
||||
* @property string $text_not_nullable
|
||||
* @property string|null $medium_text_nullable
|
||||
* @property string $medium_text_not_nullable
|
||||
* @property string|null $long_text_nullable
|
||||
* @property string $long_text_not_nullable
|
||||
* @property int|null $integer_nullable
|
||||
* @property int $integer_not_nullable
|
||||
* @property int|null $tiny_integer_nullable
|
||||
* @property int $tiny_integer_not_nullable
|
||||
* @property int|null $small_integer_nullable
|
||||
* @property int $small_integer_not_nullable
|
||||
* @property int|null $medium_integer_nullable
|
||||
* @property int $medium_integer_not_nullable
|
||||
* @property int|null $big_integer_nullable
|
||||
* @property int $big_integer_not_nullable
|
||||
* @property int|null $unsigned_integer_nullable
|
||||
* @property int $unsigned_integer_not_nullable
|
||||
* @property int|null $unsigned_tiny_integer_nullable
|
||||
* @property int $unsigned_tiny_integer_not_nullable
|
||||
* @property int|null $unsigned_small_integer_nullable
|
||||
* @property int $unsigned_small_integer_not_nullable
|
||||
* @property int|null $unsigned_medium_integer_nullable
|
||||
* @property int $unsigned_medium_integer_not_nullable
|
||||
* @property int|null $unsigned_big_integer_nullable
|
||||
* @property int $unsigned_big_integer_not_nullable
|
||||
* @property float|null $float_nullable
|
||||
* @property float $float_not_nullable
|
||||
* @property float|null $double_nullable
|
||||
* @property float $double_not_nullable
|
||||
* @property string|null $decimal_nullable
|
||||
* @property string $decimal_not_nullable
|
||||
* @property int|null $boolean_nullable
|
||||
* @property int $boolean_not_nullable
|
||||
* @property string|null $enum_nullable
|
||||
* @property string $enum_not_nullable
|
||||
* @property string|null $json_nullable
|
||||
* @property string $json_not_nullable
|
||||
* @property string|null $jsonb_nullable
|
||||
* @property string $jsonb_not_nullable
|
||||
* @property string|null $date_nullable
|
||||
* @property string $date_not_nullable
|
||||
* @property string|null $datetime_nullable
|
||||
* @property string $datetime_not_nullable
|
||||
* @property string|null $datetimetz_nullable
|
||||
* @property string $datetimetz_not_nullable
|
||||
* @property string|null $time_nullable
|
||||
* @property string $time_not_nullable
|
||||
* @property string|null $timetz_nullable
|
||||
* @property string $timetz_not_nullable
|
||||
* @property string|null $timestamp_nullable
|
||||
* @property string $timestamp_not_nullable
|
||||
* @property string|null $timestamptz_nullable
|
||||
* @property string $timestamptz_not_nullable
|
||||
* @property int|null $year_nullable
|
||||
* @property int $year_not_nullable
|
||||
* @property string|null $binary_nullable
|
||||
* @property string $binary_not_nullable
|
||||
* @property string|null $uuid_nullable
|
||||
* @property string $uuid_not_nullable
|
||||
* @property string|null $ipaddress_nullable
|
||||
* @property string $ipaddress_not_nullable
|
||||
* @property string|null $macaddress_nullable
|
||||
* @property string $macaddress_not_nullable
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBigIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBigIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBinaryNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBinaryNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBooleanNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBooleanNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereCharNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereCharNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDateNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDateNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDatetimeNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDatetimeNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDatetimetzNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDatetimetzNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDecimalNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDecimalNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDoubleNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDoubleNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereEnumNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereEnumNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereFloatNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereFloatNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereIpaddressNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereIpaddressNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereJsonNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereJsonNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereJsonbNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereJsonbNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereLongTextNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereLongTextNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMacaddressNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMacaddressNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMediumIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMediumIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMediumTextNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMediumTextNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereSmallIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereSmallIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereStringNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereStringNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTextNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTextNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimeNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimeNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimestampNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimestampNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimestamptzNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimestamptzNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimetzNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimetzNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTinyIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTinyIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedBigIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedBigIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedMediumIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedMediumIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedSmallIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedSmallIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedTinyIntegerNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedTinyIntegerNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUuidNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUuidNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereYearNotNullable($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereYearNullable($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Post extends Model
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user