Page 1 of 1

Joomla! CodeSniffer

PostPosted: Tue Jun 19, 2012 9:56 am
by JeanPierre
Hello Max,

I would like to run PHP CodeSniffer to see which modules and plugins and templates need updating. Because SSH access is not allowed. How can I run the PCHPS script?

Re: Joomla! CodeSniffer

PostPosted: Wed Jun 20, 2012 5:39 am
by Max
JeanPierre wrote:I would like to run PHP CodeSniffer to see which modules and plugins and templates need updating. Because SSH access is not allowed. How can I run the PCHPS script?


Can you please elaborate on all this? As far as I know, codesniffer is a development tool - why do you need it in a production environment? Why do you need SSH? And what is PCHPS?

Re: Joomla! CodeSniffer

PostPosted: Wed Jun 20, 2012 7:57 am
by JeanPierre
Hi Max,

I have noticed when I turn on the debugging that with the new joomla 2.5 there are still php coding errors in modules, extensions and templates. As I am new to this I have been trying to figure out why new joomla 2.5 addons are still using deprecated code. So I would like to log these errors and then if possible try to solve them myself and/or pass them on to the developers of the addons.

PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.


Checking a directory with PHP_CodeSniffer


$ phpcs /path/to/code

FILE: /path/to/code/myfile.php
--------------------------------------------------------------------------------
FOUND 5 ERROR(S) AFFECTING 5 LINE(S)
--------------------------------------------------------------------------------
2 | ERROR | Missing file doc comment
20 | ERROR | PHP keywords must be lowercase; expected "false" but found "FALSE"
47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
51 | ERROR | Missing function doc comment
88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
--------------------------------------------------------------------------------

FILE: /path/to/code/yourfile.php
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
21 | ERROR | PHP keywords must be lowercase; expected "false" but found
| | "FALSE"
21 | WARNING | Equals sign not aligned with surrounding assignments
--------------------------------------------------------------------------------

Joomla CodeSniffer

http://docs.joomla.org/Joomla_CodeSniffer

This is a custom coding standard for the PHP CodeSniffer that attempts to codify and enforce the Joomla coding standards.


To test a platform file using the provided platform coding standards use

phpcs --standard=build/phpcs/Joomla path/to/file/or/folder

Further documentation on the use of phpcs can be found at: http://pear.php.net/package/PHP_CodeSniffer/docs

To test a platform file using the provided platform coding standards (i.e. Joomla CodeSniffer) use

phpcs --standard=build/phpcs/Joomla path/to/file/or/folder

I also noticed when installing PHP Codesniffer via the Pear panel I saw the following errors:

Image

Re: Joomla! CodeSniffer

PostPosted: Wed Jun 20, 2012 9:29 am
by Max
You cannot install PHP extensions from cPanel, as our PHP installations are custom built and are not managed by cPanel.

I still do not understand why you need this in production - it's a development tool and you should use it on your own home computer. Users cannot be given SSH access for security reasons.

In terms of the debugging, it's quite likely they have not switched away from using various depreciated code in light of the PHP 5.4 release, especially if they have an obligation to maintain legacy compatibility with PHP 4. This is not something for you to worry about.

Re: Joomla! CodeSniffer

PostPosted: Wed Jun 20, 2012 9:57 am
by JeanPierre
Thanks Max