Reformatting Code Quickly 0:00Here, I have a class that, at least in terms of formatting, I've absolutely destroyed. But luckily, PHPStorm is fantastic at automating the process of fixing this. But not just fixing it, fixing it according to our preferred coding styles. So, as a first step, I can press Command-Option-L on the Mac. Or, you can press Shift-Shift, Reformat Code, and figure out what the keybinding is on your machine. Anyhow, you'll see this little dialog pop up. I'm fine with it only reformatting the file. And we will hide that dialog. And run it. And that's it. Noticing Style Mismatches 0:34And run it. And that's it. Already a hundred times better. But, at least for me, it's not perfect because it's not honoring the Laravel-specific syntax that I've adopted. And that would be things like this. This brace should be on the same line. This brace should be on its own line. There should be a space between the exclamation point right here. Again, that brace should be on its own line. This is how Laravel itself is coded. Opening PHP Code Style 0:55Again, that brace should be on its own line. This is how Laravel itself is coded. And I like to adopt that style guide for my own Laravel projects. But, if I hit Command-Option-L, right now, I probably would never want to do that because it will reset all of my customizations. But that's okay. Like all of PhpStorm, every ounce of this is configurable. So, very quickly, I'm just going to undo all of this and bring it back to the terrible way it was before. Okay. So, let's go to Preferences. And right up here at the top, we want code style for PHP specifically.So, let's go to Preferences. And right up here at the top, we want code style for PHP specifically. Now, notice that we can apply these settings on a per-project basis or make them global. So, per-project would be really helpful if you contribute to a project where you want to honor the coding style. However, it's not exactly what you use in your own projects. In those cases, you can use a project setting here. But, let's stick with defaults. Now, of course, we're not going to cover every bit of this, but we will stream through it pretty quickly. If you prefer indents, you can check that. But let's begin with wrapping and braces. Configuring Braces and Wrapping 1:55If you prefer indents, you can check that. But let's begin with wrapping and braces. Okay. So, I will let you have a look through this if you're working along. But just some quick things. Do we want a brace placement after the class declaration? No. It should be at the end of the line. However, for functions, it should be on the next line. And for other, let's do next line.However, for functions, it should be on the next line. And for other, let's do next line. Now, notice that they will give you live updates. But if you just want to use your own code, that would be fine as well. So, let's say class foo public function test name echo name. Okay. Now, when you set any of these, it will automatically update the code. So, for example, let's put this back on next line. And you'll see these are the defaults. So, let's bring it back to end of line. Adjusting Blank Lines and Alignment 2:36And you'll see these are the defaults. So, let's bring it back to end of line. Now, let's switch over to blank lines. So, I will copy my sample and bring it over here. Now, personally, I like to have a space right after the class declaration. We can enable that by doing one here for after class header, like so. Okay. So, that's fine, at least for this demo. If we go over to other, we have some cool things like align key value pairs. So, notice right here, when you format, it will automatically align those, which is pretty helpful.If we go over to other, we have some cool things like align key value pairs. So, notice right here, when you format, it will automatically align those, which is pretty helpful. Next, I want true false to always be lower case. I want null to always be lower case. And I always like to have one blank line before my return. So, I have my code, a blank line, and then return. So, we will force that, like so. Next, some people like a space around their variables. So, you see right there, it automatically applies the space. Personally, I'm not a huge fan.So, you see right there, it automatically applies the space. Personally, I'm not a huge fan. So, I will keep that like it is. Finally, for things like arrangement, for example, if you always want your getters and setters to be together, by default, that will be enabled. And you can have a look around there. Okay. So, we're just about done. One last thing in the spaces area. I noted that there needs to be a space within a conditional when you have the exclamation symbol. Tuning Spaces and Operators 3:44One last thing in the spaces area. I noted that there needs to be a space within a conditional when you have the exclamation symbol. So, for example, if not this thing, then echo good. Now, ideally, for my taste, it should be like this. All right. So, let's see if we can make that work. First, you see with around operators, we have this section right here that's disabled by default. Let's make sure that we enable it. Next, let's see what else. Scroll down.Next, let's see what else. Scroll down. How about right here? After typecast. So, if I scroll down, that would be something like right here. Notice there's no space. Let's force one. Finally, if you're working along, feel free to enable or disable anything else. Anyhow, we're back to our terribly formatted code. But now, if I hit command option L, not only does it format it, but it honors my custom formatting configuration.Anyhow, we're back to our terribly formatted code. But now, if I hit command option L, not only does it format it, but it honors my custom formatting configuration. Pretty cool.