Passed
Push — develop ( 6a6555...e059c0 )
by Peter
01:47
created

RequestAwareEventTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setRequest() 0 3 1
A getRequest() 0 6 2
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/request
6
 * @copyright   Copyright (c) 2019 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace Webino;
12
13
/**
14
 * Trait RequestAwareEventTrait
15
 * @package request
16
 */
17
trait RequestAwareEventTrait
18
{
19
    /**
20
     * Returns PHP environment execution request.
21
     *
22
     * @return RequestInterface
23
     * @throws NotRequestException
24
     */
25
    public function getRequest(): RequestInterface
26
    {
27
        if (empty($this['request'])) {
28
            throw new NotRequestException;
29
        }
30
        return $this['request'];
31
    }
32
33
    /**
34
     * Set PHP environment execution request.
35
     *
36
     * @param RequestInterface $request
37
     */
38
    protected function setRequest(RequestInterface $request): void
39
    {
40
        $this['request'] = $request;
41
    }
42
}
43