TurboContentHeader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 56
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A titleH1() 0 5 1
A titleH2() 0 5 1
A img() 0 5 1
A asHTML() 0 26 4
1
<?php
2
3
namespace sokolnikov911\YandexTurboPages;
4
5
use DOMDocument;
6
7
/**
8
 * Class TurboContentHeader
9
 * @package sokolnikov911\YandexTurboPages
10
 * @deprecated 2.0.0 Use Content::header instead
11
 */
12
class TurboContentHeader implements TurboContentHeaderInterface
13
{
14
    /** @var string */
15
    protected $titleH1;
16
17
    /** @var string */
18
    protected $titleH2;
19
20
    /** @var string */
21
    protected $img;
22
23 8
    public function titleH1(string $titleH1): TurboContentHeaderInterface
24
    {
25 8
        $this->titleH1 = $titleH1;
26 8
        return $this;
27
    }
28
29 8
    public function titleH2(string $titleH2): TurboContentHeaderInterface
30
    {
31 8
        $this->titleH2 = $titleH2;
32 8
        return $this;
33
    }
34
35 8
    public function img(string $img): TurboContentHeaderInterface
36
    {
37 8
        $this->img = $img;
38 8
        return $this;
39
    }
40
41 4
    public function asHTML(): string
42
    {
43 4
        $DOMDoc = new DOMDocument('1.0', 'UTF-8');
44
45 4
        $titleH2 = $this->titleH2 ? $this->titleH2 : '';
46
47 4
        $headerDOMElement = $DOMDoc->createElement('header', $titleH2);
48 4
        $headerDOMElement = $DOMDoc->appendChild($headerDOMElement);
49
50 4
        if (!empty($this->titleH1)) {
51 4
            $h1DOMElement = $DOMDoc->createElement('h1', $this->titleH1);
52 4
            $headerDOMElement->appendChild($h1DOMElement);
53
        }
54
55 4
        if (!empty($this->img)) {
56 4
            $figureDOMElement = $DOMDoc->createElement('figure');
57
58 4
            $imgDOMElement = $DOMDoc->createElement('img');
59 4
            $imgDOMElement->setAttribute('src', $this->img);
60 4
            $figureDOMElement->appendChild($imgDOMElement);
61
62 4
            $headerDOMElement->appendChild($figureDOMElement);
63
        }
64
65 4
        return strval(html_entity_decode($DOMDoc->saveHTML()));
66
    }
67
}
68