RaygunFormatter::format()   B
last analyzed

Complexity

Conditions 8
Paths 15

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 17
nc 15
nop 1
dl 0
loc 28
ccs 18
cts 18
cp 1
crap 8
rs 8.4444
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of Monolog Extensions
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/MonologExtensions/blob/master/LICENSE
11
 * @link http://github.com/graze/MonologExtensions
12
 */
13
14
namespace Graze\Monolog\Formatter;
15
16
use Monolog\Formatter\NormalizerFormatter;
17
18
class RaygunFormatter extends NormalizerFormatter
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  array $record A record to format
24
     *
25
     * @return mixed The formatted record
26
     */
27 7
    public function format(array $record)
28
    {
29 7
        $record = parent::format($record);
30
31 7
        $record['tags'] = [];
32 7
        $record['custom_data'] = [];
33 7
        $record['timestamp'] = null;
34
35 7
        foreach (['extra', 'context'] as $source) {
36 7
            if (array_key_exists('tags', $record[$source]) && is_array($record[$source]['tags'])) {
37 2
                $record['tags'] = array_merge($record['tags'], $record[$source]['tags']);
38
            }
39 7
            if (array_key_exists('timestamp', $record[$source]) && is_numeric($record[$source]['timestamp'])) {
40 2
                $record['timestamp'] = $record[$source]['timestamp'];
41
            }
42 7
            unset($record[$source]['tags'], $record[$source]['timestamp']);
43
        }
44
45 7
        $record['custom_data'] = $record['extra'];
46 7
        $record['extra'] = [];
47 7
        foreach ($record['context'] as $key => $item) {
48 6
            if (!in_array($key, ['file', 'line', 'exception'])) {
49 1
                $record['custom_data'][$key] = $item;
50 6
                unset($record['context'][$key]);
51
            }
52
        }
53
54 7
        return $record;
55
    }
56
}
57