PHP Code Sniffer: Testing compatibility with 5.4

Atomic repository announcements, new release notifications and other news regarding the atomic yum repository.
scott
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 8355
Joined: Wed Dec 31, 1969 8:00 pm
Location: earth
Contact:

PHP Code Sniffer: Testing compatibility with 5.4

Unread post 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.
faris
Long Time Forum Regular
Long Time Forum Regular
Posts: 2321
Joined: Thu Dec 09, 2004 11:19 am

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post 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!
--------------------------------
<advert>
If you want to rent a UK-based VPS that comes with friendly advice and support from a fellow ART fan, please get in touch.
</advert>
prupert
Forum Regular
Forum Regular
Posts: 573
Joined: Tue Aug 01, 2006 2:45 pm
Location: Netherlands

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post 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 ;-)
Lemonbit Internet Dedicated Server Management
faris
Long Time Forum Regular
Long Time Forum Regular
Posts: 2321
Joined: Thu Dec 09, 2004 11:19 am

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post by faris »

Thanks.

Additional note: you need safe mode off in php.ini (or specify a different php.ini )
--------------------------------
<advert>
If you want to rent a UK-based VPS that comes with friendly advice and support from a fellow ART fan, please get in touch.
</advert>
faris
Long Time Forum Regular
Long Time Forum Regular
Posts: 2321
Joined: Thu Dec 09, 2004 11:19 am

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post 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.
--------------------------------
<advert>
If you want to rent a UK-based VPS that comes with friendly advice and support from a fellow ART fan, please get in touch.
</advert>
DarkF@der
Forum Regular
Forum Regular
Posts: 313
Joined: Thu May 07, 2009 12:46 pm

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post by DarkF@der »

How to exclude .js and .css
Because it will go stuck on that with joomla sites.
faris
Long Time Forum Regular
Long Time Forum Regular
Posts: 2321
Joined: Thu Dec 09, 2004 11:19 am

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post 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.
--------------------------------
<advert>
If you want to rent a UK-based VPS that comes with friendly advice and support from a fellow ART fan, please get in touch.
</advert>
DarkF@der
Forum Regular
Forum Regular
Posts: 313
Joined: Thu May 07, 2009 12:46 pm

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post 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?
scott
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 8355
Joined: Wed Dec 31, 1969 8:00 pm
Location: earth
Contact:

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post by scott »

Its in the atomic repo
lvalics
Forum User
Forum User
Posts: 38
Joined: Thu Feb 22, 2007 3:49 pm
Location: Romania
Contact:

Re: PHP Code Sniffer: Testing compatibility with 5.4

Unread post by lvalics »

Nice tool, Ilike it :-)
Best regards,
Valics Lehel

Power Toys for PLESK
HOW TO: Setup a new box with PLESK
PLESK Crash Recovery Service
Post Reply