-
Notifications
You must be signed in to change notification settings - Fork 90
Add rule to add HasFactory to Models #353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9e9e508 to
09ebd2d
Compare
f56970d to
b54dc0a
Compare
The set is not really complete without it. It'll work if you use the factory directly, but the other rectors convert to use the static method which this rector fixes
|
Sorry @jradtilbrook things have been a bit busy lately. It looks overall good, I need to consider adding to the rule group and just the structure of the tests |
|
@jradtilbrook would you be able to refactor your branch to structure your tests like you did in the other branch? #351 |
|
👍 I'll try get onto that tonight |
|
@peterfox ready to go now |
|
Does it make sense to add HasFactory to all Models automatically / by default with the laravel-legacy-factories-to-classes set? I still want to convert legacy factories to classes, but now all my models received a hasFactory trait, even those which do not a have factory at all. |
|
Hmm good question 👍 In my opinion, I think it does when used as part of the set. Since the set contains However, as it allows for configuration, if that does not work for you, you can use each part of the set separately and configure the allowlist of models on which it runs. |
|
Upon second thought, I agree that keeping this rule out of the Legacy Factories set makes more sense. I'm not sure that it's easy to configure a rule when it's part of a set. You either have to use it without configuration, or not use the set at all, and get the rules one by one. Either way, it's not a great experience. We might have 'broken' the set with the last release 😓 Given we have other rules coming in for the Factories, we'll probably exclude this HasFactory rule from the legacy migration set, and include it in a new one, just for Factories. |
This adds a new rule that adds the
HasFactorytrait to Eloquent models if not present. Useful as part of the other factory related rules to upgrade pre-v8.0 code.I think might be worth including this in the set and updating some docs - let me know 👍