Passed
Push — master ( 0f66d0...a5c111 )
by Gabor
16:59 queued 08:35
created

Result   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 113
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __clone() 0 6 1
A setStatus() 0 10 2
A getStatus() 0 4 1
A getStatusReason() 0 4 1
A setMatchedMiddleware() 0 6 1
A getMatchedMiddleware() 0 4 1
A setParameters() 0 6 1
A getParameters() 0 4 1
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Router;
15
16
use InvalidArgumentException;
17
18
/**
19
 * Class Result.
20
 */
21
class Result
22
{
23
    public const CODE_FOUND = 200;
24
    public const CODE_NOT_FOUND = 404;
25
    public const CODE_BAD_METHOD = 405;
26
27
    /** @var int */
28
    private $status;
29
    /** @var string */
30
    private $matchedMiddleware;
31
    /** @var array */
32
    private $statusReason = [
33
        self::CODE_FOUND      => 'Resource found.',
34
        self::CODE_NOT_FOUND  => 'The requested resource cannot be found.',
35
        self::CODE_BAD_METHOD => 'Bad request method was used by the client.'
36
    ];
37
    /** @var array */
38
    private $parameters;
39
40
    /**
41
     * Define clone actions.
42
     */
43 7
    public function __clone()
44
    {
45 7
        unset($this->status);
46 7
        unset($this->matchedMiddleware);
47 7
        unset($this->parameters);
48 7
    }
49
50
    /**
51
     * Sets status code.
52
     *
53
     * @param int $status
54
     * @throws InvalidArgumentException
55
     * @return Result
56
     */
57 9
    public function setStatus(int $status) : Result
58
    {
59 9
        if (!isset($this->statusReason[$status])) {
60 1
            throw new InvalidArgumentException(sprintf('The parameter "%s" is not a valid router status.', $status));
61
        }
62
63 8
        $this->status = $status;
64
65 8
        return $this;
66
    }
67
68
    /**
69
     * Gets status code.
70
     *
71
     * @return int
72
     */
73 8
    public function getStatus() : int
74
    {
75 8
        return $this->status;
76
    }
77
78
    /**
79
     * Gets reason for the status set.
80
     *
81
     * @return string
82
     */
83 3
    public function getStatusReason() : string
84
    {
85 3
        return $this->statusReason[$this->status] ?? '';
86
    }
87
88
    /**
89
     * Sets matched middleware.
90
     *
91
     * @param string $matchedMiddleware
92
     * @return Result
93
     */
94 6
    public function setMatchedMiddleware(string $matchedMiddleware)
95
    {
96 6
        $this->matchedMiddleware = $matchedMiddleware;
97
98 6
        return $this;
99
    }
100
101
    /**
102
     * Gets matched middleware.
103
     *
104
     * @return string
105
     */
106 6
    public function getMatchedMiddleware() : string
107
    {
108 6
        return $this->matchedMiddleware;
109
    }
110
111
    /**
112
     * Sets the parameters.
113
     *
114
     * @param array $parameters
115
     * @return Result
116
     */
117 6
    public function setParameters(array $parameters) : Result
118
    {
119 6
        $this->parameters = $parameters;
120
121 6
        return $this;
122
    }
123
124
    /**
125
     * Gets the parameters.
126
     *
127
     * @return array
128
     */
129 4
    public function getParameters() : array
130
    {
131 4
        return $this->parameters;
132
    }
133
}
134