Skip to content

Commit 6338abb

Browse files
authored
Fix return value of scopes from parent class (#1366)
1 parent ac7e186 commit 6338abb

File tree

6 files changed

+245
-3
lines changed

6 files changed

+245
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66
--------------
77

88
### Fixed
9+
- Fix return value of query scopes from parent class [#1366 / sforward](https://github.com/barryvdh/laravel-ide-helper/pull/1366)
910

1011
### Changed
1112

src/Console/ModelsCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ public function getPropertiesFromMethods($model)
616616
$this->setProperty($name, null, null, true, $comment);
617617
}
618618
} elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery' && $method !== 'scope' && $method !== 'scopes') {
619-
//Magic set<name>Attribute
619+
//Magic scope<name>Attribute
620620
$name = Str::camel(substr($method, 5));
621621
if (!empty($name)) {
622622
$comment = $this->getCommentFromDocBlock($reflection);
@@ -628,8 +628,8 @@ public function getPropertiesFromMethods($model)
628628
get_class($model->newModelQuery())
629629
);
630630
$modelName = $this->getClassNameInDestinationFile(
631-
$reflection->getDeclaringClass(),
632-
$reflection->getDeclaringClass()->getName()
631+
new \ReflectionClass($model),
632+
get_class($model)
633633
);
634634
$this->setMethod($name, $builder . '|' . $modelName, $args, $comment);
635635
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes\Models;
6+
7+
class Post extends PostParent
8+
{
9+
public function scopePublic($query)
10+
{
11+
return $query;
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes\Models;
6+
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
class PostParent extends Model
10+
{
11+
public function scopeActive($query)
12+
{
13+
return $query;
14+
}
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes;
6+
7+
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
8+
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
9+
10+
class Test extends AbstractModelsCommand
11+
{
12+
public function test(): void
13+
{
14+
$command = $this->app->make(ModelsCommand::class);
15+
16+
$tester = $this->runCommand($command, [
17+
'--write' => true,
18+
]);
19+
20+
$this->assertSame(0, $tester->getStatusCode());
21+
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
22+
$this->assertMatchesMockedSnapshot();
23+
}
24+
}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes\Models;
6+
7+
/**
8+
*
9+
*
10+
* @property int $id
11+
* @property string|null $char_nullable
12+
* @property string $char_not_nullable
13+
* @property string|null $string_nullable
14+
* @property string $string_not_nullable
15+
* @property string|null $text_nullable
16+
* @property string $text_not_nullable
17+
* @property string|null $medium_text_nullable
18+
* @property string $medium_text_not_nullable
19+
* @property string|null $long_text_nullable
20+
* @property string $long_text_not_nullable
21+
* @property int|null $integer_nullable
22+
* @property int $integer_not_nullable
23+
* @property int|null $tiny_integer_nullable
24+
* @property int $tiny_integer_not_nullable
25+
* @property int|null $small_integer_nullable
26+
* @property int $small_integer_not_nullable
27+
* @property int|null $medium_integer_nullable
28+
* @property int $medium_integer_not_nullable
29+
* @property int|null $big_integer_nullable
30+
* @property int $big_integer_not_nullable
31+
* @property int|null $unsigned_integer_nullable
32+
* @property int $unsigned_integer_not_nullable
33+
* @property int|null $unsigned_tiny_integer_nullable
34+
* @property int $unsigned_tiny_integer_not_nullable
35+
* @property int|null $unsigned_small_integer_nullable
36+
* @property int $unsigned_small_integer_not_nullable
37+
* @property int|null $unsigned_medium_integer_nullable
38+
* @property int $unsigned_medium_integer_not_nullable
39+
* @property int|null $unsigned_big_integer_nullable
40+
* @property int $unsigned_big_integer_not_nullable
41+
* @property float|null $float_nullable
42+
* @property float $float_not_nullable
43+
* @property float|null $double_nullable
44+
* @property float $double_not_nullable
45+
* @property string|null $decimal_nullable
46+
* @property string $decimal_not_nullable
47+
* @property int|null $boolean_nullable
48+
* @property int $boolean_not_nullable
49+
* @property string|null $enum_nullable
50+
* @property string $enum_not_nullable
51+
* @property string|null $json_nullable
52+
* @property string $json_not_nullable
53+
* @property string|null $jsonb_nullable
54+
* @property string $jsonb_not_nullable
55+
* @property string|null $date_nullable
56+
* @property string $date_not_nullable
57+
* @property string|null $datetime_nullable
58+
* @property string $datetime_not_nullable
59+
* @property string|null $datetimetz_nullable
60+
* @property string $datetimetz_not_nullable
61+
* @property string|null $time_nullable
62+
* @property string $time_not_nullable
63+
* @property string|null $timetz_nullable
64+
* @property string $timetz_not_nullable
65+
* @property string|null $timestamp_nullable
66+
* @property string $timestamp_not_nullable
67+
* @property string|null $timestamptz_nullable
68+
* @property string $timestamptz_not_nullable
69+
* @property int|null $year_nullable
70+
* @property int $year_not_nullable
71+
* @property string|null $binary_nullable
72+
* @property string $binary_not_nullable
73+
* @property string|null $uuid_nullable
74+
* @property string $uuid_not_nullable
75+
* @property string|null $ipaddress_nullable
76+
* @property string $ipaddress_not_nullable
77+
* @property string|null $macaddress_nullable
78+
* @property string $macaddress_not_nullable
79+
* @property \Illuminate\Support\Carbon|null $created_at
80+
* @property \Illuminate\Support\Carbon|null $updated_at
81+
* @method static \Illuminate\Database\Eloquent\Builder|Post active()
82+
* @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery()
83+
* @method static \Illuminate\Database\Eloquent\Builder|Post newQuery()
84+
* @method static \Illuminate\Database\Eloquent\Builder|Post public()
85+
* @method static \Illuminate\Database\Eloquent\Builder|Post query()
86+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNotNullable($value)
87+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value)
88+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBinaryNotNullable($value)
89+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBinaryNullable($value)
90+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBooleanNotNullable($value)
91+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBooleanNullable($value)
92+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCharNotNullable($value)
93+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCharNullable($value)
94+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCreatedAt($value)
95+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDateNotNullable($value)
96+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDateNullable($value)
97+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimeNotNullable($value)
98+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimeNullable($value)
99+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimetzNotNullable($value)
100+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimetzNullable($value)
101+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDecimalNotNullable($value)
102+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDecimalNullable($value)
103+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDoubleNotNullable($value)
104+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDoubleNullable($value)
105+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereEnumNotNullable($value)
106+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereEnumNullable($value)
107+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereFloatNotNullable($value)
108+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereFloatNullable($value)
109+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereId($value)
110+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIntegerNotNullable($value)
111+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIntegerNullable($value)
112+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIpaddressNotNullable($value)
113+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIpaddressNullable($value)
114+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonNotNullable($value)
115+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonNullable($value)
116+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonbNotNullable($value)
117+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonbNullable($value)
118+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereLongTextNotNullable($value)
119+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereLongTextNullable($value)
120+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMacaddressNotNullable($value)
121+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMacaddressNullable($value)
122+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumIntegerNotNullable($value)
123+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumIntegerNullable($value)
124+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumTextNotNullable($value)
125+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumTextNullable($value)
126+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereSmallIntegerNotNullable($value)
127+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereSmallIntegerNullable($value)
128+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereStringNotNullable($value)
129+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereStringNullable($value)
130+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTextNotNullable($value)
131+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTextNullable($value)
132+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimeNotNullable($value)
133+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimeNullable($value)
134+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestampNotNullable($value)
135+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestampNullable($value)
136+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestamptzNotNullable($value)
137+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestamptzNullable($value)
138+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimetzNotNullable($value)
139+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimetzNullable($value)
140+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNotNullable($value)
141+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNullable($value)
142+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNotNullable($value)
143+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNullable($value)
144+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNotNullable($value)
145+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNullable($value)
146+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNotNullable($value)
147+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNullable($value)
148+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedSmallIntegerNotNullable($value)
149+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedSmallIntegerNullable($value)
150+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedTinyIntegerNotNullable($value)
151+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedTinyIntegerNullable($value)
152+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUpdatedAt($value)
153+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNotNullable($value)
154+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value)
155+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value)
156+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
157+
* @mixin \Eloquent
158+
*/
159+
class Post extends PostParent
160+
{
161+
public function scopePublic($query)
162+
{
163+
return $query;
164+
}
165+
}
166+
<?php
167+
168+
declare(strict_types=1);
169+
170+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes\Models;
171+
172+
use Illuminate\Database\Eloquent\Model;
173+
174+
/**
175+
*
176+
*
177+
* @method static \Illuminate\Database\Eloquent\Builder|PostParent active()
178+
* @method static \Illuminate\Database\Eloquent\Builder|PostParent newModelQuery()
179+
* @method static \Illuminate\Database\Eloquent\Builder|PostParent newQuery()
180+
* @method static \Illuminate\Database\Eloquent\Builder|PostParent query()
181+
* @mixin \Eloquent
182+
*/
183+
class PostParent extends Model
184+
{
185+
public function scopeActive($query)
186+
{
187+
return $query;
188+
}
189+
}

0 commit comments

Comments
 (0)