Completed
Push — master ( b8bed0...083509 )
by Eric
04:00 queued 01:09
created

ExceptionEvent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 42
rs 10
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
1 ignored issue
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?'
Loading history...
28
    {
29
        return $this->response;
30
    }
31
32
    public function setResponse(Response $response): ExceptionEvent
33
    {
34
        $this->response = $response;
35
        $this->stopPropagation();
36
37
        return $this;
38
    }
39
40
    /**
41
     * Forbids stop of current event propagation if response is not setted.
42
     *
43
     * {@inheritdoc}
44
     */
45
    public function stopPropagation(): SimpleEvent
46
    {
47
        if (null === $this->response) {
48
            return $this;
49
        }
50
51
        return parent::stopPropagation();
52
    }
53
}
54