Conditions | 12 |
Paths | 512 |
Total Lines | 41 |
Code Lines | 26 |
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 |
||
87 | protected function formatV0(array $record) |
||
88 | { |
||
89 | if (empty($record['datetime'])) { |
||
90 | $record['datetime'] = gmdate('c'); |
||
91 | } |
||
92 | $message = array( |
||
93 | '@timestamp' => $record['datetime'], |
||
94 | '@source' => $this->systemName, |
||
95 | '@fields' => array(), |
||
96 | ); |
||
97 | if (isset($record['message'])) { |
||
98 | $message['@message'] = $record['message']; |
||
99 | } |
||
100 | if (isset($record['channel'])) { |
||
101 | $message['@tags'] = array($record['channel']); |
||
102 | $message['@fields']['channel'] = $record['channel']; |
||
103 | } |
||
104 | if (isset($record['level'])) { |
||
105 | $message['@fields']['level'] = $record['level']; |
||
106 | } |
||
107 | if ($this->applicationName) { |
||
108 | $message['@type'] = $this->applicationName; |
||
109 | } |
||
110 | if (isset($record['extra']['server'])) { |
||
111 | $message['@source_host'] = $record['extra']['server']; |
||
112 | } |
||
113 | if (isset($record['extra']['url'])) { |
||
114 | $message['@source_path'] = $record['extra']['url']; |
||
115 | } |
||
116 | if (!empty($record['extra'])) { |
||
117 | foreach ($record['extra'] as $key => $val) { |
||
118 | $message['@fields'][$this->extraPrefix . $key] = $val; |
||
119 | } |
||
120 | } |
||
121 | if (!empty($record['context'])) { |
||
122 | foreach ($record['context'] as $key => $val) { |
||
123 | $message['@fields'][$this->contextPrefix . $key] = $val; |
||
124 | } |
||
125 | } |
||
126 | |||
127 | return $message; |
||
128 | } |
||
167 |