| Conditions | 12 |
| Paths | 28 |
| Total Lines | 34 |
| Code Lines | 25 |
| 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 |
||
| 46 | public function log($level, $message, array $context = []): void |
||
| 47 | { |
||
| 48 | if (!empty($context['elapsed'])) { |
||
| 49 | $sql = strtolower($message); |
||
| 50 | if ( |
||
| 51 | strpos($sql, 'insert') === 0 || |
||
| 52 | strpos($sql, 'update') === 0 || |
||
| 53 | strpos($sql, 'delete') === 0 |
||
| 54 | ) { |
||
| 55 | $this->countWrites++; |
||
| 56 | } elseif (!$this->isPostgresSystemQuery($sql)) { |
||
| 57 | ++$this->countReads; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($level === LogLevel::ERROR) { |
||
| 62 | $this->print(" ! \033[31m" . $message . "\033[0m"); |
||
| 63 | } elseif ($level === LogLevel::ALERT) { |
||
| 64 | $this->print(" ! \033[35m" . $message . "\033[0m"); |
||
| 65 | } elseif (strpos($message, 'SHOW') === 0) { |
||
| 66 | $this->print(" > \033[34m" . $message . "\033[0m"); |
||
| 67 | } else { |
||
| 68 | if ($this->isPostgresSystemQuery($message)) { |
||
| 69 | $this->print(" > \033[90m" . $message . "\033[0m"); |
||
| 70 | |||
| 71 | return; |
||
| 72 | } |
||
| 73 | |||
| 74 | if (strpos($message, 'SELECT') === 0) { |
||
| 75 | $this->print(" > \033[32m" . $message . "\033[0m"); |
||
| 76 | } elseif (strpos($message, 'INSERT') === 0) { |
||
| 77 | $this->print(" > \033[36m" . $message . "\033[0m"); |
||
| 78 | } else { |
||
| 79 | $this->print(" > \033[33m" . $message . "\033[0m"); |
||
| 80 | } |
||
| 130 |