Load WordPress Sites in as fast as 37ms!

Test your code for PHP (in-)compatibility

PHP Upgrades are a pain in the ass but from time to time, it’s desperately needed. For a hobbyist with one or two websites, it’s not that much of a deal to check your code and update, but what if you have hundreds of websites running on your servers? Automated tools would be the better choice.

Luckily there’s PHPCS – the PHP CodeSniffer – to check your code for appliance to a certain set of coding standards.

Installing PHPCS is a breeze, if you have PEAR installed. If you followed my “Ultimate WebDevelopment Server” series, you already have PEAR installed (continue at step 5), if not …

Step 1: Open the Terminal app (using Spotlight for example Space)

Step 2: Type the command

Shell commandsudo /usr/bin/php /usr/lib/php/install-pear-nozlib.phar

Enter your password, press enter and wait for the installer to finish.

Step 3: Having easy commands for PEAR and PECL is a welcome addition;

Shell commandcat >> ~/.bashrc <<'EOF'
alias pear="php /usr/lib/php/pear/pearcmd.php"
alias pecl="php /usr/lib/php/pear/peclcmd.php"
EOF

Step 4: Reload your bash profile;

Shell command. ~/.bashrc

Step 5: Now make sure PEAR and PECL are up-to-date;

Shell commandsudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net
sudo pear upgrade --force pear
sudo pear upgrade
sudo pecl upgrade

Step 6: Install PHPCS

Shell commandsudo pear install PHP_CodeSniffer

Step 7: Next up, install the coding standards ‘PHPCompatibility’ from https://github.com/wimg/PHPCompatibility.

Shell commandsudo git clone https://github.com/wimg/PHPCompatibility.git /usr/lib/php/pear/PHP/CodeSniffer/Standards/

Step 8: Now you can test your code for PHP 5.4 compatiblity with:

Shell commandphpcs --standard=PHPCompatibility  --runtime-set testVersion 5.4 "/path/to/your/php/project"

(The WIMG PHPCompatibility suite currently supports PHP Version up to 5.5)

Author: Remon Pel

WebDeveloper though not WebDesigner

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.