DoctypeHelper   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 31.43%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 19
eloc 37
c 1
b 0
f 0
dl 0
loc 65
ccs 11
cts 35
cp 0.3143
rs 10

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