Completed
Push — master ( 465cbd...e0d13e )
by Marco
06:44 queued 11s
created

Content::get()   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 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php namespace Comodojo\Dispatcher\Response;
2
3
use \Comodojo\Dispatcher\Traits\ToStringTrait;
4
use \Exception;
5
6
/**
7
 * @package     Comodojo Dispatcher
8
 * @author      Marco Giovinazzi <[email protected]>
9
 * @author      Marco Castiello <[email protected]>
10
 * @license     MIT
11
 *
12
 * LICENSE:
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
 * THE SOFTWARE.
21
 */
22
23
class Content {
24
25
    use ToStringTrait;
26
27
    private $content;
28
29
    private $type = "text/plain";
30
31
    private $charset = "utf-8";
32
33 6
    public function get() {
34
35 6
        return $this->content;
36
37
    }
38
39 5
    public function set($content = null) {
40
41 5
        if (!is_scalar($content) && $content != null) {
42
43
            throw new Exception("Invalid HTTP content");
44
45
        }
46
47 5
        $this->content = $content;
48
49 5
        return $this;
50
51
    }
52
53 2
    public function getType() {
54
55 2
        return $this->type;
56
57
    }
58
59 1
    public function setType($type) {
60
61 1
        $this->type = $type;
62
63 1
        return $this;
64
65
    }
66
67 2
    public function type($type = null) {
68
69 2
        return is_null($type) ? $this->getType() : $this->setType($type);
70
71
    }
72
73 2
    public function getCharset() {
74
75 2
        return $this->charset;
76
77
    }
78
79 1
    public function setCharset($charset) {
80
81 1
        $this->charset = $charset;
82
83 1
        return $this;
84
85
    }
86
87 2
    public function charset($charset = null) {
88
89 2
        return is_null($charset) ? $this->getCharset() : $this->setCharset($charset);
90
91
    }
92
93 2
    public function getLength() {
94
95 2
        return strlen($this->content);
96
97
    }
98
99 2
    public function length() {
100
101 2
        return $this->getLength();
102
103
    }
104
105
}
106