Netbeans PHP CodeSniffer Plugin: Now with Options Dialog

Just two days before the International PHP Conference 09 will start I got an email from alexandrehaguiar that he forked my Netbeans PHP CodeSniffer plugin and added the long awaited Options screen. This is just awesome! This way I don't have to ask the Netbeans guys at IPC all the questions about how to implement it. I merged the changes back into my branch and released a new version which also fixed another small bug. For me it works with both Netbeans 6.7.1 and 6.8 Beta. I want to thank alexandre very much for this awesome contribution.

What you can do now is chose the Coding Standard you want to use in an Options Dialog under the "Miscallenous" button. You can choose from a list of pre-defined standards, or even enter your own if you use one. Additionally you can disable that warning are shown, so that with any given coding standard you only see the errors.

You can download the new version from the Github Project Downloads page.

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


petr
Nov, 15. 2009

Keep the good work guys. It's nice to see that community is starting write plugins for php support in Netbeans.



ken guest
Nov, 17. 2009

This is nice. How are you populating the dropdown list? I think you might not be using "phpcs -i" because the in-house Standard that we've installed isn't present in it, although it is listed when one does a "phpcs -i".



alexandre haguiar
Nov, 17. 2009

Hi,

Actually the dropdown list is populate manualy but you can pass a custom standard if you want. This solution "phpcs -i" its possible but i think will need a new input in options to point the executable "phpcs" to make this solution OS independent.



alexandre haguiar
Nov, 17. 2009

Hi,

Actually the dropdown list is populate manualy but you can pass a custom standard if you want. This solution "phpcs -i" its possible but i think will need a new input in options to point the executable "phpcs" to make this solution OS independent.



pettrinetz
Nov, 19. 2009

Hi,

I've installed pear code sniffer and plugin, but "Show Code Standard Violations" is grayed out.
Can anyone explain how to install hole thing and what is required?

Thanks



b_aaa_b
Nov, 28. 2009

You must install PHP_CodeSniffer.

pear install PHP_CodeSniffer-1.2.1

http://pear.php.net/package/PHP_CodeSniffer/download



pettrinetz
Nov, 29. 2009

As I said, I've installed pear install PHP_CodeSniffer-1.2.1 and it doesn't work



mwesten
Dec, 10. 2009

Same problem here.
OSX 10.6 installed PHP_Codesniffer trough PEAR.
Installed NB plugin.
I see the option, but it's grayed out.....



mwesten
Dec, 10. 2009

I'm using NetBeans 6.8 RC2



fedegar33
Dec, 13. 2009

Hi, first thanks for your work.
I'm having a problem with the plugin.
I installed the PEAR plugin and the Netbeans plugin but when i click in " Code Standard Violations" netbeans throws an exception.
I have this problem in both 6.7.1 and 6.8.
Thanks again!



beberlei
Dec, 14. 2009

@mwesten @fedegar33 @pettrinetz

There does seem to be some problems with the Java version of the plugin. I used Java 1.6, which apparrently you shouldnt when building a plugin for Netbeans. I got quite a huge patch by Petr Pisl, which he hacked for meon IPC 09 this year, which should solve most issues. However since then I havent been able to compile the thing and repackage it. Please bear with me, a new version will be released sometime soon!



phil
Feb, 01. 2010

Whenever I try to run it I just get the exception:
java.io.IOException: CreateProcess: C:\xampp\php\phpcs --standard=Zend --report=xml application_top.php error=193

If I try the command from command line it runs, except it cant find the file since the full path isn't used.

Netbeans 6.8 on Windows



fernanda
Feb, 04. 2010

Hi Beberlei's,

I developed its own pattern, so wish I could insert it in the drop-down list of standards. This would be possible?

Hug and congratulations for the work



darren
Feb, 12. 2010

I can't find it mentioned anywhere but the Code Sniffer option is actually under the "PHP" button instead of the "Miscellaneous" button on the current version of this plugin in Netbeans 6.8 on Leopard.



gavin
Feb, 17. 2010

I can't get this working on Windows; it may be because it's trying to run "phpcs" rather than the "phpcs.bat" wrapper script:

