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