Phpstorm. Reformat Code. Chain wrapper

I have some questions regarding reformatting phpstorm code.

I have a long line and one line.

$this->getSelect()->join('some_code_here')->join('some_code_here')->join('some_code_here')->join('some_code_here')->join('some_code_here'); $this->getSelect()->join('some_code_here')->join('some_code_here'); 

I want to configure a parameter:

Code Style / PHP / Wrapping and Bindings / Call Chains

This parameter has 4 options:

 Do not wrap (1) Wrap if long (2) Crop down if long (3) Wrap always (4) 

When I select 2 or 3, I have the following:

  $this->getSelect()->join('some_code_here')->join('some_code_here')->join('some_code_here')->join( 'some_code_here' )->join('some_code_here'); $this->getSelect()->join('some_code_here')->join('some_code_here'); 

When I choose the fourth, I have:

  $this->getSelect() ->join('some_code_here') ->join('some_code_here') ->join('some_code_here') ->join('some_code_here') ->join('some_code_here'); $this->getSelect() ->join('some_code_here') ->join('some_code_here'); 

My question is:

Is it possible to wrap each call from a new line only if the method is very long (more than 120 characters).

Expected Result:

  $this->getSelect() ->join('some_code_here') ->join('some_code_here') ->join('some_code_here') ->join('some_code_here') ->join('some_code_here'); $this->getSelect()->join('some_code_here')->join('some_code_here'); 
+7
phpstorm wrapping reformatting
source share
1 answer

To obtain the desired automatic formatting, use the following settings:

  • Editor> Code Style - Right margin (columns) - 120 [ screenshot ]
  • Editor> Code Style> PHP> Wrapper and brackets (tab) - Method call chains - Shorten if long [ screenshot ]

Note: To get the automatic formatting you need, follow these steps:

 $this->getSelect() ->join('some_code_here') ->join('some_code_here') ->join('some_code_here') ->join('some_code_here') ->join('some_code_here'); $this->getSelect()->join('some_code_here')->join('some_code_here'); 

you should start by calling the method with the chain longer than your right edge (i.e. 120 in your example):

 $this->getSelect()->join('some_code_here')->join('some_code_here')->join('some_code_here')->join('some_code_here')->join('some_code_here'); $this->getSelect()->join('some_code_here')->join('some_code_here'); 

If you automatically format calls with a chain with a length of less than 120 columns, the rule will not run, i.e. this is

 $this->getSelect() ->join('some_code_here')->join('some_code_here')->join('some_code_here') ->join('some_code_here')->join('some_code_here'); $this->getSelect()->join('some_code_here')->join('some_code_here'); 

will not invoke an automatic formatting rule, since calls with a chained call do not exceed 120 columns

0
source share

All Articles