Passed
Pull Request — master (#568)
by Def
02:20
created

AbstractContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setException() 0 4 1
A getType() 0 3 1
A __construct() 0 2 1
A __toArray() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Profiler\Context;
6
7
use Throwable;
8
use Yiisoft\Db\Profiler\ContextInterface;
9
10
abstract class AbstractContext implements ContextInterface
11
{
12
    protected const METHOD = 'method';
13
    protected const EXCEPTION = 'exception';
14
15
    protected string $type;
16
17
    private Throwable|null $exception = null;
18
19
    public function __construct(private string $method)
20
    {
21
    }
22
23
    public function getType(): string
24
    {
25
        return $this->type;
26
    }
27
28
    public function setException(Throwable $e): static
29
    {
30
        $this->exception = $e;
31
        return $this;
32
    }
33
34
    public function __toArray(): array
35
    {
36
        return [
37
            self::METHOD => $this->method,
38
            self::EXCEPTION => $this->exception,
39
        ];
40
    }
41
}
42