PHPsrc / PHP-Tool-Integration

On one site there exists many good PHP tools such as PHPUnit or PHP CodeSniffer which support the development of PHP scripts. On the other side there powerful IDEs for example PHP Delepment Tools Project (PDT) but mostly with no possibility to use such tools with them. The Eclipse PHP Tool Integration (PTI) is a collection of Eclipse plugins which aims to close this gap.
19 stars 7 forks source link

PSR1 and PSR2 standards are missing #7

Open glen-84 opened 8 years ago

glen-84 commented 8 years ago

Does this plug-in use an old version of PHP CodeSniffer?

borgogelli commented 8 years ago

Issue confirmed under Eclipse Neon

binarious commented 7 years ago

I got around that by forcing my locally installed CodeSniffer:

/Applications/Eclipse.app/Contents/Eclipse/plugins/org.phpsrc.eclipse.pti.tools.codesniffer_1.3.0.R20111119000000/php/tools/phpcs.php

Change include line to the following:

include_once '/Users/youruser/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/CLI.php';

After that I referenced PSR2 in the settings via this path:

/Users/youruser/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR2
Kallys commented 7 years ago

Definitely, this plugin uses an old version of PHP_CodeSniffer : with eclipse Neon 4.3 and PDT 4.3, I got PHP_CodeSniffer 1.3, released in 2011... (latest release is 2.8.1, march 2017)

After trying many workarounds like installing PEAR manually, working aroung with "pti_phpcs.launch" file, etc. I was about to give up to get PSR2 support in eclipse, until I ended up on @binarious answer. His workaround actually still works! Thanks!

So here is another way (which I found less hacky) to update PHP_CodeSniffer support in eclipse with PTI (so it's working with PDT-ext):

  1. Find where the PHP_CodeSniffer execution file ('phpcs.php') is. It depends on your eclipse installation. You can use the "print PHP output to console" in "PHP CodeSniffer" properties in eclipse. Mine was here: /opt/.p2/pool/plugins/org.phpsrc.eclipse.pti.tools.codesniffer_1.3.0.R20111119000000/php/tools/phpcs.php
  2. Make a symbolic link in the php folder (parent of parent of 'phpcs.php') to your PHP_CodeSniffer installation path. No need to edit the phpcs.php file since it is actually searching for a local installation of PHP_CodeSniffer inside the php folder. ln -s /opt/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer /opt/.p2/pool/plugins/org.phpsrc.eclipse.pti.tools.codesniffer_1.3.0.R20111119000000/php/
  3. Manually add wanted standards from your PHP_CodeSniffer installation in eclipse preferences. Press New, name it (eg: "PSR1"), set path (eg: /opt/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR1)
  4. Enjoy!

Note: Installation methods of PHP_CodeSniffer. I used composer global installation, adapt your paths depending on your installation.


Edit: you could also consider using this fork.