Getting the most out of PHPStorm for Drupal 8

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
recording alright good stuff so this is getting the most out of phpstorm withdrew blade I've been working with you blade for the past year or so and like just how I use my IDE change significantly from hot when I was off developing d7 asleep night and day a a little bit about me I work at digital bridge solutions were mostly ecommerce shop in Chicago focusing on b2b stuff so a lot of Drupal commerce a lot of Magento we're starting up with the Oro if you've ever heard of it yes actually be great to close the doors Joe can you try and close the doors all right that's much better so you had to repeat this I worked it'll do digital bridge solutions um I've been there about two years now I've been working with Drupal about four we mostly do e-commerce so joopa commerce Magento that kind of stuff all PHP my tag is control a dome on True Blood or github anywhere where I can find it and get it I don't have a Twitter I try not to tweet but feel free to tweet my company and they'll get it back to me so let's let's do a little bit a little bit about you guys how many guys how many of you guys are currently using phpstorm awesome I mean if you are using X debug with phpstorm same thing great and how many of you have like some type of automatic code testing your code sniffing or get hook that you know tells you if something's going wrong awesome so this should all be we're gonna start out with plugins this is kind of this is the list of core plugins that I considered to be like really essential to my efficiency the first is get everybody has their own get interface I really like the phpstorm one because it's integrated with my code development and it's a very nice interface to use it does PI sixty to eighty percent of what I need to do on a day to day to day basis the rest of it I do in the command line dot ignore is a plug-in that interprets get ignore files and really any type of ignore file and highlights it in phpstorm so like the boxes files are grayed out to tell you that it's not gonna get changed which is super helpful the symphony plugin this is d8 specific it has a lot of symphony integration goodness for phpstorm and kind of does the last stuff around the services and annotations and that kind of stuff drupal symphony bridge is a plugin to integrate symphony or integrate the symphony plugin too to integrate with the symphony plugin for PHP storms physically for drupal things and I believe that's mostly services but I'm not 100% sure about everything that it does and then PHP PHP annotations which is required by the symphony plugin that does a lot of the auto completion of annotations and classes and stuff and keep promoter X's a new one so I started or I started working on this presentation couple months ago and I was like I should there's more shortcuts in phpstorm so key promoter acts prompts you like when you do something with the mouse to use the shortcut which is super cool git so we're gonna go through get quickly I assume that most of you are familiar with it and have your preferences for a get interface I'm just gonna quickly go through the things I find the best about the phpstorm get interface if you guys have anything else that you really like feel free to shout it out so the tool window just to turn it on there's this little grey box at the bottom of phpstorm which opens up this bar and you can do version control there and then the version control window is history which is let's write this isn't being tracked into repo currently that's good but anyways the history it kind of shows you all the different shows you all the commits in the repo or all the repos that you're tracking because phpstorm can track multiple repos in the same project so shows you all the commits it shows you the files that have changed it shows you what branches this commit is in and the various tags you can filter by branch user date path so it's a fairly nice interface to just kind of navigate a repo and then there's the local changes which shows you everything that's changed in the everything that's changed in the repo and would be committed so super helpful is yeah I actually meant to do so the way I built these slides is that this is really a I think when you go back to it they'll be helpful most of the presentation will be done and actually done in phpstorm just I don't like example repos and for repo so yeah the history local change is all super helpful Petrey storm also tracks local history of files so if we go in here UCS local history show history it will show you all the changes that I've made to this file it can be fairly spotty between sessions but like if you know you had something working and you've then broke it super helpful to go back the diff you which was similar to the local I was showing so any of the files that have changed it'll bring up a dip of Weston's repo and what's different pretty nice and that's really the interfaces I use the most it's also really nice for merged resolution it'll give you a three-way view where you can like arrow things to left into the right into the middle edit the file in there and then it'll warn me if you haven't resolved all the conflicts so very nice all right that was mincing and sniffing so when things sniffing is really is linting is is something gonna break its syntax that kind of stuff sniffing is kind of more stylish like yes this is functional but is it really nice to look at you know is it clean can people read it so phpstorm has a bunch of different knitting of sniffing integrations the main one for drupal is ph bcs which is PHP code sniffer and what that does is it does all the PHP PHP in style like snipping so it'll highlight within PHP storm when you're not following a Drupal style guide which if you write patches or just kind of want to keep your code readable with the rest of Drupal is super hopeful the style int is actually new in 8.4 and it does CSS linting so if you're writing any CSS is super helpful eventually it'll be available for contribute themes to like run against a patch through Drupal CI but I don't think that's there right now p.s lint is for JavaScript I personally don't look write a lot of JavaScript but if you do phpstorm has a linter ford or has integration for es lint and Drupal core comes with NES lint file and it's a slant so style lint is new I've been using sass Lynch for the past couple of months which is super cool because it does it has sass rules for like a CSS files and stuff so it'll tell you like when your nesting too deep or you know to use a variable instead of a direct color name and that kind of stuff and it's all configurable with with his own configuration file I believe style lint supports s through a plug-in but I've never tried it so might be worth exploring [Music] alright so this by default I've got this custom block bus I know the code in there logically is horrible that's not purpose but by default this is what phpstorm will show you is like errors and stuff I'm guessing most of you can see a bunch of Drupal coding style errors in this and it looks really ugly to you so if we turn on PHP CS just make sure all right so now we got a bunch of other stuff so you can see that is saying this functions missing a block doc or docx block what else do we got billed is not an o'er camel format which I'm actually sure this right and then indenting is wrong it's like this whole function is just indented too far what's this function so that knocks out one of them build shouldn't have that underscore there and you can see that there was this red line up here telling us that my class did not implement the build method which is required for a class implementing the base block interface so this why I like the red line will actually throw a PHP error yeah so if i refresh my page it just doesn't work and PHP storms like that so I'm actually gonna leave that for now because we're gonna cover how to fix that later the arrays are a mess we got double quotes instead of single quotes so we have no period we have stuff going across the border so the great thing is that if you set up phpstorm to use Drupal coding standards which is like default integration yeah so this is default phpstorm you can set it to use the Drupal Co style and you reformat the code through phpstorm it'll fix most of it for us so yeah like I didn't do the period and it didn't break out my comments but it did most of it for us it didn't add a comment here the video and the audio yes but like there's not a video of the room it's so to actually turn it on its settings editor PHP and that'll do that's like all the code settings for PHP and then you choose Drupal from predefined style and then to actually reformat it is code reformat code yeah so like it's super helpful like just it's probably decrease the amount of air as I make significantly just having that warning there even if I don't have like something that's like telling me my commit has to be perfect before it's gonna be accepted and then it'll tell us that the use class right we're not using this so we don't need it so that's peach BCS super helpful I have heard of people setting it to show it as an error instead of instead of a warning it's like so Joe's warning right you can do shows air but personally I prefer errors to be things that are actually gonna break my sight instead of just style God warnings but if you're committing and like your commits not gonna be accepted if the style is bad and maybe there is the right thing to do so this is pH BCS is like plus a command-line tool and it has a rule set which Drupal provides its own like the coder module provides it your vote rule set for pH BCS so yes you can write your own or customize the Drupal one peepee storm actually I'm not sure I think drooling has one side right I don't know about that yeah phpstorm to notice the version of Drupal Lake if you set up that you're close so very good so if there's a difference it'll do it for you actually I think I might turn down here too so my warning about stuff like sassily is that it can get overwhelming very quickly alright so I copied this directly from this is a bootstrap class or a file and you can see that like there's all kinds of errors just by default in bootstrap with the defaults Asselin settings so like if you're gonna do this make sure that you know what rooms you want and like that you actually care about them because most of this is just it's all style and how it's gonna be read it's not functionally different right like yeah it's not gonna find my variables because I don't have them like it wants me to rearrange all the all of these so that they're in alphabetical order don't really care about that but does always do the full project because phpstorm does a lot of indexing and like auto-completion stuff where it has access to everything you'll get a lot more functionality than just opening up for the theme yeah or even above the doctorate if they're using composer like it might just be the entire folder like yeah so I'm using Drupal um and you can see that like Drupal VM there's a bunch of Drupal VM config stuff and then there's the web root which is the doc root and this is actually Drupal but like there's the vendor folder here which is super important for PHP stuff and they auto-completion is so much better with the vendor folder not that I've tried to find I assume I had no you can do except mark bookmarks and stuff but I'm not sure yeah cuz like the themes kind of buried so if you want to just keep that open I'm not sure all right back to the presentation so yeah that was minting and was a lynching and sniffing pH BCS super useful if you're gonna do one of these DuPage BCS nice all right navigating code so this was by far the biggest change between d78 right object-oriented code which is nice for development but kind of a pain to navigate so I learned a bunch of new navigation tricks in phpstorm shift shift will search anywhere and everything which is awesome right so who wants to look up something anything node base class there's apparently we got some twig most we got all right knows way too specific all right we got our form class form Ajax response builder maybe you're doing something with Ajax but it'll search everything and it kind of gives you like it groups somebody what you're getting back which is helpful I'll show you the path so if you know what yet what you actually want because yeah like we see with node there's a bunch of stuff from the vendor folder there's much less up from Drupal can be a bit of a pain just circulate through and this more I was just doing enter on this but you can click on to like actual file names it searches symbols if you have a case where you have like an actual unicode symbol I believe it will search for that too but I don't do that so you probably shouldn't do that hierarchy view this is by far one of my favorite views in phpstorm so this will actually show you the entire hierarchy of a class we close out with this so we have we have our our custom block that's which extends block based so if I do ctrl H on this it pulls up every implementation like the entire hierarchy plug-in base context-aware plugin block base and then all the implementations of block base and you know what views like it just shows you everything relevant to that to that class which is super helpful if you're looking for examples or trying to navigate up the stream if I pull this up all the time when I'm looking for examples like how to do something because I'm like somebody else has pide done this before and I can just go look at how they did it you can also do I don't do this one very often but I think you can do functions and methods as well control shift H yeah so like you can get a function hierarchy actually surprise the build one doesn't have I believe this would show you like if it's calling a parent like if there's a parent classes also called will show you that entire heart hierarchy copying paths so you know sharing what code you're looking at is super helpful and with Drew Boyd there's a bunch of different files and it could be hard to describe what you're looking at so ctrl shift C will give you the entire path like on your laptop which can be helpful if you're trying to like do something on command line or if you just want a relative path with a line number ending motion control shift alt C or just like relative to the project with the line number you do have to be careful with that one because like if you're on a function it'll append that like it'll copy the relative path like the namespace function path I believe so we do control shift I'll see I'm build yeah so it's like it gave us the whole build thing but if we do it up here it gives us line 17 so it will change based on kind of what you have selected so just be aware of that one function definitions add in here doc is a nice tag is so helpful right if you do ctrl Q it brings up the definition for that which is nice so you don't have to go up and down and open up other files this also works just on function declarations and also on when you call functions so if we did like this sure talk you right it'll bring up the definition of that function too so like if you just need if you're spot checking something you just want to really quickly check it's a great way to bring up the documentation for a function go to function declaration so if you actually want to go to like the base of where something is to find control B or shift click I believe it was control click yeah so what control B took us right to calculate dependencies in the black face class super helpful I mostly use this one when I'm debugging and I want to put a breakpoint like at the very top of something find usages so if you actually wanted to see like the square brackets so little square brackets so like it took me to the top of the file left or right all right so are you actually I think that I'm pretty sure that does exist I don't use it very often where were we find usages right so I can calculate dependencies if we do an alt f7 they don't since this is uh what was the saying freitas asking if it wants to do the base method instead of actual one on this class it's like the base method will find everything one on this path will just find stuff this actually when this class is being called so I'm gonna do everything and it will pull up literally every place that this function is used and it kind of groups them up by super or by uh by how they're used so delegate to another instant business method delegate to super method method call usage and comments so like if you're actually looking for other implementations this is probably place to go and you can see it's using an if statement here so it can be helpful if you're looking for when to use a function or how to use it most actions so when you go like when you have squiggly lines under stuff see what can I do alright let's do like a type of that's not a real word and they'll tell me that if I do all hunter it will give you a bunch of options change too that's not gonna give me there we go so I just entered on change to and I'm navigating with my arrow keys welcome hit I get rid of this clock base use statement false enter import class so most of the times when you see like something highlighted or underlined you can all Center it and it will give you what actions you can do on it this is a nice short keyboard shortcut because you can usually right-click and do the same thing gutter icons so these are very little these are tiny little things in the gutter of phpstorm that are super super helpful the three that I know about are i/o and H I the eye icon takes you to implementations of parent methods or children or if you're at the parent it will show you all the implementations of the of the child classes which is useful if you want to plop all the examples instead of doing like the alt f7 that we showed Oh shows you what stuff is being overwritten it's like build is overriding the extent of the block base and it will take us to that if you click on it and then you can see here's all the implementations of this method and H is hook which is useful when t7 and t8 h arrow up is like the base hope declaration can go to that each arrow down I believe is implement eight actually I don't think there's a nature about let's see if we can find an API bus this isn't going to work or tolls for you so hook block do you alter here's all the implementations of it and if you're on the hook it shows you where the definition is and then also where it's called like where the actual hook is called so this is where the block view book is called in Drupal core so if you're working with hook still super helpful and that's it for really navigating code does anybody else does anybody feel like I miss something big awesome I'm always interested to learn more about PHP some because I feel like I'm learning something new every week and there's just so much to know yes there's very good integration for PHP unit at least I'm not sure about how great B hat integration is by now you can run B hat tests in phpstorm okay yeah so for the recording apparently the be hit the B hat integration is really great like you can actually bug through it and there's I assumed syntax and code completion as well yeah so sounds like PHP unit and B head or supported fairly well all the functions that is inherited I'm not sure about that one actually typically when I do that I just I do with this and I look at what's available so right so I'll do this and I'll just let the auto completion do its thing I assume there is a view to show that but usually I'm only doing it when I'm writing code so this error yeah I mean thing yeah so you can pull it up with control-shift I code completion and boilerplate so first a shout out to Drupal Council is super helpful for generating boilerplate code and even though it can generate a lot more than you need is way easier to trim it down than to know everything you could possibly like implement so if you want to like generate a form or an entity or like an event listener your console is super helpful as far as actually doing a PHP storm as we saw it'll give you this nice read error when you don't implement the right methods and then interface or class and if you right-click if you do control I it'll show you all the methods like that you can implement it so this is the one we actually need but it gives us a bunch of other stuff that we could do as well select that we want the inherit dock and we now have a bill the nicer one though is alt-enter so I got rid of the old one we just did I all enter this just add method stubs and it gives us the entire documentation and oh did you and that I do that for every required method that class needs so usually I do that and I just replace this with inherit dock when I'm done because I don't need that documentation after I write the function okay that's method to use statements kinda already covered this but when you're all to completing stuff phpstorm will add the use statements for you at the top of the file but like if you copy something in from from drupal.org err Stack Overflow and you have this nice yellow highlight you can just all Center it and import the class if there's more than one option we'll let you navigate all the different classes that it could be until you find the one that you want and unused classes are shown in Gregg's like if you write some stuff and then you don't need it anymore it's like you're doing something with entity site manager and you just don't need it anymore it's gonna show him grade the PHP CSS will highlighted I don't as far as I know it doesn't clean up after herself like I've never seen it remove a class but that might just be harm deleting things and that that's really all I have for code completion and boilerplate that the one real pain point I've had is like implementing an interface with required required methods and the documentation for those required methods they bounce have like any code completion stuff but they use all the time I know there's this thing what was it no actually we something I've left like 12 minutes all right we're gonna skip over 2x debug patching real quickly d8 patching with composer highly recommend it it's awesome like I said before you can first you can apply patches directly phpstorm either from your clipboard or from a file quick patches for confirm muggles if you're working with a kinship module and your repositories using composer there's this tag called for first source which will install the repo versus a package if you can then declare that as a new get root in your project and phpstorm track changes those files and then that's really great for like if you're debugging a control or like writing a passion a quick patch against the control module and then phpstorm can generate patches but you can also use your favorite patching method I prefer get actually for phpstorm and an X debug ecstasy bug is awesome I want to make sure I got this in here so configuring X debug there's a bunch of configuration rounded I personally use Drupal VM and phpstorm which means I'd have to button clicks to make it work but it can be more involved with that more involved in that depending on your setup enabling us debug like I said it's 2 flex for me in my in my browser there's this little bug here debug that turns it on when the browser was which tells chrome Daleks on the right next debug headers and then phpstorm there's this phone up here and that tells it to listen for those headers setting breakpoints so we've got this nice class what if you want to know whenever this class is call you just you click on the gutter here and you get this red red mark and we turned on actually delete this all right so we should get a it should stop right so you can see that's just the browser's hanging right now and that's because it's waiting for PHP to finish so we've successfully put a breakpoint on our class and this will stop whenever like this class is called so the interface you're setting a breakpoint over here is the resume button stop this button lets you manage all the breakpoints in your code so if you have a bunch it's nicer than going to the file and finding them you can also delete them which is handy if you don't want them anymore this will mute all them all the breakpoints in your code so if you're just annoyed and you want to actually run something without stopping and every single one of your breakpoints you can do that you can also conditionally mute them I'm not sure if we can do that right now while we're stopped and I don't know what the buttons down here do I think these are mostly phpstorm buttons so and then you can see in on the left here you have a tall sack in the middle this is all the variables available and their values and on the right you have watches so watches like over here I can watch the class variable and the watches and this is really helpful for like window values really nested deeply inside another variable cuz it'll just it'll set the value here instead of having to navigate through this because the hierarchy won't like if I navigate in this and the actual this variable and I picked something out of here like this this isn't gonna stay open when i refresh the page and or when I resume so I'm not yeah it's not gonna like that one but most times it'll work all right so Mercedes not working all right so you can see I've had to this block here the message changes randomly I saw my breakpoint set yeah so you can like turn off individual breakpoints and you can see the green right there and that's just you get this pulled up by right-clicking so you can see the message is changing now let's see we kind of we want to really inspect what the message is going to be before sets out or perhaps we have the value we have an error with like one of the values or one of the key values so I'm gonna set a breakpoint on this if key key equals chose a message line so you can see the chosen message is key to the key value is currently zero and the message is well nothing right now all right that works for me I'm gonna set another breakpoint down here at the return I'm actually not sure which line I need since is stopped these new breakpoints will get hit immediately that's not going like completest request and you're going to do you're not gonna have to refresh the page to hit these so this is the message that the code selected well I don't like that so you can change the value of variables that's fresh information marks this is a silly example but it's really helpful like when you're actually debugging something or when you're trying to write some code that you can change variables like on the fly at a breakpoint so we have let that finish and you can see we have our accent birds from each mark in the front end here you can also do conditional breakpoints so like if I only cared about when the key equals three I can do that and so this one I stopped when the key equals three right so refresh the page key value three so let's skip 0 1 and 2 as long as showing us 3 actually I think let's make sure I'm not skipping too much Shepard the interface evaluating code this one's important so you can change values but you can also evaluate code when you're stopped so very collective value 8 expression or Auto fade so if I wanted to get the value of chosen message I could do that but most importantly and this is super helpful when I've been developing is autocomplete works and it also acts it also returns the value of your call all right that's not for your face ID right so instead of writing some code refreshing the page and seeing what happens you can just test out your statements here and see what they're gonna return at that point in the code so no more I've pretty much stopped using like DPM because I just don't need it with this I when I write a new method I put like one breakpoint in I write out my code I test my questionable calls in this box here and I fix them if they're not returning the right values it's really helpful like entities with fields because there's all kinds of fun ways to access values I'm in on a field and this makes sure that I get it right the first time instead of kind of guessing and hoping it works Thunder mapping so if you want to put a breakpoint in in a vendor file you actually have to map that separately in phpstorm so it's languages and frameworks PHP servers so like I need right now if I put a breakpoint in the vendor folder nothing would happen if I do there / nuptup - drupal vm / what is it rupal flashbender not my parents would work in the vendor folder and that's one of the thing like phpstorm is pretty good about doing the web route the doctor route but it doesn't always get the vendor folder so if you're not stopping in the vendor folder that's probably why you can see also on the left here there's different keywords like you can have multiple URLs that stop at it so if you're doing a multi domain site you have to declare each one each mapping individually I think I was able to speed the most Lex debug stuff see I missing anything on the interface Oh step over a step into so step over well stuff like it'll let the current line complete and then go to the next line but you don't you don't the set a breakpoint step into well actually take us into this if statement so like step into anyways you can use stuff over and step into and force it up into and step out to navigate like through the code line by line like step by step by step without having to set a breakpoint and every line of code like I said one up there at chosen message refresh the page and I just step over this line it'll take me down to the next line in the next line all right I think that was everything I want to cover Oh PHP CBI which this is PHP code beautifier you can integrate it through an external tool in phpstorm and this will is like that reformat that we saw at the beginning but they don't do it so much better I actually do a bit more than like the phpstorm reformatting will do these are my configurations I'm not a hundred percent sure if they work with d8 but I think they do and other things phpstorm does composer management is new to one of the versions of people it's in a new in a newer version of phpstorm I haven't tested it but I know is the thing and it tells me about it every time I open up phpstorm and then Matt layman has written a Drupal test running plugin for phpstorm Mac layman works with commerce guys he does a lot of drupal contributions so if you're doing contribution and you're running your tests there's a plug-in for that I personally haven't used it and that gives us the time does anybody have any questions we have been go over a little bit yes I've tried this as well because I'm running out of em and phpstorm is on my laptop I haven't gotten it to work successfully but I've seen multiple guys where you have to turn on in the actual command line PHP configuration and then there's something about passing passing ports I think well yeah I haven't gotten that to work successfully either I've heard guys that say as possible [Music] and a general warning about XD bug it does affect performance so if your site's running slow you should hide turn it off but if your debugging it's about worth it yes yes it does window hope productivity guide so this will show you like how much time this has saved me or when the last time I use the command let's see I used one a year ago tag name completion code completion I've used sixty five hundred times syntax of our selection twelve thousand times yeah that's kind of cool to look at also when the help menu is a key map reference so pull up all the shortcuts and I nearly forgot but I have those printed out from phpstorm so I'll go put these out of here I also have stickers from them so those will be up here then we can go like few more minutes yes copper's their peaches for a little inner gate with doctor and vagrant but I was on mine it [Music] I'm trying to get this post up to the session descriptions level and then we'll be fully level [Applause]
Info
Channel: Bay Area Drupal Camp
Views: 2,100
Rating: 5 out of 5
Keywords: BADCamp, Drupal, Drupal Camp, BADCamp 2017, Open Source CMS
Id: nSFhZHa1nSo
Channel Id: undefined
Length: 47min 42sec (2862 seconds)
Published: Mon Oct 23 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.