Skip to content

AddHasFactoryToModelsRector doesn't check if factory exists #381

@hackel

Description

@hackel

After enabling the new LARAVEL_FACTORIES set, I had to revert 120 changed models in a project where the HasFactory trait was added when no factory class actually exists. I would argue that in its current state, AddHasFactoryToModelsRector doesn't belong in this set as it's not reasonable to assume every app has a factory for every single model in their application.

Ideally, the rector would check if the factory exists first prior to adding the HasFactory trait. It would be nice if it added the appropriate @use docblock referencing the factory class as well. I don't know if this is currently feasible, though.

Just my two cents. Skipping that rule is an easy enough solution as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions