Using External Tools in PhpStorm
In a recent ticket on YouTrack (our issue tracker), our community member Jared Morgan documented how you can use the “External Tools” feature of PhpStorm to run everyday tools from your toolchain from a custom key binding, without ever leaving your IDE.
Jared wanted to use phpDocumentor, so let’s take a look at how we can configure and run that, plus PHP Copy/Paste Detector.
phpDocumentor is a tool that looks at the annotations in your codebase and generates API documentation in HTML for you. It’s a useful tool written by Mike van Riel (thanks, Mike!) and is something I’ve often used during my contributions to Zend Framework.
Assuming you have phpDocumentor installed as part of your composer dependencies for the project, configuring phpDocumentor as an external tool in PhpStorm is relatively straightforward. First, we need to manage our external tools; you can find it in the standard Preferences window under Tools -> External Tools. We can click the + to add a new external tool, and then name it “Generate Documentation” or similar.
The command I would use from the terminal to generate the docs for Zend\Stratigility (the package I chose to generate API docs for) is:
vendor/bin/phpdoc -d src/ -t doc/API/
This command, when run from the root of my Zend\Stratigility clone, will run the `phpdoc` tool on the `src/` directory (the PSR-4 namespace root of this project), and put the docs into the `doc/API/` folder. To configure this in the External Tools settings pane, it would look like this:
Basically, all we need to do is to tell PhpStorm where to find the executable for `phpdoc`, which parameters to pass, and finally to run as the project root as working directory.
Next, we want to bind a keyboard shortcut to run this external tool. To do this, navigate to Keymap in the preference pane, and then select External Tools and Generate Documentation (or whatever you named your external tool configuration). Now you can bind a key to generate the phpDocumentor documentation just like you would with any of the built-in features.
PHP Copy/Paste Detector
Another useful tool to run over your codebase is Sebastian Bergmann’s PHP Copy/Paste Detector. In this case, we’ve again installed the tool using composer, and can configure it in a very similar way. To run the tool, I would just use the following command in my terminal:
To add this as a tool so we can trigger it without needing to leave PhpStorm, we’d just add the following configuration as an external tool:
Notice in this instance I have used relative paths rather than the full paths, and this works just fine too.
I don’t intend to run this tool often, so instead of using a keybinding, I can just run this directly from the Tools menu of the IDE. Under the External Tools option, you can see that, like any bundled feature, our external tools can be run, and we even get prompted with the shortcut we’ve bound just in case we forget.
Try adding your favorite tools to PhpStorm, and let me know which tools you find useful to be integrated into the IDE.
— Gary and the PhpStorm Team
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…