| Conditions | 17 |
| Paths | 64 |
| Total Lines | 38 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 139 | protected function loadConfig( string$name, IConfigProvider$configProvider ) |
||
| 140 | { |
||
| 141 | $config= $configProvider->getConfig($this->nodeType.'_nodes',$name) ?: $configProvider->getConfig($this->nodeType.'_nodes','*'); |
||
| 142 | |||
| 143 | if( isset($config['multiple']) ){ |
||
| 144 | foreach( $config['multiple'] as $value ){ |
||
| 145 | if( $this->line->pregGet($value['pattern']) ){ |
||
| 146 | $config= $value; |
||
| 147 | break; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | if( isset($config['in']) ){ |
||
| 153 | $config=(function( array$config )use($name){ |
||
| 154 | foreach( $config['in'] as $key=>$value ){ |
||
| 155 | if( $this->document->scope && $this->document->scope->scope===$key ){ |
||
| 156 | $value['in_scope']= $key; |
||
| 157 | return $value; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | if( !isset($config['out']) ){ |
||
| 161 | $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',',array_keys($config['in']))); |
||
| 162 | } |
||
| 163 | return $config['out']; |
||
| 164 | })($config); |
||
| 165 | }elseif( isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope,$config['only_in'])) ){ |
||
| 166 | $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',',$config['only_in'])); |
||
| 167 | }elseif( isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope,$config['not_in'])) ){ |
||
| 168 | $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',',$config['not_in'])); |
||
| 169 | } |
||
| 170 | |||
| 171 | if( !is_array($config) ){$this->document->throw("The $this->nodeType node $name is not supported.");} |
||
| 172 | |||
| 173 | $this->config= $config; |
||
| 174 | |||
| 175 | return $this; |
||
| 176 | } |
||
| 177 | } |
||
| 178 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.