ExceptionTrackable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 14
c 1
b 0
f 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exception() 0 3 1
A __construct() 0 12 1
1
<?php
2
3
/**
4
 * This file is part of slick/telemetry package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\Telemetry\Model;
13
14
use Psr\Log\LogLevel;
15
use Slick\Telemetry\Trackable;
16
use Throwable;
17
18
/**
19
 * ExceptionTrackable
20
 *
21
 * @package Slick\Telemetry\Model
22
 */
23
final class ExceptionTrackable implements Trackable
24
{
25
    use TrackableMethods;
26
27
    private Throwable $exception;
28
29
    /**
30
     * Creates a ExceptionTrackable
31
     *
32
     * @param Throwable $exception
33
     * @param iterable $context
34
     */
35
    public function __construct(Throwable $exception, iterable $context = [])
36
    {
37
        $this->message = $exception->getMessage();
38
        $this->exception = $exception;
39
        $this->context = $context;
40
        $this->logLevel = LogLevel::ALERT;
41
        $this->label = Trackable::LABEL_EXCEPTION;
42
        $this->context = array_merge($context, [
0 ignored issues
show
Bug introduced by
It seems like $context can also be of type iterable; however, parameter $arrays of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
        $this->context = array_merge(/** @scrutinizer ignore-type */ $context, [
Loading history...
43
            'label' => $this->label,
44
            'exception' => get_class($this->exception),
45
            'file' => "{$exception->getFile()} ({$exception->getLine()})",
46
            'trace' => $this->exception->getTraceAsString()
47
        ]);
48
    }
49
50
    /**
51
     * exception
52
     *
53
     * @return Throwable
54
     */
55
    public function exception(): Throwable
56
    {
57
        return $this->exception;
58
    }
59
}
60