Passed
Branch master (e714e6)
by Gabriel
13:58 queued 11:36
created

DoctypeHelper::render()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 21
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 15.0484

Importance

Changes 0
Metric Value
cc 9
eloc 19
nc 9
nop 0
dl 0
loc 21
ccs 11
cts 19
cp 0.5789
crap 15.0484
rs 7.041
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\View\Helpers;
4
5
use Exception;
6
7
/**
8
 * Class DoctypeHelper
9
 * @package Nip\View\Helpers
10
 */
11
class DoctypeHelper extends AbstractHelper
12
{
13
    protected $docType;
14
15
    /**
16
     * @return string
17
     */
18
    public function __toString()
19
    {
20
        return $this->render();
21
    }
22
23
    /**
24
     * @return string
25
     */
26 1
    public function render()
27
    {
28 1
        switch ($this->docType) {
29 1
            case 'XHTML11':
30
                return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
31 1
            case 'XHTML1_STRICT':
32
                return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
33 1
            case 'XHTML1_FRAMESET':
34
                return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
35 1
            case 'XHTML_BASIC1':
36
                return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">';
37 1
            case 'HTML4_STRICT':
38
                return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
39 1
            case 'HTML4_LOOSE':
40
                return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
41 1
            case 'HTML4_FRAMESET':
42
                return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">';
43 1
            case 'XHTML1_TRANSITIONAL':
44
                return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
45
            default:
46 1
                return '<!DOCTYPE html>';
47
        }
48
    }
49
50
    /**
51
     * @param bool $docType
52
     * @return $this
53
     * @throws Exception
54
     */
55
    public function set($docType = false)
56
    {
57
        switch ($docType) {
58
            case 'XHTML11':
59
            case 'XHTML1_STRICT':
60
            case 'XHTML1_TRANSITIONAL':
61
            case 'XHTML1_FRAMESET':
62
            case 'XHTML_BASIC1':
63
            case 'HTML4_STRICT':
64
            case 'HTML4_LOOSE':
65
            case 'HTML4_FRAMESET':
66
                $this->docType = $docType;
67
                break;
68
            default:
69
                throw new Exception('unknown doctype');
70
                break;
71
        }
72
73
        return $this;
74
    }
75
}
76