phpstorm - PSR2 code style and PHP Code Sniffer doesn't agreed? -


i have setup editor code style setup editor > code style > php predefined style >psr1/psr2. have php code sniffer , php mess detector installed , configured well. time format code using ctrl+alt+l following issue:

enter image description here

why that? original code looks (i think not helpful anyway here it's):

public function mytestfunction() {     $is_valid = true;      if ($this->manual_value && !$this->_inputvalidator->isvalidstring(             $this->manual_value,             1,             2,             regex::string         )     ) {         $is_valid = false;     }      return $is_valid; } 

psr2 doesn't multi-line if condition needs indented, phpstorm putting in 1 indent because lines inside if condition , 1 additional indent because lines inside multi-line function call.

psr2 does multi-line function calls must indented, says must indented once. documented here: https://github.com/php-fig/fig-standards/blob/master/accepted/psr-2-coding-style-guide.md#46-method-and-function-calls

so correct psr2 code this:

public function mytestfunction() {     $is_valid = true;      if ($this->manual_value && !$this->_inputvalidator->isvalidstring(         $this->manual_value,         1,         2,         regex::string     )     ) {         $is_valid = false;     }      return $is_valid; } 

but doesn't great.

what tend combine psr2 multi-line condition rules pear standard, give valid psr2 code:

public function mytestfunction() {     $is_valid = true;      if ($this->manual_value         && !$this->_inputvalidator->isvalidstring(             $this->manual_value,             1,             2,             regex::string         )     ) {         $is_valid = false;     }      return $is_valid; } 

i have no idea if phpstorm agree that, think might given indent rules appears have.

you can put && @ end of first line instead of @ start of second. code posted above pear coding standard uses, psr2 doesn't define rules this.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -