File tree Expand file tree Collapse file tree 6 files changed +63
-3
lines changed
tests/Console/ModelsCommand/Factories Expand file tree Collapse file tree 6 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
4
4
5
5
[ Next release] ( https://github.com/barryvdh/laravel-ide-helper/compare/v2.10.0...master )
6
6
--------------
7
+ ### Fixed
8
+ - Fix recursively searching for ` HasFactory ` and ` Macroable ` traits [ \# 1216 / daniel-de-wit] ( https://github.com/barryvdh/laravel-ide-helper/pull/1216 )
7
9
8
10
2021-04-09, 2.10.0
9
11
------------------
Original file line number Diff line number Diff line change @@ -1082,7 +1082,7 @@ protected function getReturnTypeFromReflection(\ReflectionMethod $reflection): ?
1082
1082
*/
1083
1083
protected function getSoftDeleteMethods ($ model )
1084
1084
{
1085
- $ traits = class_uses ( get_class ( $ model), true );
1085
+ $ traits = class_uses_recursive ( $ model );
1086
1086
if (in_array ('Illuminate \\Database \\Eloquent \\SoftDeletes ' , $ traits )) {
1087
1087
$ modelName = $ this ->getClassNameInDestinationFile ($ model , get_class ($ model ));
1088
1088
$ builder = $ this ->getClassNameInDestinationFile ($ model , \Illuminate \Database \Query \Builder::class);
@@ -1105,7 +1105,8 @@ protected function getFactoryMethods($model)
1105
1105
1106
1106
$ modelName = get_class ($ model );
1107
1107
1108
- $ traits = class_uses ($ modelName , true );
1108
+
1109
+ $ traits = class_uses_recursive ($ modelName );
1109
1110
if (!in_array ('Illuminate \\Database \\Eloquent \\Factories \\HasFactory ' , $ traits )) {
1110
1111
return ;
1111
1112
}
Original file line number Diff line number Diff line change @@ -296,7 +296,7 @@ protected function getMacroableClasses(Collection $aliases)
296
296
return !$ reflection ->isInternal () && $ reflection ->getName () === $ class ;
297
297
})
298
298
->filter (function ($ class ) {
299
- $ traits = class_uses ($ class );
299
+ $ traits = class_uses_recursive ($ class );
300
300
301
301
// Filter only classes with the macroable trait
302
302
return isset ($ traits [Macroable::class]);
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Factories \Factories ;
6
+
7
+ use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Factories \Models \ModelWithNestedFactory ;
8
+ use Illuminate \Database \Eloquent \Factories \Factory ;
9
+
10
+ class ModelWithNestedFactoryFactory extends Factory
11
+ {
12
+ /**
13
+ * The name of the factory's corresponding model.
14
+ *
15
+ * @var string
16
+ */
17
+ protected $ model = ModelWithNestedFactory::class;
18
+
19
+ /**
20
+ * Define the model's default state.
21
+ *
22
+ * @return array
23
+ */
24
+ public function definition ()
25
+ {
26
+ return [
27
+ //
28
+ ];
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Factories \Models ;
6
+
7
+ class ModelWithNestedFactory extends ModelWithFactory
8
+ {
9
+ }
Original file line number Diff line number Diff line change @@ -59,6 +59,24 @@ class ModelWithFactory extends Model
59
59
60
60
namespace Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Factories \Models ;
61
61
62
+ /**
63
+ * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithNestedFactory
64
+ *
65
+ * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithNestedFactoryFactory factory(...$parameters)
66
+ * @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newModelQuery()
67
+ * @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newQuery()
68
+ * @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory query()
69
+ * @mixin \Eloquent
70
+ */
71
+ class ModelWithNestedFactory extends ModelWithFactory
72
+ {
73
+ }
74
+ <?php
75
+
76
+ declare (strict_types=1 );
77
+
78
+ namespace Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Factories \Models ;
79
+
62
80
use Illuminate \Database \Eloquent \Factories \HasFactory ;
63
81
use Illuminate \Database \Eloquent \Model ;
64
82
You can’t perform that action at this time.
0 commit comments