| Conditions | 11 |
| Paths | 31 |
| Total Lines | 34 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 27 | public function log( $message, $level, $destination ='') |
||
| 28 | { |
||
| 29 | if ($this->debugLevel >= $level) |
||
| 30 | { |
||
| 31 | $message = '['. date("Y/m/d H:i:s") . '] ' . |
||
| 32 | '[TrapDirector] ['.$this->logLevels[$level].']: ' .$message . "\n"; |
||
| 33 | |||
| 34 | $output = ( $destination != '' ) ? $destination : $this->outputMode; |
||
| 35 | switch ($output) |
||
| 36 | { |
||
| 37 | case 'file': |
||
| 38 | file_put_contents ($this->outputFile, $message , FILE_APPEND); |
||
| 39 | break; |
||
| 40 | case 'syslog': |
||
| 41 | switch($level) |
||
| 42 | { |
||
| 43 | case 1 : $prio = LOG_ERR;break; |
||
| 44 | case 2 : $prio = LOG_WARNING;break; |
||
| 45 | case 3 : $prio = LOG_INFO;break; |
||
| 46 | case 4 : $prio = LOG_DEBUG;break; |
||
| 47 | default: $prio = LOG_ERR; |
||
| 48 | } |
||
| 49 | syslog($prio,$message); |
||
| 50 | break; |
||
| 51 | case 'display': |
||
| 52 | echo $message; |
||
| 53 | break; |
||
| 54 | default : // nothing we can do at this point |
||
| 55 | throw new Exception($message); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | if ($level == 1) |
||
| 59 | { |
||
| 60 | throw new Exception($message); |
||
| 61 | } |
||
| 121 | } |