Conditions | 12 |
Paths | 256 |
Total Lines | 41 |
Code Lines | 20 |
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 |
||
34 | protected function prepareTags(array $record): array |
||
35 | { |
||
36 | $tags = []; |
||
37 | |||
38 | if (isset($_SERVER['REMOTE_ADDR'])) { |
||
39 | $tags['serverName'] = $_SERVER['REMOTE_ADDR']; |
||
40 | } |
||
41 | |||
42 | if (isset($record['level'])) { |
||
43 | $tags['severity'] = $this->rfc5424ToSeverity($record['level']); |
||
44 | } |
||
45 | |||
46 | if (isset($_SERVER['REQUEST_URI'])) { |
||
47 | $tags['endpoint_url'] = $_SERVER['REQUEST_URI']; |
||
48 | } |
||
49 | |||
50 | if (isset($_SERVER['REQUEST_METHOD'])) { |
||
51 | $tags['method'] = $_SERVER['REQUEST_METHOD']; |
||
52 | } |
||
53 | |||
54 | if (isset($record['context']['user_id'])) { |
||
55 | $tags['user_id'] = $record['context']['user_id']; |
||
56 | } |
||
57 | |||
58 | if (isset($record['context']['project_id'])) { |
||
59 | $tags['project_id'] = $record['context']['project_id']; |
||
60 | } |
||
61 | |||
62 | if (isset($record['context']['file'])) { |
||
63 | $tags['file'] = $this->replaceDigitData($record['context']['file']); |
||
64 | } |
||
65 | |||
66 | if (isset($record['context']['event']['api_stats'][0])) { |
||
67 | foreach ($record['context']['event']['api_stats'][0] as $key => $value) { |
||
68 | if (is_string($value) || is_int($value)) { |
||
69 | $tags[$key] = $value; |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | |||
74 | return $tags; |
||
75 | } |
||
164 |