RequestEvent::hasResponse()   A
last analyzed

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 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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