Practical Development 3: Project
Third in a series of articles on practical development. The advantages of dealing with your Project through an in Integrated Development Environment (IDE) such as PHP Storm. Consult previous articles in this series.
Managing your project and files using PHP Storm
Choosing PHP Storm
There is no "wrong" choice in choosing an IDE, it is a matter of personal preference. If the IDE covers your requirements and feels good, stick with it!
After exploring several option I found Php Storm to be available on all major platforms ( Windows, Mac OS X and Linux), responsive, user friendly and feature rich, covering the basis of my development needs. Whenever the IDE is referenced in the context of this series of articles it references PHP Storm specifically.
Even though Php Storm is a commercial product – and well worth its cost to commercial developers – it is free to "open source developers". If you are contributing to Joomla, inquire with the "Joomla bug squad" for a copy of the Joomla license key. It comes with a standard trial period of 30 days.
As with any complex tools there's more than one way to do it, I'll discuss what I consider to be a generic way that can be tailored to the specific need.
Download your PHP Storm version from the Jetbrains site and follow the installation instructions and you should be good to go.
We start by creating a new project from existing files. This creation starts at directory level and we will be using ##PROJECTS##//local.##DOMAIN##
The .idea directory is created by PHP Storm and it holds the project settings.
ALL the files and directories from the chosen project directory and down are indexed, monitored and are accessible from within IDE for inspection and editing.
An IDE will provide support for a large number of file types such as
.php, .css / .less / .scss, .xml, .html, .js, .ini
Syntax high lighting
The most basic help when inspecting files comes from coloring the source code, highlighting, making the code more easilly readable. The above a shows part of a .php file with mixed language support for php, html and css.
But syntax highlighting can be useful in identifying missing closing quotes.
Collapsing blocks of code to a single line
Show and Navigate
Because the IDE actually "reads" the source code, comment blocks and interprets it, it will be able to offer you additional information else. Ctrl - hovering a method for example will show the parameters used. Ctrl - Clicking the method or variable will navigate to the relevant source file at the exact position.
The IDE will also show methods that are deprecated, those that are at risk of being removed in a next release
A constant in coding it is that in hindsight we typically are not happy with what we did way back, in comes refactoring, the process restructuring existing code.
PHP Storm comes with some amazing functionality that is worth exploring. For example instead of using "search and replace", use right click on a variable or method, and select refactor | rename.
PHP storm will use its knowledge of interpreting the, to intelligently do the search and replace, potentially renaming files and what not.
The Joomla project has its own coding standards that help ensure our code is the highest quality which will make it easy to read, debug, and maintain. PHP storm can be extended to have specific support for Joomla in IDE's .
PHP storm can reformat code or selections to have correct indentation, spacing etc. With the help of Joomla specific configuration file we can have the IDE apply styling the Joomla way ( see also Joomla docs). To add support for the Joomla! coding style downloaded a configuration file here and copy Joomla.xml file to /config/codestyles/ in the PHP storm installation directory.
Open the PHP Storm - Settings (via File | Settings ), and type code in the selection to reveal and select the Joomla code style.
Having the code look nice is one thing, to ensure the code actually complies to the Joomla coding standards we need to employ a code sniffer (see also Joomla docs).
First setup codesniffer tool following the PHP Storm documentation. Now open the PHP Storm - Settings (via File | Settings ), and type code in the selection to reveal and select the Joomla code style. Now Reference the code sniffer executable to activate the code sniffer.
Next we need to install the support for the Joomla coding standards. Extract the coding standards to
or (for advance users clone) the GIT repository to that location.
Open the PHP Storm - Settings (via File | Settings ), and type inspec in the selection to reveal and select the Joomla code style.
And as a result we are now being warned when violating the Joomla coding standards
Version control, Pre-processing, Building and Testing
These topics are so important and complex they are worth articles by themselves, so please be patient.