Wordpress PHP Code Sniffer in Netbeans

From GLMWiki
Jump to: navigation, search

PHPCS With WordPress Standards in Netbeans

There are a handful of steps that are needed before phpcs can be configured with netbeans


First, download / clone phpcs (PHP_CodeSniffer):

       git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs 

Next, download / clone wpcs:

       git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs

Now there should be two separate directories; phpcs and wpcs. phpcs alone does not include wordpress standards and will need to be configured to recognize them

        run this command from within your cloned  phpcs  directory:
               ./scripts/phpcs --config-set installed_paths ../wpcs   <--- this should include the wordpress standards in phpcs


In Netbeans:

      Tools > Options > PHP (tab) > Code Analysis 
            (browse for the phpcs script within the phpcs/scripts/phpcs directory you cloned and configured)
            You should be able to set the 'default standard' to wordpress after selecting the phpcs script

To Use / inspect a script against the WP conventions:

        While in the current file you want to inspect, navigate to Source > Inspect > Scope: Current file 
                                                                                      Use: Configuration 'Code Sniffer'

You should see a list of errors ( unless you're Linus Torvalds) in the inspector pane of your editor explaining your convention infractions