| Conditions | 19 |
| Paths | 6144 |
| Total Lines | 72 |
| Lines | 10 |
| Ratio | 13.89 % |
| 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 |
||
| 105 | protected function write(array $record): void |
||
| 106 | { |
||
| 107 | $previousUserContext = false; |
||
| 108 | $options = []; |
||
| 109 | $options['level'] = $this->logLevels[$record['level']]; |
||
| 110 | $options['tags'] = []; |
||
| 111 | |||
| 112 | if (!empty($record['extra']['tags'])) { |
||
| 113 | $options['tags'] = array_merge($options['tags'], $record['extra']['tags']); |
||
| 114 | unset($record['extra']['tags']); |
||
| 115 | } |
||
| 116 | |||
| 117 | View Code Duplication | if (!empty($record['context']['tags'])) { |
|
| 118 | $options['tags'] = array_merge($options['tags'], $record['context']['tags']); |
||
| 119 | unset($record['context']['tags']); |
||
| 120 | } |
||
| 121 | |||
| 122 | if (!empty($record['context']['fingerprint'])) { |
||
| 123 | $options['fingerprint'] = $record['context']['fingerprint']; |
||
| 124 | unset($record['context']['fingerprint']); |
||
| 125 | } |
||
| 126 | |||
| 127 | View Code Duplication | if (!empty($record['context']['logger'])) { |
|
| 128 | $options['logger'] = $record['context']['logger']; |
||
| 129 | unset($record['context']['logger']); |
||
| 130 | } else { |
||
| 131 | $options['logger'] = $record['channel']; |
||
| 132 | } |
||
| 133 | |||
| 134 | foreach ($this->getExtraParameters() as $key) { |
||
| 135 | foreach (['extra', 'context'] as $source) { |
||
| 136 | if (!empty($record[$source][$key])) { |
||
| 137 | $options[$key] = $record[$source][$key]; |
||
| 138 | unset($record[$source][$key]); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | if (!empty($record['context'])) { |
||
| 144 | $options['extra']['context'] = $record['context']; |
||
| 145 | if (!empty($record['context']['user'])) { |
||
| 146 | $previousUserContext = $this->ravenClient->context->user; |
||
| 147 | $this->ravenClient->user_context($record['context']['user']); |
||
| 148 | unset($options['extra']['context']['user']); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | if (!empty($record['contexts'])) { |
||
| 153 | $options['contexts'] = $record['contexts']; |
||
| 154 | } |
||
| 155 | |||
| 156 | if (!empty($record['extra'])) { |
||
| 157 | $options['extra']['extra'] = $record['extra']; |
||
| 158 | } |
||
| 159 | |||
| 160 | if (!empty($this->release) && !isset($options['release'])) { |
||
| 161 | $options['release'] = $this->release; |
||
| 162 | } |
||
| 163 | |||
| 164 | if (isset($record['context']['exception']) && ($record['context']['exception'] instanceof \Exception || (PHP_VERSION_ID >= 70000 && $record['context']['exception'] instanceof \Throwable))) { |
||
| 165 | $options['extra']['message'] = $record['formatted']; |
||
| 166 | $this->ravenClient->captureException($record['context']['exception'], $options); |
||
| 167 | } else { |
||
| 168 | $this->ravenClient->captureMessage($record['formatted'], [], $options); |
||
| 169 | } |
||
| 170 | |||
| 171 | $this->ravenClient->breadcrumbs->reset(); |
||
| 172 | |||
| 173 | if (false !== $previousUserContext) { |
||
| 174 | $this->ravenClient->user_context($previousUserContext); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 |