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

DoctypeHelper   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 32.35%

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 11
cts 34
cp 0.3235
rs 10
c 0
b 0
f 0
wmc 19

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
B render() 0 21 9
B set() 0 19 9
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