-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[5.0] Automatically Resolve Migrations Dependencies #6784
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
@antonioribeiro I think @taylorotwell actually put the spaces there on purpose. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taylor normally aliases contracts when he imports them.
use Illuminate\Contracts\Container\Container as ContainerContract;
On Filesystem but not on Resolver? |
Don't know. I've never understood why spaces are sometimes ok. |
Alignment, 1-3 spaces may be needed if you want things straight. In this case there was too much, but let's see what he says about this :) |
He uses spaces to align his parameters neatly underneath eachother. Tabs are used for code indenting. You should use spaces starting from |
This is the original code and it makes no sense to me: Even if he chooses to use tabs here and spaces there, the snippet is using both. So you can just use tabs to align in this case. |
@antonioribeiro I believe it should be like this (tabs for indentation, spaces for alignment): public function __construct(MigrationRepositoryInterface $repository,
ContainerInterface $container,
Resolver $resolver,
Filesystem $files)
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you alias this ContainerInterface
as there is no conflict with another class named Container
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're meant to use ContainerContract
anyway. That's Taylor's standard. Why did you change it to interface?
1474a2c
to
557abc9
Compare
@hannesvdvreken, because @GrahamCampbell:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be aligned with spaces.
Ping @antonioribeiro. Please fix the inline issues. |
02cece7
to
907dec6
Compare
@GrahamCampbell, sorry but your comments confused me. You were talking about indentation and the difference was in the two spaces in docblocs. I also replaced those identation tabs with spaces. All changes were amended, please take a look and tell me if there is still something missing. |
Looks good now. Thanks. :) |
Actually, no, it's not. You've accepted params to the conductor in a different order to the order you've set the properties. Just a minor inconsistency. |
907dec6
to
c465625
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrect indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still needs fixing
This is the original code:
I assumed it was ordered by size, I've seen this more than once, like this
Should I fix original code too? |
Yeh. You should set properties in the same order you received them in the constructor. |
e3630fc
to
f92eeb5
Compare
That identation is not indentation, it's alignment, and according to @driesvints I should use spaces on them. Originally that alignment was wrong, because we had 1 line aligned with spaces and the order using tabs. I'm using spaces on all of them now. Is it wrong? Also you are quoting a line that's not in the same order now. |
Ok, now it's correct. Thanks. |
@antonioribeiro now I don't want this to turn into a giant tabs vs. spaces debate but the current alignment isn't correct. I'll re-paste my previous snippet here (you can just copy/paste this) public function __construct(MigrationRepositoryInterface $repository,
ContainerContract $container,
Resolver $resolver,
Filesystem $files)
{ Notice how the dependencies perfectly match the distance from the first dependency. You only indent with spaces which makes it look like the parameters after the first one don't align properly. Check the diff: https://github.com/laravel/framework/pull/6784/files#diff-a66c98fc0ca13ef8851970c40f8342d1R60 I've added a screenshot to show you what I mean: Just to give you my opinion on this: this is a ridiculously discussion we're having atm and just a perfect example on why you should use spaces for indentation and not tabs. Tabs just confuses people when mixed with spaces for alignment :) |
I really think laravel should just take the jump and move to PSR-2, and symfony style docblocks. |
f92eeb5
to
a5e8841
Compare
Perfect :) |
Also: I don't totally like the idea of Laravel going 100% PSR-2, because I like the current Allman's Style, it's beautiful and the code flow makes more sense to me. |
How about psr-2 with allman style braces? |
I think this is a discussion which shouldn't be held here. |
Yeh... |
Boom! #6836. |
I've kind of always avoided this as people can just use App::make from within a migration if they need anything from the container, and because one wouldn't typically unit test a migration. |
:( I really liked this idea. I hate using App::make in constructors. Feels really hacky. |
Also, in my opinion, it's kind of confusing to see classes being autoresolved in some parts of Laravel and not in others. Newcomers might hit a wall until they understand some features aren't supposed to work everywhere. |
I just don't understand the point of dependency injecting migrations? Are On Fri, Jan 2, 2015 at 5:11 PM, Antonio Carlos Ribeiro <
|
People might need to inject classes to help their migrations to happen. Something that happened to me was a simple group of columns I needed in two different tables, so I did: I have two (very similar) of those:
and this is the common columns generator:
Of course I could use inheritance or traits, but mind just went first with a common Laravel solution and it didn't worked. |
Also something I often do is injecting migrations in other migrations. Say you add a new table that replaces an other one, in the new migration's down method I just call the old migration's up method to avoid to have to repeat the old structure's fields twice. |
If I understand Taylor correctly, he's saying we don't need constructor injection here because that's only necessary if you want to unit test your classes - and you probably don't do so for migrations. Since we already have te |
So if I'm understanding well, reversing your logic, one who doesn't unit test is not supposed to use constructor injection, and the new method injection, they are off limits? Sounds depressing, because those are fantastic Laravel features and everyone should be a allowed to use them If you are trying to teach by example, it might not be the best didactic. I personally do not have a problem with this, every time I hit a wall I just extend the service and add what I need. I had to extend migrations to use transactions and rollback failed migrations (on PosgtreSQL), and also to be able to namespace, separate migrations per service and selectively enable them. But, when you expect people to have aha moments like "of course this feature is not supposed to work here, we don't inject mocks into migrations!", I fear exclusion and, in the future, docs may have to change a bit: "PHP THAT DOESN'T HURT PROS" |
I agree. I inject dependencies even when I don't bother writing tests for
|
I believe you can always use Wrote a blog post on this a couple of days ago. It's not finished but feedback is welcome. hannesvdvreken.github.io |
Just hit that bump. Went the typical DI fashion in migrations, ended up with It would create consistency within the laravel application to have DI supported in all app classes. |
This one is to automatically resolve:
@GrahamCampbell, before you say anything, there was a bunch of spaces before Filesystem:
So I replaced them all with tabs.