`make:factory` enhancements
- [x] auto-detect phpstan and add specific
@phpstan-method(not needed for psalm) https://github.com/zenstruck/foundry/pull/338 - [x] availability to create factory for object not related to doctrine https://github.com/zenstruck/foundry/pull/343
- [x] Use field limit length when specified #286 #294
- [x] support default property for mongoDB #238 https://github.com/zenstruck/foundry/pull/340
- [x] auto defaults for non-nullable 1-1/n-1 relationships #175 https://github.com/zenstruck/foundry/pull/221
- [x] Foundry generates the factory with $faker->text() if its a string, i think $faker->sentence() oder $faker->word() would fit better. If doctrine type Text, I would recommend to use $faker->text()
- [x] sort the default values alphanumeric
- [x] indent the phpdoc properly (see below)
- [x] Move the generated comments to @see annotations above the methods. (see below)
- [x] Import non-nullable relationship factories (https://github.com/zenstruck/foundry/pull/351#discussion_r1029584697)
- [x] auto-complete FQCN's
bin/console make:entity User<tab>(auto-complete classes that start withUser) https://github.com/zenstruck/foundry/pull/383 - [x] handle enums default https://github.com/zenstruck/foundry/pull/393
- [x] list embeddables in
make:factory~- [ ] add docs on--no-persistencebehavior~ won'tdo - [x] handle when factory with same name already exists https://github.com/zenstruck/foundry/pull/402
- [x] match directory/namespace structure https://github.com/zenstruck/foundry/issues/401 https://github.com/zenstruck/foundry/pull/411
- [x] add a bundle's configuration for base namespace where to create factories
Some more complex features that would be very nice to add:
- [x] based on
auto defaults for non-nullable: if the factory is missing, we could also create the missing factory - [x] handle previous feature with
--all~- [ ] "update" factories~ this one is really tricky, and not sure people will actually use it.... - [ ] add an option to
make:entity:--with-factory
Some additional suggestions by @OskarStark:
-
Foundry generates the factory with $faker->text() if its a string, i think $faker->sentence() oder $faker->word() would fit better. If doctrine type Text, I would recommend to use $faker->text()
-
Another proposal would be to sort the default values alphanumeric
-
And we should indent the phpdoc properly
(php-cs-fixer adjusts these
-
Move the generated comments to
@seeannotations above the methods.
Import non-nullable relationship factories
This is complete, correct?
This is complete, correct?
I'd say it's almost complete, I'd like to display a message when a factory does not exists...
but that message will be removed when we'll implement if the factory is missing, we could also create the missing factory
auto-detect phpstan and add specific @phpstan-method (not needed for psalm)
Are you sure this is not needed for Psalm?
The default @method annotations that make:factory generates are technically wrong (as of foundry 1.36). They do help IDEs with providing autocomplete, but they can't be used for statical analyses (or lead to false positives).
I could only use foundry with Psalm by either removing all the @method annotations, or adding psalm-specific ones.
hi!
no, this was a false statement! Since then we've added the @psalm-method phpdocs
https://github.com/zenstruck/foundry/blob/1.x/tests/Fixtures/Maker/expected/can_create_factory_for_entity_with_repository_with_data_set_psalm.php#L40-L53
Psalm/PHPStan detection is pretty weak here: it could fail if the default config file does not exists https://github.com/zenstruck/foundry/blob/1.x/src/Bundle/Maker/Factory/FactoryGenerator.php#L144-L151
@nikophil Nice, thanks a lot! It seems like it was indeed my unusal Psalm setup that prevented the auto detection. :)