تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Installing PHP CS Fixer0:00

It would be nice if we could automatically format our code to follow some kind of coding standard. So, for example, if we could hit a button, and this would automatically be updated for PSR-2. Alright, well, to do that, we can set up a build system. But first, I want to pull in a package that will actually tackle this for us. If I switch over to Chrome, we will use Fabian's phpCodeSniffer. Alright, so let's pull that in globally. composer global require and pull that in. And give that just a second. And there we go. So we should have that now. And we do. Great.

Running Fixer Manually0:32

And there we go. So we should have that now. And we do. Great. Next, well, well first, let's just see how to do it manually from the command line. I'm in my current project, and let's go into app/Providers, and that file we were working with was AppServiceProvider. So what I want to do is trigger a command that will automatically clean all of this stuff up for PSR 2. Okay, here's how we do that. phpcsfixer, and we will fix up AppServiceProvider, and specifically, I want PSR 2 formatting. Okay, so if we run that, there we go, it took care of that.

Creating Sublime Build System1:02

and specifically, I want PSR-2 formatting. Okay, so if we run that, there we go, it took care of that. And if I go back to Sublime, it's automatically been formatted. Great, but I don't want to have to switch to the command line every time we do that. Instead, we'll set up a PSR-2 build system. Okay, so let's add a new one. And there's lots of configuration here. In our case, we will trigger a shell command, and, well, we basically want to reproduce everything we did right here. So why don't we just grab that entirely and paste it in,

Using Build Variables1:28

and, well, we basically want to reproduce everything we did right here. So why don't we just grab that entirely and paste it in, and we can remove these quotes. But now, of course, we don't want to hard code that name in. Well, as it turns out, if I switch over to Chrome, Sublime has a number of variables that we can reference within our build files. So in this specific example, what we want is this file variable. I will replace that like so. And really, that's all there is to it. So I will save this.

And really, that's all there is to it. So I will save this. Why don't we create a folder called Builds, and within it, I will save this as PSR 2. Okay, great. So I'm going to switch back to that example file and hit Command C to undo. And we're back to our messy file. And now if I go to Tools, Build System, and we now have a PSR 2 option. Okay, so we select that.

Disabling Build Output Panel2:17

and we now have a PSR-2 option. Okay, so we select that. And now if we build with Command B, let's see it work. Command B. And we can see it's finished, and our file has been updated. However, one last thing. Did you notice that when we ran it, it pulls up a panel here, just showing you the output? Well, maybe that's useful, but I'd rather not do that. So instead, if I hit Command Comma to visit my settings,

Well, maybe that's useful, but I'd rather not do that. So instead, if I hit Command Comma to visit my settings, I will add a new option here, Show Panel on Build. That defaults to true, but I will turn that off. false. Alright. So now we have this messy file we're working on, but it's easy to clean up. Command B, and that automatically formats it according to PSR 2. Very cool.

Command B, and that automatically formats it according to PSR-2. Very cool.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