PHP CodeSniffer for Netbeans v0.2

I finally found some time to spend some time on the PHP CodeSniffer for Netbeans plugin. Previously the plugin used an unnecessary API which restricted the use to Netbeans 6.7.0 only. This API was removed so that the plugin should now work with all Netbeans Versions >= 6.7.0.

Additionally when working the previous version would scan every PHP script on a file per file basis when the all projects or main projects filters were activated. This rendered made the plugin almost useless. In the current version scans of filters that contain more than one file are blocked. That means you will only see Coding Violations when you enable the "Current File" filter. Using any other filter will just do nothing and won't put your Netbeans in permanent hibernation mode (aka useless mode).

There is also some preference "phpcs.codingStandard" using the NbPreferences API which allows to configure the coding standard. However this feature was contributed by Manuel Piechler and I don't yet understand how I can manipulate it. Maybe someone knows how (*Looking in Mapis general direction*)? By default the Zend Coding Standard is used.

Update: Coding Standard can be changed by hacking into the config file .netbeans/6.7/config/Preferences.properties setting "phpcs.CodingStandard=". Additionally I fixed several bugs with the inline highlighting that did not refresh when lines in the file changed.

Share This Post

  • Share on Twitter
  • Facebook
  • Share on deli.cio.us
  • Share on Digg
  • Share on reddit
  • Share on StumbleUpon

Tags

This post is untagged.

Comments


arne riemann
Oct, 06. 2009

When iam trying to install the plugin, netbeans 6.7.1 tells me " The Plugin PHP Project is requested"



beberlei
Oct, 06. 2009

Gah still?

Sucks! I am looking into it this evening, bare with me please :-) Being a Java/Netbeans noobie its quite hard to know where to look and configure ;-)



stloyd
Oct, 06. 2009

Maybe you should list plugins what you use in you netbeans so we could try to help you remove this dependency or install it at ours netbeans instances :-)



honza
Oct, 06. 2009

Could you point me at a howto about installing this plugin? I've had no luck with http://wiki.netbeans.org/InstallingAPlugin ... thanks



stloyd
Oct, 06. 2009

@honza
1. Download plugin from http://github.com/beberlei/netbeans-php-enhancements/
2. Run Netbeans atleast 6.7 (plugin its not working with 6.7.1 as you can read),
3. Select menu "Tools - Plugins", then go to "Downloaded" section and select file by clicking and "Add Plugins" button,
4. Proceed instalation,
5. HF :-)



hozna
Oct, 06. 2009

@stloyd Thanks!



hiskingdomcomes
Oct, 06. 2009

I've installed the plugin on 6.7.1 and have PHP support installed. The plugin does install properly. But how do I configure the thing? I can't find anything about "Todo Lists". Can you please describe a step by step howto on how to proceed at least after the installation? Because to me, it's not intuitive enough. Thanks.

- HisKindomComes -



hiskingdomcomes
Oct, 06. 2009

I'm sorry. I've found the 'Tasks' window now and I could proceed with clicking 'Current File' and selecting 'PHP Coding Standards' in the menu. Thanks anyway.

- HisKingdomComes -



hiskingdomcomes
Oct, 06. 2009

I hate to say this, but this plugin for Netbeans is not working properly under Windows. It's running OK, but it can't find the correct executable...

Caused: java.io.IOException: Cannot run program "C:\wamp\bin\php\php5.3.0\phpcs" (in directory "C:\wamp\www\todomanager\public_html\protected\controller"): CreateProcess error=.....

phpcs.bat is a DOS-Batch (.bat) file and won't execute as a Windows 32 executable. If I strip the extension, I've to rename the phpcs which is a PHP file that handles the call to the PHP_Code_Sniffer libraries.

I don't know how to solve this. I would love to use this functionality, but for now I just do it on the commandline.

BTW, is it possible to pass along the standards to sniff?

Thanks.

- HisKingdomComes -



nubeiro
Oct, 06. 2009

Nice plugin, as others have pointed out, only works for nb 6.7.
It would be great to be able to configure the standard to sniff.
I've been tinkering with properties files under config/Preferences with no luck :-S
Anyone?



nubeiro
Oct, 07. 2009

Thanks a lot for the update.
Now the problem is that the plugin overwrites user configuration :-S
Already opened an issue on github repository (thought that would help)



hiskingdomcomes
Oct, 07. 2009

For those people out there using Netbeans under Vista (or maybe any Windows) and are having trouble to execute the phpcs.bat executable this is what I did:

Find the phpcs file (no extension). Actually this is a PHP file, so add the extension (.php) to it. Open up the phpcs.bat file and modify the line where it calls the phpcs file (no extension) by adding the extension you just added. This way the bat file will correctly call the phpcs.php file and not get in conflict with the Netbeans call to a Win32-application phpcs executable.

Then, download a bat-to-exe converter from Fatih Kodak. It's freeware, very simple and effective. The phpcs.bat is very simple so it should convert properly. You can first run the converter through a anti-virus scanner to see it is a clean file. I've downloaded the converter from Fatih's own website: http://www.f2ko.de/English/b2e/index.php

Let the converter create a phpcs.exe file in the same directory as the phpcs.bat file. Leave it as is. No further changes should (have to) be made.

Go back to your Netbeans and Right-Click on your file in the editor and choose "Show Code Standard Violations" and see if it works. You shouldn't get any warning on the right-bottom anymore.

NOTE: I use Netbeans 6.7.1 on Vista with PHP 5.3.0 and the most recent PHP Codesniffer (1.2.0 stable) from PEAR.

I hope this helps!

- HisKingdomComes -



hiskingdomcomes
Oct, 07. 2009

Sorry to bother you this much, but I really find this plugin interesting. So, therefore, I tell you that the Preferences.properties are overwritten when Netbeans starts. It reverts back to Zend somehow and that's inconvenient.

- HisKingdomComes -



hiskingdomcomes
Oct, 07. 2009

Ah, I forgot to check the GitHub first. I see you submitted an issue yourself about the same topic. Next time, I first check GitHub ;-)

- HisKingdomComes -



maikl
Oct, 15. 2009

Where can I put my own CS files and in which format? Our programming was in the last time a litte bit lazy, so I don“t want to be too harsh to my colleges (and me). And we have the the brackets after the "if" alsways on a new line. So where am I able to set these settings?
Its a great thing to check the code maschinable but only with my own coding standards.



b_aaa_b
Nov, 27. 2009

Does the plugin work with Netbeans version 6.8 M2?
I try to "Add Plugins" but I see nothing.



b_aaa_b
Nov, 27. 2009

Sorry, I didn't see this article http://www.whitewashing.de/blog/articles/122



stephane
Apr, 08. 2010

I'm having an issue with the PHP Coding Standard plugin on my Linux box under Netbeans 6.8.

I could install the plugin fine from the de-whitewashing-php-cs.nbm file then activate the Default filter in the Task window with the PHP Coding Standards checkbox ticked all right.

But the taskt list is still empty.

And right clicking on the source code file show a greyed out menu item Show Code Standards Violations.

So I can't get to using it yet.. tough luck.

I restarted Netbeans to no effect.



Adrian
Jul, 09. 2010

Thx again, it works fine with 6.8. and 6.9.
:-)


Write a Comment