Completed
Push — 4.0 ( cafdfc...affd8b )
by Marco
02:49
created

Status200::consolidate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 9
cp 0.7778
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
crap 2.0438
1
<?php namespace Comodojo\Dispatcher\Response\Preprocessor;
2
3
/**
4
 * Status: OK
5
 *
6
 * @package     Comodojo Dispatcher
7
 * @author      Marco Giovinazzi <[email protected]>
8
 * @author      Marco Castiello <[email protected]>
9
 * @license     GPL-3.0+
10
 *
11
 * LICENSE:
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License as
15
 * published by the Free Software Foundation, either version 3 of the
16
 * License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License
24
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
 */
26
27
class Status200 extends AbstractPreprocessor {
28
29 1
    public function consolidate() {
30
31 1
        $this->response->getHeaders()->set('Content-Length', $this->response->getContent()->length());
32
33 1
        $type = $this->response->getContent()->type();
34 1
        $charset = $this->response->getContent()->charset();
35
36 1
        if ( is_null($charset) ) {
37
            $this->response->getHeaders()->set("Content-type", strtolower($type));
38
        } else {
39 1
            $this->response->getHeaders()->set("Content-type", strtolower($type)."; charset=".$charset);
40
        }
41
42 1
    }
43
44
}
45