PHP Projects¶
TL;DR - You must ensure the points below are handled.
PHPStorm Config¶
All developers should be actively using the preset PHP QA coding standard globally in PHPStorm.
To achieve this, there are PHPStorm config files that need to be imported that will configure the code style for PHP and also set up file templates for PHP classes.
The configuration files are located within the QA repository
Follow the instructions to import the config, be sure to set the style as global
in PHPStorm.
Importing Config¶
To import the config, download the jar
files from the repository page, there will be one for the code style and another
for the code templates.
In Phpstorm, go to File -> Import Settings
and select the downloaded jar files, this will import the settings.
If you are using Jetbrains account sync then you will need to disable this to allow access to the import item. Once the import is done, you can re-enable sync and overwrite the Jetbrains settings.
Once this is complete, your Jetbrains account will persist the configuration between IDE installs.
Warning
Your Jetbrains account settings will be clobbered by the above. Any other appearance/misc settings will need to be restored manually.
PHPQA¶
All developers should be actively using PHPQA to analyse their code and run their tests.
This is important as it will actively enforce code style, check for errors using PHPStan and automatically fix code styling issues with beautifier.
PHPQA will work with most frameworks but most notably will not work with Magento 1 due to how classes are namespaced.
Laravel, Symfony, Lumen, etc and bespoke will work out of the box with the PHPQA preset configuration.
Testing Structure¶
When working with frameworks (not Magento) or bespoke projects,
you should be conforming to the standard testing structure
using small
, medium
and large
tests.
When writing tests, you should observe this is as standard practice, it is expected that you conform to this structure to maintain consistency between projects and to make hand overs easier to perform.
Continuous Integration¶
When working on a project, there are two was to set up continuous integration depending on whether it is open source - or not.
If the project is open source, the default approach is to use Travis to handle CI, otherwise a git post receive hook and a bash script will handle CI.
In either approach, PHPQA will handle the actual CI process on the CI runner (bash or Travis).
Travis¶
A simple example of using Travis with PHPQA is the Type Safe functions library. This is a simple library that wraps the native PHP function calls to make them strictly typed (to help PHPStan and stay DRY).
See how to work with Travis for more information.