Creating Method Snippets0:00
Now, you already know how to create snippets, but just remember for php to have some specific ones to speed up your workflow. So one thing you could do is create it manually, but you could also use SnippetMaker. You can try a few of these, really. Let's pull that one in. And a huge one is M-E-T, tab, to create a method. All right. Let's just write that out, method. This is what you want. So let's highlight it, and we'll say, Make Snippet.
This is what you want. So let's highlight it, and we'll say, Make Snippet. And there you go. All right. So the trigger will be M-E-T. The description is, php public method. The scoping is fine. And then the file name is fine. Okay. So you'll see that it rapidly builds that up for you, and you can save it.
But next, we do need a tab stop right here. So let's do this. And then close out here. All right. One more time. M-E-T, my method, tab, and we're all set. Let's fix the indentation there. Anyways, some others I would recommend would be, of course, protected method. Yeah, just make that its own snippet as well. Make snippet.
Yeah, just make that its own snippet as well. Make snippet. And for that, I usually do P-M-E-T. That looks good. That all looks good. And then once again, let's fix this. We'll end here, and then update our method. Okay. So now, I can rapidly build up a public method, and then do another one for a protected method. And I promise you, that stuff's going to save you an enormous amount of time.
Snippet for $this1:34
So now, I can rapidly build up a public method, and then do another one for a protected method. And I promise you, that stuff's going to save you an enormous amount of time. Now, you could add one for a constructor, but don't forget, you already have that shortcut from the Sublime PHP Companion package. Now, a few other things that I would recommend here. Take it as far as creating a snippet for $ that will expand to this. Because if you think about it, how often do you type this out in your projects? Probably over and over. So let's make a snippet out of that, and the trigger will be $. And we'll say this, good.
So let's make a snippet out of that, and the trigger will be $. And we'll say this, good. And the file name, this. All right. And that looks pretty good to me. All right. So yeah. Now, anywhere in your projects, you can just say $tab, and that's not right. Maybe we need to backslash that one more time. $tab, and there we go.
Class File Stub Snippet2:24
Maybe we need to backslash that one more time. $tab, and there we go. All done. $tab, call method, and you're all set to go. Incredibly useful. Now, I'd also do one for a general file stub. So you'd have namespace app here, class, name. Yeah. So let's make a snippet out of that, and then we will iterate on it. We could do class for that, good, good.
So let's make a snippet out of that, and then we will iterate on it. We could do class for that, good, good. And yeah. So let's see what we have here. So namespace, it will always be app, but I usually fill in at that point. So we'll start there, add a class name, and then finally end there. And I think that's good. So let's give this a shot. You create a new file. So let's even do that from scratch.
You create a new file. So let's even do that from scratch. So we know we can use advanced new file, command, option, N, and we could say app/bar.php. And now if I type class, that'll fill it in. Whoops. Looks like namespace is all messed up. Ah, yeah. We have to escape that. Okay. One more time.
Custom Laravel Test Snippet3:25
Okay. One more time. Class, tab. Keep it like that, tab, bar, and then we're all set to go. We can add our constructor, and yeah. You can see how quickly we can get going here. Now one that I even do is for quick test classes. Now with Laravel, we can create a test. So I could call this FooTest. And if we take a look at that, yeah, it will scaffold out one for me.
So I could call this foo test. And if we take a look at that, yeah, it will scaffold out one for me. But there are certain things that I always do. Like if I'm using database migrations, I will pull that in, and then I will delete transactions. And without middleware, I just like to clean things up a little bit. And then I hate having to manually delete this myself. Maybe I will just default to something like that. Okay. So if I want that, let's make that a snippet called test class, description, new, php test class, and the file name.
So if I want that, let's make that a snippet called Test class, description, new, php Test class, and the file name. Yeah. That all looks pretty good to me, I think. So yeah, now I could just say within my test directory, let's add a new addThingTest, and then I can just type it up here. Really useful. Saves a lot of time. And of course, right here, we'll have a tab stop, and then my final. All right.
And of course, right here, we'll have a tab stop, and then my final. All right. One more time. Test class, addThingTest, it does that. And then let's just fill in the remaining portion. So I guess that should be the final stop. And then we'll go to here. Good. So final test, test class, addThing. It does that thing.
