ExceptionEvent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jarvis\Skill\EventBroadcaster;
6
7
use Symfony\Component\HttpFoundation\Response;
8
9
/**
10
 * @author Eric Chau <[email protected]>
11
 */
12
class ExceptionEvent extends SimpleEvent
13
{
14
    private $exception;
15
    private $response;
16
17
    public function __construct(\Throwable $exception)
18
    {
19
        $this->exception = $exception;
20
    }
21
22
    public function exception(): \Throwable
23
    {
24
        return $this->exception;
25
    }
26
27
    public function response(): ?Response
28
    {
29
        return $this->response;
30
    }
31
32
    public function setResponse(Response $response): void
33
    {
34
        $this->response = $response;
35
        $this->stopPropagation();
36
    }
37
38
    /**
39
     * Forbids stop of current event propagation if response is not setted.
40
     *
41
     * {@inheritdoc}
42
     */
43
    public function stopPropagation(): void
44
    {
45
        if (null === $this->response) {
46
            return;
47
        }
48
49
        parent::stopPropagation();
50
    }
51
}
52