RequestEvent   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 29
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponse() 0 3 1
A setResponse() 0 4 1
A hasResponse() 0 3 1
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Biurad opensource projects.
5
 *
6
 * @copyright 2019 Biurad Group (https://biurad.com/)
7
 * @license   https://opensource.org/licenses/BSD-3-Clause License
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Flange\Event;
14
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * Allows to create a response for a request.
19
 *
20
 * Call setResponse() to set the response that will be returned for the
21
 * current request. The propagation of this event is stopped as soon as a
22
 * response is set.
23
 *
24
 * @author Divine Niiquaye Ibok <[email protected]>
25
 */
26
class RequestEvent extends KernelEvent
27
{
28
    private ?ResponseInterface $response = null;
29
30
    /**
31
     * Returns the response object.
32
     */
33
    public function getResponse(): ?ResponseInterface
34
    {
35
        return $this->response;
36
    }
37
38
    /**
39
     * Sets a response and stops event propagation.
40
     */
41
    public function setResponse(ResponseInterface $response): void
42
    {
43
        $this->response = $response;
44
        $this->stopPropagation();
45
    }
46
47
    /**
48
     * Returns whether a response was set.
49
     *
50
     * @return bool Whether a response was set
51
     */
52
    public function hasResponse(): bool
53
    {
54
        return null !== $this->response;
55
    }
56
}
57