Conditions | 19 |
Paths | 6144 |
Total Lines | 74 |
Code Lines | 44 |
Lines | 10 |
Ratio | 13.51 % |
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 |
||
49 | protected function write(array $record) |
||
50 | { |
||
51 | $previousUserContext = false; |
||
52 | $options = []; |
||
53 | $options['level'] = $this->logLevels[$record['level']]; |
||
54 | $options['tags'] = []; |
||
55 | |||
56 | if (!empty($record['extra']['tags'])) { |
||
57 | $options['tags'] = array_merge($options['tags'], $record['extra']['tags']); |
||
58 | unset($record['extra']['tags']); |
||
59 | } |
||
60 | |||
61 | View Code Duplication | if (!empty($record['context']['tags'])) { |
|
62 | $options['tags'] = array_merge($options['tags'], $record['context']['tags']); |
||
63 | unset($record['context']['tags']); |
||
64 | } |
||
65 | |||
66 | if (!empty($record['context']['fingerprint'])) { |
||
67 | $options['fingerprint'] = $record['context']['fingerprint']; |
||
68 | unset($record['context']['fingerprint']); |
||
69 | } |
||
70 | |||
71 | View Code Duplication | if (!empty($record['context']['logger'])) { |
|
72 | $options['logger'] = $record['context']['logger']; |
||
73 | unset($record['context']['logger']); |
||
74 | } else { |
||
75 | $options['logger'] = $record['channel']; |
||
76 | } |
||
77 | |||
78 | foreach ($this->getExtraParameters() as $key) { |
||
79 | foreach (['extra', 'context'] as $source) { |
||
80 | if (!empty($record[$source][$key])) { |
||
81 | $options[$key] = $record[$source][$key]; |
||
82 | |||
83 | unset($record[$source][$key]); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if (!empty($record['context'])) { |
||
89 | $options['extra']['context'] = $record['context']; |
||
90 | |||
91 | if (!empty($record['context']['user'])) { |
||
92 | $previousUserContext = $this->ravenClient->context->user; |
||
93 | $this->ravenClient->user_context($record['context']['user']); |
||
94 | unset($options['extra']['context']['user']); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | if (!empty($record['extra'])) { |
||
99 | $options['extra']['extra'] = $record['extra']; |
||
100 | } |
||
101 | |||
102 | // New for phptek/sentry |
||
103 | $stack = false; |
||
104 | if (!empty($record['stack'])) { |
||
105 | $stack = (bool) $record['stack']; |
||
106 | } |
||
107 | |||
108 | if (!empty($this->release) && !isset($options['release'])) { |
||
109 | $options['release'] = $this->release; |
||
110 | } |
||
111 | |||
112 | if (isset($record['context']['exception']) && ($record['context']['exception'] instanceof \Exception || (PHP_VERSION_ID >= 70000 && $record['context']['exception'] instanceof \Throwable))) { |
||
113 | $options['extra']['message'] = $record['formatted']; |
||
114 | $this->ravenClient->captureException($record['context']['exception'], $options); |
||
115 | } else { |
||
116 | $this->ravenClient->captureMessage($record['formatted'], [], $options, $stack); |
||
117 | } |
||
118 | |||
119 | if ($previousUserContext !== false) { |
||
120 | $this->ravenClient->user_context($previousUserContext); |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 |