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

Content   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Test Coverage

Coverage 94.74%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 9
c 5
b 0
f 0
lcom 3
cbo 1
dl 0
loc 65
ccs 18
cts 19
cp 0.9474
rs 10

5 Methods

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