whitewashing.de

PHP CodeSniffer for Netbeans v0.2

05. October 2009

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.

:: Category: PHP, Comments (17)

Comments (17)

When iam trying to install the plugin, netbeans 6.7.1 tells me " The Plugin PHP Project is requested" User: arne riemann - Date: 2009/10/06 09:33
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 ;-) User: beberlei - Date: 2009/10/06 10:08
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 :-) User: stloyd - Date: 2009/10/06 10:25
Could you point me at a howto about installing this plugin? I've had no luck with http://wiki.netbeans.org/InstallingAPlugin ... thanks User: honza - Date: 2009/10/06 10:39
@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 :-) User: stloyd - Date: 2009/10/06 11:06
@stloyd Thanks! User: hozna - Date: 2009/10/06 14:09
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 - User: hiskingdomcomes - Date: 2009/10/06 15:49
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 - User: hiskingdomcomes - Date: 2009/10/06 16:10
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:wampbinphpphp5.3.0phpcs" (in directory "C:wampwwwtodomanagerpublic_htmlprotectedcontroller"): 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 - User: hiskingdomcomes - Date: 2009/10/06 16:28
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? User: nubeiro - Date: 2009/10/06 16:57
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)
User: nubeiro - Date: 2009/10/07 09:30
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 - User: hiskingdomcomes - Date: 2009/10/07 11:07
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 - User: hiskingdomcomes - Date: 2009/10/07 14:36
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 - User: hiskingdomcomes - Date: 2009/10/07 14:38
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. User: maikl - Date: 2009/10/15 11:50
Does the plugin work with Netbeans version 6.8 M2?
I try to "Add Plugins" but I see nothing. User: b_aaa_b - Date: 2009/11/27 16:24
Sorry, I didn't see this article http://www.whitewashing.de/blog/articles/122 User: b_aaa_b - Date: 2009/11/27 21:36

Post A Comment

 
 
 
 
::Back To The Top