| Conditions | 19 |
| Paths | 6144 |
| Total Lines | 57 |
| Code Lines | 42 |
| 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 |
||
| 80 | protected function write(array $record) |
||
| 81 | { |
||
| 82 | $previousUserContext = false; |
||
| 83 | $options = array(); |
||
| 84 | $options['level'] = $this->logLevels[$record['level']]; |
||
| 85 | $options['tags'] = array(); |
||
| 86 | if (!empty($record['extra']['tags'])) { |
||
| 87 | $options['tags'] = array_merge($options['tags'], $record['extra']['tags']); |
||
| 88 | unset($record['extra']['tags']); |
||
| 89 | } |
||
| 90 | if (!empty($record['context']['tags'])) { |
||
| 91 | $options['tags'] = array_merge($options['tags'], $record['context']['tags']); |
||
| 92 | unset($record['context']['tags']); |
||
| 93 | } |
||
| 94 | if (!empty($record['context']['fingerprint'])) { |
||
| 95 | $options['fingerprint'] = $record['context']['fingerprint']; |
||
| 96 | unset($record['context']['fingerprint']); |
||
| 97 | } |
||
| 98 | if (!empty($record['context']['logger'])) { |
||
| 99 | $options['logger'] = $record['context']['logger']; |
||
| 100 | unset($record['context']['logger']); |
||
| 101 | } else { |
||
| 102 | $options['logger'] = $record['channel']; |
||
| 103 | } |
||
| 104 | foreach ($this->getExtraParameters() as $key) { |
||
| 105 | foreach (array('extra', 'context') as $source) { |
||
| 106 | if (!empty($record[$source][$key])) { |
||
| 107 | $options[$key] = $record[$source][$key]; |
||
| 108 | unset($record[$source][$key]); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | if (!empty($record['context'])) { |
||
| 113 | $options['extra']['context'] = $record['context']; |
||
| 114 | if (!empty($record['context']['user'])) { |
||
| 115 | $previousUserContext = $this->ravenClient->context->user; |
||
| 116 | $this->ravenClient->user_context($record['context']['user']); |
||
| 117 | unset($options['extra']['context']['user']); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | if (!empty($record['contexts'])) { |
||
| 121 | $options['contexts'] = $record['contexts']; |
||
| 122 | } |
||
| 123 | if (!empty($record['extra'])) { |
||
| 124 | $options['extra']['extra'] = $record['extra']; |
||
| 125 | } |
||
| 126 | if (!empty($this->release) && !isset($options['release'])) { |
||
| 127 | $options['release'] = $this->release; |
||
| 128 | } |
||
| 129 | if (isset($record['context']['exception']) && ($record['context']['exception'] instanceof \Exception || (PHP_VERSION_ID >= 70000 && $record['context']['exception'] instanceof \Throwable))) { |
||
| 130 | $options['message'] = $record['formatted']; |
||
| 131 | $this->ravenClient->captureException($record['context']['exception'], $options); |
||
| 132 | } else { |
||
| 133 | $this->ravenClient->captureMessage($record['formatted'], array(), $options); |
||
| 134 | } |
||
| 135 | if ($previousUserContext !== false) { |
||
| 136 | $this->ravenClient->user_context($previousUserContext); |
||
| 137 | } |
||
| 140 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.