diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ffdc4cb..6c753169e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. [Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.10.0...master) -------------- +### Fixed +- Fix recursively searching for `HasFactory` and `Macroable` traits [\#1216 / daniel-de-wit](https://github.com/barryvdh/laravel-ide-helper/pull/1216) 2021-04-09, 2.10.0 ------------------ diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 35c1419d8..12fe8b941 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1082,7 +1082,7 @@ protected function getReturnTypeFromReflection(\ReflectionMethod $reflection): ? */ protected function getSoftDeleteMethods($model) { - $traits = class_uses(get_class($model), true); + $traits = class_uses_recursive($model); if (in_array('Illuminate\\Database\\Eloquent\\SoftDeletes', $traits)) { $modelName = $this->getClassNameInDestinationFile($model, get_class($model)); $builder = $this->getClassNameInDestinationFile($model, \Illuminate\Database\Query\Builder::class); @@ -1105,7 +1105,8 @@ protected function getFactoryMethods($model) $modelName = get_class($model); - $traits = class_uses($modelName, true); + + $traits = class_uses_recursive($modelName); if (!in_array('Illuminate\\Database\\Eloquent\\Factories\\HasFactory', $traits)) { return; } diff --git a/src/Generator.php b/src/Generator.php index a5822006a..9f0438fde 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -296,7 +296,7 @@ protected function getMacroableClasses(Collection $aliases) return !$reflection->isInternal() && $reflection->getName() === $class; }) ->filter(function ($class) { - $traits = class_uses($class); + $traits = class_uses_recursive($class); // Filter only classes with the macroable trait return isset($traits[Macroable::class]); diff --git a/tests/Console/ModelsCommand/Factories/Factories/ModelWithNestedFactoryFactory.php b/tests/Console/ModelsCommand/Factories/Factories/ModelWithNestedFactoryFactory.php new file mode 100644 index 000000000..1362462b1 --- /dev/null +++ b/tests/Console/ModelsCommand/Factories/Factories/ModelWithNestedFactoryFactory.php @@ -0,0 +1,30 @@ +