Completed
Push — 4.0 ( 3b08f9...a100dc )
by Marco
14:07
created

Status   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.31%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 43
ccs 12
cts 13
cp 0.9231
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 5 1
A set() 0 13 2
A description() 0 7 2
1
<?php namespace Comodojo\Dispatcher\Response;
2
3
use \Comodojo\Dispatcher\Components\ToString as ToStringTrait;
4
use \Comodojo\Dispatcher\Components\HttpStatusCodes;
5
use \Exception;
6
7
/**
8
 * @package     Comodojo Dispatcher
9
 * @author      Marco Giovinazzi <[email protected]>
10
 * @author      Marco Castiello <[email protected]>
11
 * @license     GPL-3.0+
12
 *
13
 * LICENSE:
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27
 */
28
29
class Status {
30
    
31
    use ToStringTrait;
32
33
    private $status_code = 200;
34
    
35
    private $codes;
36
    
37 5
    public function __construct() {
38
        
39 5
        $this->codes = new HttpStatusCodes;
40
        
41 5
    }
42
43 6
    public function get() {
44
45 6
        return $this->status_code;
46
47
    }
48
49 4
    public function set($code) {
50
51 4
        if ( !$this->codes->exists($code) ) {
52
53
            throw new Exception("Invalid HTTP Status Code $code");
54
55
        }
56
57 4
        $this->status_code = $code;
58
59 4
        return $this;
60
61
    }
62
63 1
    public function description($code=null) {
64
65 1
        if ( is_null($code) ) return $this->codes->getMessage($this->status_code);
66
        
67 1
        return $this->codes->getMessage($code);
68
69
    }
70
71
}
72