Passed
Push — main ( 9f9f0b...c9aeaf )
by Iain
05:28
created

ExceptionProcessor::getArr()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
c 0
b 0
f 0
nc 4
nop 2
dl 0
loc 18
rs 9.8666
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Humbly Arrogant Software Limited 2020-2024
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: 26.06.2026 ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Common\Logging\Monolog;
16
17
use Monolog\LogRecord;
18
use Monolog\Processor\ProcessorInterface;
19
20
final class ExceptionProcessor implements ProcessorInterface
21
{
22
    public function __invoke(LogRecord $record)
23
    {
24
        $output = [];
25
26
        $output = $this->getArr($record, $output);
27
28
        return $output;
29
    }
30
31
    /**
32
     * @param LogRecord $record
33
     *
34
     * @return array
35
     */
36
    public function getArr(mixed $record, array $output)
37
    {
38
        foreach ($record as $key => $value) {
39
            if (is_array($value)) {
40
                $output[$key] = $this->getArr($value, $output);
41
            } elseif ($value instanceof \Throwable) {
42
                $output[$key] = [
43
                    'message' => $value->getMessage(),
44
                    'file' => $value->getFile(),
45
                    'line' => $value->getLine(),
46
                    'code' => $value->getCode(),
47
                ];
48
            } else {
49
                $output[$key] = $value;
50
            }
51
        }
52
53
        return $output;
54
    }
55
}
56