...
java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
Caused: java.io.IOException: Cannot run program "C:\php\php-5.3.1-nts-Win32-VC9-x86\phpcs" (in directory "C:\www\formResponses\private\inc\component\desktopComponent\desktopAppElement\FormResponses"): CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessBuilder.start(Unknown Source)
at org.netbeans.api.extexecution.ExternalProcessBuilder.call(ExternalProcessBuilder.java:293)
at org.netbeans.api.extexecution.ExternalProcessBuilder.call(ExternalProcessBuilder.java:72)
at org.netbeans.api.extexecution.ExecutionService$3.call(ExecutionService.java:254)
...



gavin
Feb, 17. 2010

I got this working on Windows, see http://github.com/beberlei/netbeans-php-enhancements/issues#issue/3

Hope this helps someone out



savageman
Mar, 09. 2010

Well, very nice job. It works perfectly using predifined standards (Zend, pear, ...). I'm just wondering how to add my own Code Sniffer : my firm use one and I need to check against these standards rather than Zend or pear.
The article says "You can choose from a list of pre-defined standards, or even enter your own if you use one." but I could not manage to enter my own...
Just a little how-to use "MySource" would be awesome.
Thanks! ;)



katsuke
Mar, 23. 2010

Am having an issue that i don't quite understand, at first i installed the plugin correctly and it worked perfectly, but apparently something i did made the option of "Show Code Standard Violations" become disabled (grayed out) Any suggestions on how to reactivate it?

Netbeans 6.8 Windows XP



katsuke
Mar, 23. 2010

Just solved it, apparently the call:

public static final String BINARY = "phpcs"; //NOI18N
on CodeSnifferBinary.java line: 17

Does not work with my configuration, (i converted my phpcs.bat into a phpcs.exe following - HisKingdomComes - suggestion of using bat-to-exe converter from Fatih Kodak.)

So i changed the call to:

public static final String BINARY = "phpcs.bat"; //NOI18N

Recompiled, and substituted the file:
c:\documents and settings\user\.netbeans\6.8\modules\de-whitewashing-php-cs.jar

Its fully working again. Not quite sure why it worked in the first try, maybe something with the PATH.

Hope this helps someone if they encounter the same issue.



iwanluijks
Apr, 08. 2010

Getting this exception:
java.io.IOException: CreateProcess error=193, %1 is geen geldige Win32-toepassing
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
Caused: java.io.IOException: Cannot run program "C:\Dev\PHP\phpcs" (in directory "L:\trouwplannen"): CreateProcess error=193, %1 is geen geldige Win32-toepassing
at java.lang.ProcessBuilder.start(Unknown Source)
at org.netbeans.api.extexecution.ExternalProcessBuilder.call(ExternalProcessBuilder.java:293)
at org.netbeans.api.extexecution.ExternalProcessBuilder.call(ExternalProcessBuilder.java:72)
at org.netbeans.api.extexecution.ExecutionService$3.call(ExecutionService.java:254)
Caused: org.netbeans.api.extexecution.ExecutionService$WrappedException
at org.netbeans.api.extexecution.ExecutionService$3.call(ExecutionService.java:294)
at org.netbeans.api.extexecution.ExecutionService$3.call(ExecutionService.java:230)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused: java.util.concurrent.ExecutionException
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at de.whitewashing.php.cs.CodeSniffer.execute(CodeSniffer.java:84)
at de.whitewashing.php.cs.CodeSnifferAction.performAction(CodeSnifferAction.java:32)
at org.openide.util.actions.NodeAction.performAction(NodeAction.java:296)
at org.openide.util.actions.CallableSystemAction$1.run(CallableSystemAction.java:127)
at org.netbeans.modules.openide.util.ActionsBridge.implPerformAction(ActionsBridge.java:83)
at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(ActionsBridge.java:64)
at org.openide.util.actions.CallableSystemAction.actionPerformed(CallableSystemAction.java:123)
at org.openide.util.actions.NodeAction.actionPerformed(NodeAction.java:284)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
[catch] at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:125)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)



anedo
Apr, 29. 2010

Getting this error when setting the phpcs path in the Netbeans 6.9beta1 (MaxOSX) options (the "Standard" menu is empty):


