Conditions | 19 |
Paths | 21 |
Total Lines | 52 |
Code Lines | 41 |
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 |
||
30 | public function log($level, $message, array $context = []) |
||
31 | { |
||
32 | if (is_array($message)) { |
||
33 | dump($message); |
||
34 | echo "Envoi de array comme message de log...\n"; |
||
35 | |||
36 | return; |
||
37 | } |
||
38 | $message = trim($message); |
||
39 | $date = date('Y-m-d H:i:s'); |
||
40 | switch ($level) { |
||
41 | case 'emergency': |
||
42 | case 'alert': |
||
43 | case 'critical': |
||
44 | $this->echoColor("[$level] ".$date.' : '.$message."\n", Color::BG_RED.Color::WHITE); |
||
45 | if ($context !== []) { |
||
46 | dump($context); |
||
47 | } |
||
48 | $this->logInFile($level, $message); |
||
49 | break; |
||
50 | case 'error': |
||
51 | case 'warning': |
||
52 | $this->echoColor("[$level] ".$date.' : '.$message."\n", Color::BG_YELLOW.Color::BLACK); |
||
53 | if ($context !== []) { |
||
54 | dump($context); |
||
55 | } |
||
56 | break; |
||
57 | case 'notice': |
||
58 | $this->echoColor("[$level] ".$message."\n"); |
||
59 | if ($context !== []) { |
||
60 | dump($context); |
||
61 | } |
||
62 | break; |
||
63 | case 'info': |
||
64 | if ($this->verbose || $this->debug) { |
||
65 | $this->echoColor("[$level] ".$message."\n", Color::GRAY); |
||
66 | if ($context !== []) { |
||
67 | dump($context); |
||
68 | } |
||
69 | } |
||
70 | break; |
||
71 | case 'debug': |
||
72 | if ($this->debug) { |
||
73 | $this->echoColor("[$level] ".$message."\n", Color::GRAY); |
||
74 | if ($context !== []) { |
||
75 | dump($context); |
||
76 | } |
||
77 | } |
||
78 | break; |
||
79 | case 'echo': |
||
80 | $this->echoColor($message."\n"); |
||
81 | break; |
||
82 | } |
||
105 |