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

Content::set()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 13
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
crap 3.072
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