| Conditions | 10 |
| Paths | 17 |
| Total Lines | 23 |
| 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 |
||
| 11 | public function log($level, $message, array $context = array()) |
||
| 12 | { |
||
| 13 | $severity = $level; |
||
|
|
|||
| 14 | switch($level) |
||
| 15 | { |
||
| 16 | case \Psr\Log\LogLevel::EMERGENCY: |
||
| 17 | case \Psr\Log\LogLevel::ALERT: |
||
| 18 | case \Psr\Log\LogLevel::CRITICAL: |
||
| 19 | case \Psr\Log\LogLevel::ERROR: |
||
| 20 | case \Psr\Log\LogLevel::WARNING: |
||
| 21 | case \Psr\Log\LogLevel::NOTICE: |
||
| 22 | case \Psr\Log\LogLevel::INFO: |
||
| 23 | case \Psr\Log\LogLevel::DEBUG: |
||
| 24 | break; |
||
| 25 | default: |
||
| 26 | throw new \Psr\Log\InvalidArgumentException('log function only accepts valid levels. Level was: '.$level); |
||
| 27 | } |
||
| 28 | if($this->shouldLog($level)) |
||
| 29 | { |
||
| 30 | $newMessage = $this->interpolate($message, $context); |
||
| 31 | error_log('['.$level.'] '.$newMessage); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } |
||
| 36 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.