Showing posts with label php. phpcbf. Show all posts
Showing posts with label php. phpcbf. Show all posts

Monday, July 13, 2015

Fixing PSR2 errors with phpcbf and integration with Netbeans 8

I used my own style  formatting the code until now (I  am still using Notepad++ to edit my code, and I hit the TAB to indent  the code). I've read about the PSR-2 coding style guide and I want to follow it from now, but what  about the code already written? There is a solution for that :
PHP Code Sniffer and  PHP Code Beautifier and Fixer. On my home laptop I installed also NetBeans and I made efforts to integrate these static analysis tools with NetBeans 8 on Windows 7.

Some good articles about this topic:

http://blog.florianwolters.de/tutorial/2012/05/03/Integrate-tools-for-static-PHP-code-analyses-into-NetBeans-7.x/
https://blogs.oracle.com/netbeansphp/entry/static_code_analysis
 
 But still the mother fucker "phpcbf" was not fixing my code:

              "diff" is not recognized as an internal or external command....  



On Windows machines there is a problem with the --diff option (another reason to move to Linux), you need to specify  "--no-patch" http://stackoverflow.com/questions/24015486/fixing-psr2-errors-with-phpcbf-phar

I decided to run it form command line and not from NetBeans.  My phpcbf command to fix the errors was:


"..path.. to phpcbf.bat"  "fix" "--no-ansi" "--verbose" "--dry-run" "--no-patch" "--format=xml" "--no-interaction" "--level=psr2" "--config=sf20" "C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\myFrontController"

Inside the file "phpcbf.bat" you may need to add manually the path to php.exe and to phpcbf (with no extension)