Test Failed
Push — master ( 90252a...135589 )
by Waaaaaaaaaa
02:31
created

Logfile::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Logfile;
4
5
use Throwable;
6
7
class Logfile
8
{
9
    protected $token;
10
11
    protected $sender;
12
13
    protected $config;
14
15
    public function __construct(string $token, Config $config = null)
16
    {
17
        $this->token = $token;
18
        $this->sender = new Sender();
19
        $this->config = $config ?: new Config();
20
    }
21
22
    public function setConfig(Config $config): void
23
    {
24
        $this->config = $config;
25
    }
26
27
    public function getConfig(): Config
28
    {
29
        return $this->config;
30
    }
31
32
    protected function getToken(): string
33
    {
34
        return $this->token;
35
    }
36
37
    /**
38
     * Capture exception and return the event ID
39
     *
40
     * @param Throwable $exception
41
     * @return string
42
     */
43
    public function captureException(Throwable $exception): string
44
    {
45
        $payload = Payload::createFromException($exception, $this->getConfig());
46
        return $this->log($payload);
47
    }
48
49
    /**
50
     * Log payload
51
     *
52
     * @param Payload $payload
53
     * @return string
54
     */
55
    public function log(Payload $payload): string
56
    {
57
        $this->sender->send($payload, $this->getToken());
58
        return $payload->getId();
59
    }
60
}
61