6

As the title says:

Is there a Netbeans/PHPStorm plugin for writing/refactoring to PSR-compilant code ?

phphint.org does exactly that, but offers only an online-copy&paste-tool, not an IDE-integrated real time solution.

What exactly i'm searching for is:

  1. "real time" PSR-code checking while typing
  2. reformating/refactoring projects to fit PSR (1/2) coding guidelines (as far as possible)

In case you are wondering what i'm talking about: PSR-1 Basic Coding Standard and PSR-2 Coding Style Guide are Coding Guidelines published by the big PHP guys.

Charles
  • 50,943
  • 13
  • 104
  • 142
Sliq
  • 15,937
  • 27
  • 110
  • 143

4 Answers4

10

For PhpStorm code formatting can be set to PSR1/PSR2 simply:
File -> Settings -> Code Style -> PHP -> Set From... -> Predefined Style -> PSR1/PSR2

Details are on the JetBrain's web site too.

And use Ctrl + Alt + L to reformat code.

Andron
  • 6,413
  • 4
  • 43
  • 56
5

Just have a look at Fabien Potenciers CS fixer at https://github.com/fabpot/PHP-CS-Fixer - I cannot tell you about the quality of the output, but as this seems to be a one time task, I don't think you'd need a plugin for this.

PHPStorm does format your code well to PSR standards by default, and it will also refactor stuff like missing curly braces for one-line if structures etc.

Sven
  • 69,403
  • 10
  • 107
  • 109
1

For the 2nd thing you ask, actually it's already built in Netbeans, you just have to configure it properly and hit ctrl+shift+F.

Beldar
  • 421
  • 1
  • 5
  • 10
0

In addition to above answer - we need to use external tool in phpStorm - step by step explanation to set it up on PHPStorm :

before we adding tool : we need to install php-cs-fixer globally

command line run : composer global require fabpot/php-cs-fixer once Installed you can test it by entering
command line run : php-cs-fixer

should give something like this what you see in command line

once all good - - go to PHPStorm - go to settings - External tools - add new tool

add the following as per image below

phpstorm new external tool settings

Program : /Users/seramo/.composer/vendor/bin/php-cs-fixer (global path to php-cs-fixer- you can navigate and select right path for you )

Parameters: fix $FilePathRelativeToProjectRoot$ --level=psr2 ( this is command to execute on file )

Working Directory : $ProjectFileDir$

now save and apply.

in you file - menu -tools - External Tools - php-cs-fixer

running this should fix you file to PSR-2 Standards.

additionally, you can assign key to run this tool.

jai
  • 541
  • 5
  • 8