Completed
Push — bash-completion ( 164352...1454d3 )
by Carsten
86:55 queued 83:59
created

HtmlResponseFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 10 3
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\web;
9
10
use yii\base\Component;
11
12
/**
13
 * HtmlResponseFormatter formats the given data into an HTML response content.
14
 *
15
 * It is used by [[Response]] to format response data.
16
 *
17
 * @author Qiang Xue <[email protected]>
18
 * @since 2.0
19
 */
20
class HtmlResponseFormatter extends Component implements ResponseFormatterInterface
21
{
22
    /**
23
     * @var string the Content-Type header for the response
24
     */
25
    public $contentType = 'text/html';
26
27
28
    /**
29
     * Formats the specified response.
30
     * @param Response $response the response to be formatted.
31
     */
32 3
    public function format($response)
33
    {
34 3
        if (stripos($this->contentType, 'charset') === false) {
35 3
            $this->contentType .= '; charset=' . $response->charset;
36 3
        }
37 3
        $response->getHeaders()->set('Content-Type', $this->contentType);
38 3
        if ($response->data !== null) {
39 3
            $response->content = $response->data;
40 3
        }
41 3
    }
42
}
43