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.
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
sudo /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;
cat >> ~/.bashrc <<'EOF'
alias pear="php /usr/lib/php/pear/pearcmd.php"
alias pecl="php /usr/lib/php/pear/peclcmd.php"
Step 4: Reload your bash profile;
Step 5: Now make sure PEAR and PECL are up-to-date;
sudo 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
sudo pear install PHP_CodeSniffer
Step 7: Next up, install the coding standards ‘PHPCompatibility’ from https://github.com/wimg/PHPCompatibility.
sudo 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:
phpcs --standard=PHPCompatibility --runtime-set testVersion 5.4 "/path/to/your/php/project"
(The WIMG PHPCompatibility suite currently supports PHP Version up to 5.5)