- Using the TYPO3 Coding Standard
Using the TYPO3 Coding Standard¶
The coding standards¶
The TYPO3 Coding Standard consists of the sniff pool and the special standard (e.g. TYPO3v4 or FLOW3). The folder TYPO3 contains the sniff pool. This is the home of all sniffs which we (re)implemented for our Coding Guidelines. This are all the shiny sniffs for the TYPO3v4 and the FLOW3 CGL.
The folder TYPO3v4 contains no sniffs but a ruleset.xml file. In this file we refer to the needed sniffs for the specified standard. So we take some shipped sniffs from PHP_CodeSniffer and our own ones from TYPO3 folder.
In both folders there are also package.xml files. This are the definition files for building PEAR packages from.
|- CodingStandardName |- Sniffs |- Tests |- Builds |- PEAR-Package-Majorversion.Minorversion.Serviceversion.tgz |- ruleset.xml |- package.xml
|- TYPO3 | |- Sniffs | | |- Classes | | | |- LowercaseClassKeywordsSniff.php | | | |- ... | | |- Commenting | | |- ... | |- Tests | | |- Classes | | |- ... | |- Builds | | |- PHPCS_TYPO3_SniffPool-0.0.3.tgz | |- ruleset.xml | |- package.xml |- TYPO3v4 |- Builds | |- PHPCS_TYPO3v4_Standard-0.0.3.tgz |- ruleset.xml |- package.xml
Use the Codesniffer¶
The easiest way to install the TYPO3 Coding Standard is via PEAR. We assume PEAR is installed on your machine (Otherwise read the manual at http://pear.php.net/).
Go to http://pear.typo3.org and follow the instructions there. The package know his dependencies very well, so you will be ask to install the mentioned PEAR packages if they are not installed yet.
Note: Its very important to install the PHP_CoderSniffer >= version 1.3.0RC1.
With "phpcs -i" you could verify if the standards are installed.
phpcs -i The installed coding standards are MySource, PEAR, PHPCS, Squiz, TYPO3, TYPO3v4 and Zend
For developer / contributer¶
If you are a user who want to develop / contribute / play around with the full copy of our development cycle, you need to check out the trunk of PHP_CoderSniffer:
svn co http://svn.php.net/repository/pear/packages/PHP_CodeSniffer/trunk/ PHP_CodeSniffer/CodeSniffer
After this you need to clone our complete repository:
git clone git://git.typo3.org/Teams/forge.typo3.org/hudson-helpers/tools/PHP_CodeSniffer.git PHP_CodeSniffer/TYPO3_CGL_Standard
Symlink the standards into your PEAR Codesniffer installation¶
Now you must symlink the coding standards into the PHP_CodeSniffer checkout.For example:
- Checkout-Path for PHP_CodeSniffer: /Users/Your/Path/Development/PHP_CodeSniffer/CodeSniffer
- Checkout-Path for TYPO3 Standards: /Users/Your/Path/Development/PHP_CodeSniffer/TYPO3_CGL_Standard
The folder structure looks now like this:
|- Development |- PHP_CodeSniffer | |- CodeSniffer | |- .svn | |- CodeSniffer | |- scripts | |- tests | |- CodeSniffer.php | |- CodeSniffer.sample.conf | |- LICENCE | |- package.xml |-TYPO3_CGL_Standard |- .git |- TYPO3 | |- Sniffs | | |- Classes | | | |- LowercaseClassKeywordsSniff.php | | | |- ... | | |- Commenting | | |- ... | |- Tests | | |- Classes | | |- ... | |- Builds | | |- PHPCS_TYPO3_SniffPool-0.0.3.tgz | |- ruleset.xml | |- package.xml |- TYPO3v4 |- Builds | |- PHPCS_TYPO3v4_Standard-0.0.3.tgz |- ruleset.xml |- package.xml
According to the folder structure above, you have to symlink the standards:
ln -s /Users/Your/Path/Development/PHP_CodeSniffer/TYPO3_CGL_Standard/TYPO3 /Users/Your/Path/Development/PHP_CodeSniffer/CodeSniffer/Standards/TYPO3 ln -s /Users/Your/Path/Development/PHP_CodeSniffer/TYPO3_CGL_Standard/TYPO3v4 /Users/Your/Path/Development/PHP_CodeSniffer/CodeSniffer/Standards/TYPO3v4
With "php Users/Your/Path/Development/PHP_CodeSniffer/scripts/phpcs -i" you could verify if the standards are installed.
php Users/Your/Path/Development/PHP_CodeSniffer/scripts/phpcs -i The installed coding standards are MySource, PEAR, PHPCS, Squiz, TYPO3, TYPO3v4 and Zend
To run the unit tests you must fire the following command (PHPUnit must be installed!):
Since we are on git and gerrit you could push your patches right ahead into gerrit. So its easier for us to review / annotate / merge your patch.
For more informations about git and gerrit please read the informations on behind the following links carefully.
According to our branching model we push every change into "develop" branch. So when pushing you have to type this command into your terminal:
git push ssh://review.typo3.org/forge.typo3.org/hudson-helpers/tools/PHP_CodeSniffer.git HEAD:refs/for/develop
Note 1: The name of you local branch doesn't matter - you push allways into develop
Note 2: Pushes to other branches will be refused!