0

2 years ago I installed Joomla coding standard definition for PHP Codesniffer (https://github.com/joomla/coding-standards) for Sublime Text and everything worked well.

I just moved to a new laptop and set up a new development environment, now Joomla coding standard doesn't run when saving files.

Yes, PHP Code Sniffer was installed and works well. In my "Settings - User" I have

{
    "phpcs_additional_args": {
        "--standard": "Joomla",
        "-n": ""
    },
}

And this doesn't work. But if I change "Joomla" to "PSR2" then I get errors/warnings when saving files. So PHPCS works with PSR2 standard but not with Joomla standard.

If any developer here has any suggestion, please let me know. I really appreciate!

I use openSUSE 13.2 and Sublime Text 3.

This was how I installed Joomla standard, I assume it was successful :)

username@servername:~> sudo git clone https://github.com/joomla/coding-standards.git `pear config-get php_dir`/PHP/CodeSniffer/Standards/Joomla
root's password:
Cloning into '/usr/share/php5/PEAR/PHP/CodeSniffer/Standards/Joomla'...
remote: Counting objects: 1916, done.
remote: Total 1916 (delta 0), reused 0 (delta 0), pack-reused 1916
Receiving objects: 100% (1916/1916), 1.04 MiB | 117.00 KiB/s, done.
Resolving deltas: 100% (727/727), done.
Checking connectivity... done.

I'm not sure if it is related, but I get errors when running from command line. Hadn't try this way before.

username@servername:~> phpcs --standard=Joomla /srv/www/htdocs/joomla341/
PHP Fatal error:  Uncaught exception 'PHP_CodeSniffer_Exception' with message 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found' in /usr/share/php5/PEAR/PHP/CodeSniffer/Standards/Joomla/Sniffs/Commenting/FileCommentSniff.php:18
Stack trace:
#0 /usr/share/php5/PEAR/PHP/CodeSniffer.php(1318): include_once()
#1 /usr/share/php5/PEAR/PHP/CodeSniffer.php(560): PHP_CodeSniffer->registerSniffs(Array, Array)
#2 /usr/share/php5/PEAR/PHP/CodeSniffer/CLI.php(830): PHP_CodeSniffer->initStandard(Array, Array)
#3 /usr/share/php5/PEAR/PHP/CodeSniffer/CLI.php(95): PHP_CodeSniffer_CLI->process()
#4 /usr/bin/phpcs(25): PHP_CodeSniffer_CLI->runphpcs()
#5 {main}
  thrown in /usr/share/php5/PEAR/PHP/CodeSniffer/Standards/Joomla/Sniffs/Commenting/FileCommentSniff.php on line 18
  • 1
    What version of Code Sniffer are you using? – Lodder Mar 30 '15 at 13:16
  • Hi @Lodder I'm not sure how to get the version, but I see in the comment block in /usr/share/php5/PEAR/PHP/CodeSniffer/Sniff.php, it says "2.3.0". – Hung Tran Mar 30 '15 at 13:25
2

Joomla conding standards are created for PHP CodeSniffer 1.5.x.

pear install PHP_CodeSniffer-1.5.x

For instance, just yestearday I installed the latest 1.5.6 in Ubuntu with:

pear install PHP_CodeSniffer-1.5.6

In addition, you may want to copy the files from the repo http://joomla.github.io/coding-standards to the local directory where they are located:

pear config-get php_dir

In my system, coding standards are located in /usr/share/php/PHP/CodeSniffer/Standards

Ref: https://docs.joomla.org/Joomla_CodeSniffer#Installation

| improve this answer | |
  • Thank you @Anibal, I uninstalled PHPCS 2 and installed 1.5.6. I guess I run "pear install PHP_CodeSniffer" to the latest version was installed. But it was not enough yet, I needed to delete the folder /usr/share/php5/PEAR/PHP/CodeSniffer/Standards/Joomla, and git clone again. Now every works. My bad to miss the "Important note" in the git repo :). – Hung Tran Mar 31 '15 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.