Page 1 of 1

PHP Code Sniffer: Testing compatibility with 5.4

Posted: Tue Jul 16, 2013 12:14 pm
by scott
PHP codesniffer is a utility to lint PHP code for coding standards. It includes the PHPCompatibility module to test code against PHP 5.3, 5.4 and 5.5 sets. I highly recommend checking your applications with it for compatibility with PHP 5.4.

Example output of an application that is not compatible with PHP 5.4:

Code: Select all

 127 | ERROR   | The use of function session_register is discouraged in PHP
     |         | version 5.3 and forbidden in PHP version 5.4 and forbidden in
     |         | PHP version 5.5; use use $_SESSION instead
To install:

yum install phpcs

Example usage:

Code: Select all

 for i in `ls -1 /var/www/vhosts/`; do echo "DOMAIN "$i;phpcs -p --standard=PHPCompatibility /var/www/vhosts/$i/httpdocs --report-full=/root/possible.5.4.issues/$i;done 

General notes:
This utility is written in PHP, so memory limits and disabled functions could mess it up. Otherwise its very very cool, I highly recommend it.

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Tue Jul 16, 2013 2:57 pm
by faris
On a couple of my systems it wants to install php-pear from the base repo (not ART):

Code: Select all

 Package                      Arch       Version               Repository  Size
================================================================================
Installing:
 php-pear-PHP-CodeSniffer     noarch     1.5.0-3.el6.art       atomic     491 k
Installing for dependencies:
 php-channel-phpunit          noarch     1.3-7.el6.art         atomic     4.5 k
 php-pear                     noarch     1:1.9.4-4.el6         base       393 k
 php-phpunit-PHP-Timer        noarch     1.0.4-3.el6.art       atomic     8.2 k
Is that OK? I'm being cautious here! I realise php-pear is basically a bunch of code as opposed to php binary stuff, so the currently installed php version and the source of the rpm shouldn't matter. Nevertheless, something at the back of my mind says "Danger Will Robinson" so I thought I'd check first!

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Tue Jul 16, 2013 5:49 pm
by prupert
Cool addition to the atomic channel. Thanks, Scott!
On a couple of my systems it wants to install php-pear from the base repo (not ART)
Sure, that is okay.
Generally speaking there is significantly less danger in installing something from CentOS base than from the atomic channel ;-)

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Thu Jul 18, 2013 1:06 pm
by faris
Thanks.

Additional note: you need safe mode off in php.ini (or specify a different php.ini )

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Thu Jul 18, 2013 1:24 pm
by faris
Ach. I had to add --extensions=php to get it to work nicely :-)
It was otherwise getting stuck reading jquery-1.4.4.min.js in one particular directory.

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Fri Jul 19, 2013 7:42 am
by DarkF@der
How to exclude .js and .css
Because it will go stuck on that with joomla sites.

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Fri Jul 19, 2013 9:28 am
by faris
just add --extensions=php to the command, which will only scan php files. You could also use --extensions=php,html,htm and any other extensions you DO want to scan, separated by a comma.

Optionally, also add -n to not be warned about warnings, only errors, and -v for more verbose output if it gets stuck somewhere).

e.g.

Code: Select all

for i in `ls -1 /var/www/vhosts/`; do echo "DOMAIN "$i;phpcs --extensions=php -p --standard=PHPCompatibility /var/www/vhosts/$i/httpdocs --report-full=/root/possible.5.4.issues/$i;done 
What I can't figure out is how not to be warned about php 5.5 errors. My results are littered with mysql errors that only apply to 5.5.

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Fri Jul 19, 2013 11:16 am
by DarkF@der
Excluding Packages from CentOS / Red Hat Enterprise Linux 5 - atomicrocketturtle.com
Finished
Setting up Install Process
No package phpcs available.
Nothing to do


No phpcs in Nucleus repository?

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Fri Jul 19, 2013 12:08 pm
by scott
Its in the atomic repo

Re: PHP Code Sniffer: Testing compatibility with 5.4

Posted: Mon Aug 12, 2013 9:45 am
by lvalics
Nice tool, Ilike it :-)