PhpStorm: Auto-format with line breaker

737 views Asked by At

I'm working on a new project with existing sources. And the guy who's writte code used a weird format code. See bellow :

     public function analyzeCalcul 
                       (   $calcul
                         , $selection
                       ) {
    $pattern                 = "/[0-9".$this -> revertSymbol."?]+/" ;
    preg_match_all ($pattern, $calcul, $out) ;
    // on regarde les numeros de questions
    if (!count ($out)) {
      $OneErrorToAff         = ErrorModel::newError () ;
      $OneErrorToAff -> AffOneError
              (   __LINE__
                , __FILE__
                , __CLASS__
                , "pattern pour le calcul de facette non trouvé ???"
              ) ;
      throw new Exception ($OneErrorToAff -> getStrError ()) ;
    }
   }

For my opinion, is not human readable, to many line breaker it's insane :O I want format it in PSR 2, I can do it one file by file but the project is kind of big so I'm looking for an automation of it.

I tried many online tools but only file by file. I used PhpStorm, and I don't see any tricks for thoose line breaker.

Any suggestion about it ?

1

There are 1 answers

0
LazyOne On BEST ANSWER

Use Code | Reformat Code... for your code formatting needs.

If invoked from the Project View panel, this action will be applied to the selected files / whole folder.


Actual PSR-2 code style can be set at Settings/Preferences | Editor | Code Style | PHP -- there is Set from... clickable text on right top side of the screen.

P.S. Ensure that your have Code Style | PHP | Wrapping and Braces | Keep when reformatting | Line breaks option disabled.