Skip to content

Commit 317e773

Browse files
committed
feat(ModelsCommand): add configuration option to disable model query methods
1 parent d567978 commit 317e773

File tree

5 files changed

+223
-6
lines changed

5 files changed

+223
-6
lines changed

config/ide-helper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@
6161

6262
'include_factory_builders' => false,
6363

64+
/*
65+
|--------------------------------------------------------------------------
66+
| Write model query methods
67+
|--------------------------------------------------------------------------
68+
|
69+
| Set to false to disable the 'query()', 'newQuery()' and 'newModelQuery()' methods.
70+
|
71+
*/
72+
73+
'write_query_methods' => true,
74+
6475
/*
6576
|--------------------------------------------------------------------------
6677
| Write model magic methods

src/Console/ModelsCommand.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,13 +687,17 @@ public function getPropertiesFromMethods($model)
687687
);
688688
$this->setMethod($name, $builder . '<static>|' . $modelName, $args, $comment);
689689
}
690-
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) {
691-
$builder = $this->getClassNameInDestinationFile($model, get_class($model->newModelQuery()));
690+
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])
691+
) {
692+
if($this->laravel['config']->get('ide-helper.write_query_methods', true)){
692693

693-
$this->setMethod(
694-
$method,
695-
$builder . '<static>|' . $this->getClassNameInDestinationFile($model, get_class($model))
696-
);
694+
$builder = $this->getClassNameInDestinationFile($model, get_class($model->newModelQuery()));
695+
696+
$this->setMethod(
697+
$method,
698+
$builder . '<static>|' . $this->getClassNameInDestinationFile($model, get_class($model))
699+
);
700+
}
697701

698702
if ($this->write_model_external_builder_methods) {
699703
$this->writeModelExternalBuilderMethods($model);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryMethods\Models;
6+
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
class Post extends Model
10+
{
11+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryMethods;
6+
7+
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
8+
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
9+
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryMethods\Models\Post;
10+
11+
class Test extends AbstractModelsCommand
12+
{
13+
protected function getEnvironmentSetUp($app)
14+
{
15+
parent::getEnvironmentSetUp($app);
16+
17+
$app['config']->set('ide-helper.write_query_methods', false);
18+
}
19+
20+
public function test(): void
21+
{
22+
$command = $this->app->make(ModelsCommand::class);
23+
24+
$tester = $this->runCommand($command, [
25+
'--write' => true,
26+
]);
27+
28+
$this->assertSame(0, $tester->getStatusCode());
29+
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
30+
$this->assertMatchesMockedSnapshot();
31+
$this->assertStringNotContainsString("@method static \Illuminate\Database\Eloquent\Builder<static>|Post query()", $this->mockFilesystemOutput);
32+
}
33+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryMethods\Models;
6+
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
/**
10+
*
11+
*
12+
* @property int $id
13+
* @property string|null $char_nullable
14+
* @property string $char_not_nullable
15+
* @property string|null $string_nullable
16+
* @property string $string_not_nullable
17+
* @property string|null $text_nullable
18+
* @property string $text_not_nullable
19+
* @property string|null $medium_text_nullable
20+
* @property string $medium_text_not_nullable
21+
* @property string|null $long_text_nullable
22+
* @property string $long_text_not_nullable
23+
* @property int|null $integer_nullable
24+
* @property int $integer_not_nullable
25+
* @property int|null $tiny_integer_nullable
26+
* @property int $tiny_integer_not_nullable
27+
* @property int|null $small_integer_nullable
28+
* @property int $small_integer_not_nullable
29+
* @property int|null $medium_integer_nullable
30+
* @property int $medium_integer_not_nullable
31+
* @property int|null $big_integer_nullable
32+
* @property int $big_integer_not_nullable
33+
* @property int|null $unsigned_integer_nullable
34+
* @property int $unsigned_integer_not_nullable
35+
* @property int|null $unsigned_tiny_integer_nullable
36+
* @property int $unsigned_tiny_integer_not_nullable
37+
* @property int|null $unsigned_small_integer_nullable
38+
* @property int $unsigned_small_integer_not_nullable
39+
* @property int|null $unsigned_medium_integer_nullable
40+
* @property int $unsigned_medium_integer_not_nullable
41+
* @property int|null $unsigned_big_integer_nullable
42+
* @property int $unsigned_big_integer_not_nullable
43+
* @property float|null $float_nullable
44+
* @property float $float_not_nullable
45+
* @property float|null $double_nullable
46+
* @property float $double_not_nullable
47+
* @property string|null $decimal_nullable
48+
* @property string $decimal_not_nullable
49+
* @property int|null $boolean_nullable
50+
* @property int $boolean_not_nullable
51+
* @property string|null $enum_nullable
52+
* @property string $enum_not_nullable
53+
* @property string|null $json_nullable
54+
* @property string $json_not_nullable
55+
* @property string|null $jsonb_nullable
56+
* @property string $jsonb_not_nullable
57+
* @property string|null $date_nullable
58+
* @property string $date_not_nullable
59+
* @property string|null $datetime_nullable
60+
* @property string $datetime_not_nullable
61+
* @property string|null $datetimetz_nullable
62+
* @property string $datetimetz_not_nullable
63+
* @property string|null $time_nullable
64+
* @property string $time_not_nullable
65+
* @property string|null $timetz_nullable
66+
* @property string $timetz_not_nullable
67+
* @property string|null $timestamp_nullable
68+
* @property string $timestamp_not_nullable
69+
* @property string|null $timestamptz_nullable
70+
* @property string $timestamptz_not_nullable
71+
* @property int|null $year_nullable
72+
* @property int $year_not_nullable
73+
* @property string|null $binary_nullable
74+
* @property string $binary_not_nullable
75+
* @property string|null $uuid_nullable
76+
* @property string $uuid_not_nullable
77+
* @property string|null $ipaddress_nullable
78+
* @property string $ipaddress_not_nullable
79+
* @property string|null $macaddress_nullable
80+
* @property string $macaddress_not_nullable
81+
* @property \Illuminate\Support\Carbon|null $created_at
82+
* @property \Illuminate\Support\Carbon|null $updated_at
83+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBigIntegerNotNullable($value)
84+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBigIntegerNullable($value)
85+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBinaryNotNullable($value)
86+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBinaryNullable($value)
87+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBooleanNotNullable($value)
88+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereBooleanNullable($value)
89+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereCharNotNullable($value)
90+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereCharNullable($value)
91+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereCreatedAt($value)
92+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDateNotNullable($value)
93+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDateNullable($value)
94+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDatetimeNotNullable($value)
95+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDatetimeNullable($value)
96+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDatetimetzNotNullable($value)
97+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDatetimetzNullable($value)
98+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDecimalNotNullable($value)
99+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDecimalNullable($value)
100+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDoubleNotNullable($value)
101+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereDoubleNullable($value)
102+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereEnumNotNullable($value)
103+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereEnumNullable($value)
104+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereFloatNotNullable($value)
105+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereFloatNullable($value)
106+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereId($value)
107+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereIntegerNotNullable($value)
108+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereIntegerNullable($value)
109+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereIpaddressNotNullable($value)
110+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereIpaddressNullable($value)
111+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereJsonNotNullable($value)
112+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereJsonNullable($value)
113+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereJsonbNotNullable($value)
114+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereJsonbNullable($value)
115+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereLongTextNotNullable($value)
116+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereLongTextNullable($value)
117+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMacaddressNotNullable($value)
118+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMacaddressNullable($value)
119+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMediumIntegerNotNullable($value)
120+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMediumIntegerNullable($value)
121+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMediumTextNotNullable($value)
122+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereMediumTextNullable($value)
123+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereSmallIntegerNotNullable($value)
124+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereSmallIntegerNullable($value)
125+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereStringNotNullable($value)
126+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereStringNullable($value)
127+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTextNotNullable($value)
128+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTextNullable($value)
129+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimeNotNullable($value)
130+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimeNullable($value)
131+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimestampNotNullable($value)
132+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimestampNullable($value)
133+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimestamptzNotNullable($value)
134+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimestamptzNullable($value)
135+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimetzNotNullable($value)
136+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTimetzNullable($value)
137+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTinyIntegerNotNullable($value)
138+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereTinyIntegerNullable($value)
139+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedBigIntegerNotNullable($value)
140+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedBigIntegerNullable($value)
141+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedIntegerNotNullable($value)
142+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedIntegerNullable($value)
143+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedMediumIntegerNotNullable($value)
144+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedMediumIntegerNullable($value)
145+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedSmallIntegerNotNullable($value)
146+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedSmallIntegerNullable($value)
147+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedTinyIntegerNotNullable($value)
148+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUnsignedTinyIntegerNullable($value)
149+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUpdatedAt($value)
150+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUuidNotNullable($value)
151+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereUuidNullable($value)
152+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereYearNotNullable($value)
153+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post whereYearNullable($value)
154+
* @mixin \Eloquent
155+
*/
156+
class Post extends Model
157+
{
158+
}

0 commit comments

Comments
 (0)