Passed
Push — master ( 7656d0...dbe1c1 )
by Divine Niiquaye
04:04
created

RequestEvent::hasResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\Event;
19
20
use Psr\Http\Message\ResponseInterface;
21
22
/**
23
 * Allows to create a response for a request.
24
 *
25
 * Call setResponse() to set the response that will be returned for the
26
 * current request. The propagation of this event is stopped as soon as a
27
 * response is set.
28
 *
29
 * @author Divine Niiquaye Ibok <[email protected]>
30
 */
31
class RequestEvent extends KernelEvent
32
{
33
    private ?ResponseInterface $response = null;
34
35
    /**
36
     * Returns the response object.
37
     */
38
    public function getResponse(): ?ResponseInterface
39
    {
40
        return $this->response;
41
    }
42
43
    /**
44
     * Sets a response and stops event propagation.
45
     */
46
    public function setResponse(ResponseInterface $response): void
47
    {
48
        $this->response = $response;
49
        $this->stopPropagation();
50
    }
51
52
    /**
53
     * Returns whether a response was set.
54
     *
55
     * @return bool Whether a response was set
56
     */
57 4
    public function hasResponse(): bool
58
    {
59 4
        return null !== $this->response;
60
    }
61
}
62