5 minutes reading time (922 words)

Practical Development 3: Project

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

vg swdev 0001 projectIntegrated development environments (IDE's) such as Eclipse, Netbeans, Php Storm and others can help to enhance productivity for our projects. They offer differing levels of support for languages such PHP, JavaScript and HTML with respect to highlighting, editing, inspection, refactoring, Joomla! coding standards, extensibility via plugins and much more.

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.

Installation

Download your PHP Storm version from the Jetbrains site and follow the installation instructions and you should be good to go.

The Project

We start by creating a new project from existing files. This creation starts at directory level and we will be using ##PROJECTS##//local.##DOMAIN## 

##PROJECTS##//local.##DOMAIN##/#vcs/extension
| /module
                             /www
                             /logs
                             /.idea

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.

Project Files

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

00

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.

02

But syntax highlighting can be useful in identifying missing closing quotes.

Collapsing blocks

01

Collapsing blocks of code to a single line

01

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.

04

The IDE will also show methods that are deprecated, those that are at risk of being removed in a next release

03

Refactoring

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.

09a

PHP storm will use its knowledge of interpreting the, to intelligently do the search and replace, potentially renaming files and what not.

Joomla support

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 .

Code style

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.

05a

Code sniffer

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.

##XAMPP_INSTALL##/php/phpcs.bat

06a

Next we need to install the support for the Joomla coding standards. Extract the coding standards to

##XAMPP_INSTALL##/php/pear/PHP/CodeSniffer/Standards/Joomla

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.

07a

And as a result we are now being warned when violating the Joomla coding standards

08a

Version control, Pre-processing, Building and Testing

These topics are so important and complex they are worth articles by themselves, so please be patient.

Previous articles in this series

  1. Introduction
  2. Working environment
0
Per què les universitats han de considerar Joomla
Migration complexe d’un site Joomla! 1.5 avec un m...
 

Comments

Already Registered? Login Here
No comments made yet. Be the first to submit a comment

By accepting you will be accessing a service provided by a third-party external to https://magazine.joomla.org/