1

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 ?

Kiloumap Mrz
  • 2,133
  • 1
  • 9
  • 18
  • `Code | Reformat Code...`. If you invoke it from Project View panel, then this action will be applied to the selected files / whole folder. – LazyOne Nov 02 '18 at 10:55
  • Actual PSR-2 code style can be set at `Settings/Preferences | Editor | Code Style | PHP` -- there is `Set from...` link on right top side of the screen. – LazyOne Nov 02 '18 at 10:56
  • thanks for your help. I've already checked in code style, it's not working for line breaker. I haven't see anything about that. I can only manage space, tab... Even if i fix psr-2 on the set form button. – Kiloumap Mrz Nov 02 '18 at 11:02
  • 1
    It works with line breaks. Maybe you have `Keep when reformatting | Line breaks` checked? Please share your code style + 1 file that needs to be formatted (full file, share a link, not just copy-paste here) – LazyOne Nov 02 '18 at 11:36
  • Oh thanks LazyOne, I have'nt see it, i'm blind ... Thanks a lot ! you save to me many hours :P – Kiloumap Mrz Nov 02 '18 at 11:40

1 Answers1

3

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.

LazyOne
  • 158,824
  • 45
  • 388
  • 391