| Conditions | 13 |
| Paths | 37 |
| Total Lines | 33 |
| Code Lines | 26 |
| 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 |
||
| 53 | public function log($level, $message, array $context = array()) : void |
||
| 54 | { |
||
| 55 | // check, if requested level should be logged |
||
| 56 | // causes InvalidArgumentException in case of unknown level. |
||
| 57 | if (!$this->logLevel($level)) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | $strMessage = 'PHP-' . strtoupper($level) . ': ' . $this->replaceContext($message, $context); |
||
| 61 | switch ($level) { |
||
| 62 | case LogLevel::EMERGENCY: |
||
| 63 | case LogLevel::ALERT: |
||
| 64 | case LogLevel::CRITICAL: |
||
| 65 | case LogLevel::ERROR: |
||
| 66 | $this->fb->error($strMessage); |
||
| 67 | break; |
||
| 68 | case LogLevel::WARNING: |
||
| 69 | $this->fb->warn($strMessage); |
||
| 70 | break; |
||
| 71 | case LogLevel::NOTICE: |
||
| 72 | $this->fb->log($strMessage); |
||
| 73 | break; |
||
| 74 | case LogLevel::INFO: |
||
| 75 | $this->fb->info($strMessage); |
||
| 76 | break; |
||
| 77 | case LogLevel::DEBUG: |
||
| 78 | $this->fb->log($strMessage); |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | if (count($context) > 0) { |
||
| 82 | foreach ($context as $key => $value) { |
||
| 83 | // only add, if not included as placeholder in the mesage |
||
| 84 | if (strpos($message, '{' . $key . '}') === false) { |
||
| 85 | $this->fb->log($value, $key); |
||
| 86 | } |
||
| 91 |