java.lang.NullPointerException
at org.netbeans.core.startup.preferences.NbPreferences.put(NbPreferences.java:155)
at de.whitewashing.php.cs.ui.options.CodeSnifferOptions.setCodingStandard(CodeSnifferOptions.java:49)
at de.whitewashing.php.cs.ui.options.CodeSnifferOptionsPanel.store(CodeSnifferOptionsPanel.java:137)
at de.whitewashing.php.cs.ui.options.CodeSnifferOptionsPanelController.applyChanges(CodeSnifferOptionsPanelController.java:28)
at org.netbeans.modules.options.TabbedController.applyChanges(TabbedController.java:126)
at org.netbeans.modules.options.CategoryModel$Category.applyChanges(CategoryModel.java:387)
at org.netbeans.modules.options.CategoryModel$Category.access$1000(CategoryModel.java:316)
at org.netbeans.modules.options.CategoryModel.save(CategoryModel.java:215)
at org.netbeans.modules.options.OptionsPanel.save(OptionsPanel.java:207)
at org.netbeans.modules.options.OptionsDisplayerImpl$OptionsPanelListener.actionPerformed(OptionsDisplayerImpl.java:331)
at org.netbeans.core.windows.services.NbPresenter$ButtonListener.actionPerformed(NbPresenter.java:1292)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
at javax.swing.plaf.basic.BasicRootPaneUI$Actions.actionPerformed(BasicRootPaneUI.java:191)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1638)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2839)
at javax.swing.KeyboardManager.fireBinding(KeyboardManager.java:267)
at javax.swing.KeyboardManager.fireKeyboardAction(KeyboardManager.java:216)
at javax.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:2916)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2908)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2802)
at java.awt.Component.processEvent(Component.java:6125)
at java.awt.Container.processEvent(Container.java:2085)
at java.awt.Component.dispatchEventImpl(Component.java:4714)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Component.dispatchEvent(Component.java:4544)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
at java.awt.Component.dispatchEventImpl(Component.java:4586)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4544)
[catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:133)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)



chilicheech
Jul, 02. 2010

Using this plugin on NetBeans 6.9 on Mac OSX 10.5.8 with Java SE 6 the context menu item "Show Code Standard Violations" was greyed out. This was because phpcs' path wasn't set in the plugin's preferences. Upon attempting to set it NetBeans threw an exception. So, I manually set the path in "/Users//.netbeans/6.9/config/Preferences/de/whitewashing/php/cs.properties". The setting is:

phpcs.shellScript=/usr/local/bin/phpcs

Save the file, close and reopen NetBeans, and now the menu option is no longer greyed out and I am able to set the path in the plugin's preference pane.

Is it possible that the code is trying to set this setting without first creating it if it's not already present?

Here's the exception I was getting:

Getting this error when setting the phpcs path in the Netbeans 6.9 (MaxOSX) options (the "Standard" menu is empty):


java.lang.NullPointerException
at org.netbeans.core.startup.preferences.NbPreferences.put(NbPreferences.java:155)
at de.whitewashing.php.cs.ui.options.CodeSnifferOptions.setCodingStandard(CodeSnifferOptions.java:49)
at de.whitewashing.php.cs.ui.options.CodeSnifferOptionsPanel.store(CodeSnifferOptionsPanel.java:137)
at de.whitewashing.php.cs.ui.options.CodeSnifferOptionsPanelController.applyChanges(CodeSnifferOptionsPanelController.java:28)
at org.netbeans.modules.options.TabbedController.applyChanges(TabbedController.java:126)
at org.netbeans.modules.options.CategoryModel$Category.applyChanges(CategoryModel.java:387)
at org.netbeans.modules.options.CategoryModel$Category.access$1000(CategoryModel.java:316)
at org.netbeans.modules.options.CategoryModel.save(CategoryModel.java:215)
at org.netbeans.modules.options.OptionsPanel.save(OptionsPanel.java:207)
at org.netbeans.modules.options.OptionsDisplayerImpl$OptionsPanelListener.actionPerformed(OptionsDisplayerImpl.java:331)
at org.netbeans.core.windows.services.NbPresenter$ButtonListener.actionPerformed(NbPresenter.java:1292)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
at javax.swing.plaf.basic.BasicRootPaneUI$Actions.actionPerformed(BasicRootPaneUI.java:191)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1638)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2839)
at javax.swing.KeyboardManager.fireBinding(KeyboardManager.java:267)
at javax.swing.KeyboardManager.fireKeyboardAction(KeyboardManager.java:216)
at javax.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:2916)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2908)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2802)
at java.awt.Component.processEvent(Component.java:6125)
at java.awt.Container.processEvent(Container.java:2085)
at java.awt.Component.dispatchEventImpl(Component.java:4714)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Component.dispatchEvent(Component.java:4544)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
at java.awt.Component.dispatchEventImpl(Component.java:4586)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4544)
[catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:133)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Write a Comment