Passed
Push — html-helpers ( eca32d...09239a )
by Nikolaos
04:43
created

Meta::addHttp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * For the full copyright and license information, please view the LICENSE.md
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Phalcon\Html\Helper;
13
14
use Phalcon\Html\Exception;
15
16
/**
17
 * Class Meta
18
 */
19
class Meta extends AbstractSeries
20
{
21
    /**
22
     * Add an element to the list
23
     *
24
     * @param array $attributes
25
     *
26
     * @return Meta
27
     * @throws Exception
28
     */
29 2
    public function add(array $attributes = []): Meta
30
    {
31 2
        $this->store[] = $this->indent
32 2
            . $this->renderTag(
33 2
                $this->getTag(),
34
                $attributes
35
            )
36
        ;
37
38 2
        return $this;
39
    }
40
41
    /**
42
     * @param string $httpEquiv
43
     * @param string $content
44
     *
45
     * @return Meta
46
     * @throws Exception
47
     */
48 2
    public function addHttp(string $httpEquiv, string $content): Meta
49
    {
50 2
        return $this->addElement('http-equiv', $httpEquiv, $content);
51
    }
52
53
    /**
54
     * @param string $name
55
     * @param string $content
56
     *
57
     * @return Meta
58
     * @throws Exception
59
     */
60 2
    public function addName(string $name, string $content): Meta
61
    {
62 2
        $this->addElement('name', $name, $content);
63
64 2
        return $this;
65
    }
66
67
    /**
68
     * @param string $name
69
     * @param string $content
70
     *
71
     * @return Meta
72
     * @throws Exception
73
     */
74 2
    public function addProperty(string $name, string $content): Meta
75
    {
76 2
        $this->addElement('property', $name, $content);
77
78 2
        return $this;
79
    }
80
81
    /**
82
     * @return string
83
     */
84 2
    protected function getTag(): string
85
    {
86 2
        return 'meta';
87
    }
88
89
    /**
90
     * @param string $element
91
     * @param string $value
92
     * @param string $content
93
     *
94
     * @return Meta
95
     * @throws Exception
96
     */
97 2
    private function addElement(
98
        string $element,
99
        string $value,
100
        string $content
101
    ): Meta {
102
        $attributes = [
103 2
            $element  => $value,
104 2
            'content' => $content,
105
        ];
106
107 2
        return $this->add($attributes);
108
    }
109
}
110