MetaTag::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\Model;
4
5
/**
6
 * Description of MetaTag.
7
 *
8
 * @author: leogout
9
 */
10
class MetaTag implements RenderableInterface
11
{
12
    const NAME_TYPE = 'name';
13
    const PROPERTY_TYPE = 'property';
14
    const HTTP_EQUIV_TYPE = 'http-equiv';
15
16
    /**
17
     * @var string
18
     */
19
    protected $type = self::NAME_TYPE;
20
21
    /**
22
     * @var string
23
     */
24
    protected $value;
25
26
    /**
27
     * @var string
28
     */
29
    protected $content;
30
31
    /**
32
     * @return string
33
     */
34
    public function getType()
35
    {
36
        return $this->type;
37
    }
38
39
    /**
40
     * @param string $type
41
     *
42
     * @return $this
43
     */
44
    public function setType($type)
45
    {
46
        if (!in_array($type, $this->getTypes())) {
47
            throw new \InvalidArgumentException(sprintf('Meta tag of type "%s" doesn\'t exist. Existing types are: name, property and http-equiv.', $type));
48
        }
49
50
        $this->type = $type;
51
52
        return $this;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getValue()
59
    {
60
        return $this->value;
61
    }
62
63
    /**
64
     * @param string $value
65
     *
66
     * @return $this
67
     */
68
    public function setValue($value)
69
    {
70
        $this->value = (string) $value;
71
72
        return $this;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getContent()
79
    {
80
        return $this->content;
81
    }
82
83
    /**
84
     * @param string $content
85
     *
86
     * @return $this
87
     */
88
    public function setContent($content)
89
    {
90
        $this->content = (string) $content;
91
92
        return $this;
93
    }
94
95
    /**
96
     * @return array
97
     */
98
    public function getTypes()
99
    {
100
        return [
101
            self::NAME_TYPE,
102
            self::PROPERTY_TYPE,
103
            self::HTTP_EQUIV_TYPE,
104
        ];
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function render()
111
    {
112
        return sprintf('<meta %s="%s" content="%s" />', $this->getType(), $this->getValue(), $this->getContent());
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function __toString()
119
    {
120
        return $this->render();
121
    }
122
}
123