diff --git a/src/Illuminate/Database/Eloquent/Factories/Factory.php b/src/Illuminate/Database/Eloquent/Factories/Factory.php index 1f2253b24e7f..8ac964225342 100644 --- a/src/Illuminate/Database/Eloquent/Factories/Factory.php +++ b/src/Illuminate/Database/Eloquent/Factories/Factory.php @@ -148,7 +148,7 @@ abstract public function definition(); /** * Get a new factory instance for the given attributes. * - * @param (callable(): array)|array $attributes + * @param (callable(array): array)|array $attributes * @return static */ public static function new($attributes = []) @@ -180,7 +180,7 @@ public function configure() /** * Get the raw attributes generated by the factory. * - * @param array $attributes + * @param (callable(array): array)|array $attributes * @param \Illuminate\Database\Eloquent\Model|null $parent * @return array */ @@ -198,7 +198,7 @@ public function raw($attributes = [], ?Model $parent = null) /** * Create a single model and persist it to the database. * - * @param array $attributes + * @param (callable(array): array)|array $attributes * @return \Illuminate\Database\Eloquent\Model|TModel */ public function createOne($attributes = []) @@ -209,7 +209,7 @@ public function createOne($attributes = []) /** * Create a single model and persist it to the database. * - * @param array $attributes + * @param (callable(array): array)|array $attributes * @return \Illuminate\Database\Eloquent\Model|TModel */ public function createOneQuietly($attributes = []) @@ -248,7 +248,7 @@ public function createManyQuietly(iterable $records) /** * Create a collection of models and persist them to the database. * - * @param array $attributes + * @param (callable(array): array)|array $attributes * @param \Illuminate\Database\Eloquent\Model|null $parent * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|TModel */ @@ -338,7 +338,7 @@ protected function createChildren(Model $model) /** * Make a single instance of the model. * - * @param (callable(): array)|array $attributes + * @param (callable(array): array)|array $attributes * @return \Illuminate\Database\Eloquent\Model|TModel */ public function makeOne($attributes = []) @@ -349,7 +349,7 @@ public function makeOne($attributes = []) /** * Create a collection of models. * - * @param array $attributes + * @param (callable(array): array)|array $attributes * @param \Illuminate\Database\Eloquent\Model|null $parent * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|TModel */ @@ -469,7 +469,7 @@ protected function expandAttributes(array $definition) /** * Add a new state transformation to the model definition. * - * @param (callable(): array)|array $state + * @param (callable(array): array)|array $state * @return static */ public function state($state) diff --git a/types/Database/Eloquent/Factories/Factory.php b/types/Database/Eloquent/Factories/Factory.php index a994f318686e..816b03815390 100644 --- a/types/Database/Eloquent/Factories/Factory.php +++ b/types/Database/Eloquent/Factories/Factory.php @@ -28,8 +28,12 @@ public function definition() } } -$factory = UserFactory::new(); -assertType('UserFactory', $factory); +assertType('UserFactory', $factory = UserFactory::new()); +assertType('UserFactory', UserFactory::new(['string' => 'string'])); +assertType('UserFactory', UserFactory::new(function ($attributes) { +// assertType('array', $attributes); + return ['string' => 'string']; +})); assertType('array', $factory->definition()); @@ -39,16 +43,28 @@ public function definition() assertType('array', $factory->raw()); assertType('array', $factory->raw(['string' => 'string'])); +assertType('array', $factory->raw(function ($attributes) { +// assert('array', $attributes); + return ['string' => 'string']; +})); // assertType('User', $factory->createOne()); // assertType('User', $factory->createOne(['string' => 'string'])); assertType('Illuminate\Database\Eloquent\Model', $factory->createOne()); assertType('Illuminate\Database\Eloquent\Model', $factory->createOne(['string' => 'string'])); +assertType('Illuminate\Database\Eloquent\Model', $factory->createOne(function ($attributes) { +// assertType('array', $attributes); + return ['string' => 'string']; +})); // assertType('User', $factory->createOneQuietly()); // assertType('User', $factory->createOneQuietly(['string' => 'string'])); assertType('Illuminate\Database\Eloquent\Model', $factory->createOneQuietly()); assertType('Illuminate\Database\Eloquent\Model', $factory->createOneQuietly(['string' => 'string'])); +assertType('Illuminate\Database\Eloquent\Model', $factory->createOneQuietly(function ($attributes) { +// assertType('array', $attributes); + return ['string' => 'string']; +})); // assertType('Illuminate\Database\Eloquent\Collection', $factory->createMany([['string' => 'string']])); assertType('Illuminate\Database\Eloquent\Collection', $factory->createMany( @@ -68,6 +84,10 @@ public function definition() assertType('Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model', $factory->create([ 'string' => 'string', ])); +assertType('Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model', $factory->create(function ($attributes) { +// assertType('array', $attributes); + return ['string' => 'string']; +})); // assertType('Illuminate\Database\Eloquent\Collection|User', $factory->createQuietly()); // assertType('Illuminate\Database\Eloquent\Collection|User', $factory->createQuietly([ @@ -95,6 +115,10 @@ public function definition() assertType('Illuminate\Database\Eloquent\Model', $factory->makeOne([ 'string' => 'string', ])); +assertType('Illuminate\Database\Eloquent\Model', $factory->makeOne(function ($attributes) { +// assert('array', $attributes); + return ['string' => 'string']; +})); // assertType('Illuminate\Database\Eloquent\Collection|User', $factory->make()); // assertType('Illuminate\Database\Eloquent\Collection|User', $factory->make([ @@ -104,6 +128,10 @@ public function definition() assertType('Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model', $factory->make([ 'string' => 'string', ])); +assertType('Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model', $factory->make(function ($attributes) { +// assert('array', $attributes); + return ['string' => 'string']; +})); assertType('UserFactory', $factory->state(['string' => 'string'])); assertType('UserFactory', $factory->state(function () {