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