| Conditions | 20 |
| Paths | 41 |
| Total Lines | 57 |
| Code Lines | 43 |
| 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 |
||
| 45 | public function log($level, $message, array $context = []): void |
||
| 46 | { |
||
| 47 | if (is_array($message)) { |
||
| 48 | $this->error('Array comme message de log...', ['message' => $message]); |
||
| 49 | |||
| 50 | return; |
||
| 51 | } |
||
| 52 | $message = trim($message); |
||
| 53 | $date = date('Y-m-d H:i:s'); |
||
| 54 | |||
| 55 | $this->incrementStatsFromContext($context); |
||
| 56 | if (isset($context['stats'])) { |
||
| 57 | unset($context['stats']); |
||
| 58 | } |
||
| 59 | |||
| 60 | switch ($level) { |
||
| 61 | case 'emergency': |
||
| 62 | case 'alert': |
||
| 63 | case 'critical': |
||
| 64 | $this->echoColor("[$level] " . $date . ' : ' . $message . "\n", Color::BG_RED . Color::WHITE); |
||
| 65 | if ($context !== []) { |
||
| 66 | dump($context); |
||
| 67 | } |
||
| 68 | $this->logInFile($level, $message); |
||
| 69 | break; |
||
| 70 | case 'error': |
||
| 71 | case 'warning': |
||
| 72 | $this->echoColor("[$level] " . $date . ' : ' . $message . "\n", Color::BG_YELLOW . Color::BLACK); |
||
| 73 | if ($context !== []) { |
||
| 74 | dump($context); |
||
| 75 | } |
||
| 76 | break; |
||
| 77 | case 'notice': |
||
| 78 | $this->echoColor("[$level] " . $message . "\n"); |
||
| 79 | if ($context !== []) { |
||
| 80 | dump($context); |
||
| 81 | } |
||
| 82 | break; |
||
| 83 | case 'info': |
||
| 84 | if ($this->verbose || $this->debug) { |
||
| 85 | $this->echoColor("[$level] " . $message . "\n", Color::GRAY); |
||
| 86 | if ($context !== []) { |
||
| 87 | dump($context); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | break; |
||
| 91 | case 'debug': |
||
| 92 | if ($this->debug) { |
||
| 93 | $this->echoColor("[$level] " . $message . "\n", Color::GRAY); |
||
| 94 | if ($context !== []) { |
||
| 95 | dump($context); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | break; |
||
| 99 | case 'echo': |
||
| 100 | $this->echoColor($message . "\n"); |
||
| 101 | break; |
||
| 102 | } |
||
| 139 |