TwitterSeoGenerator::setCard()   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 1
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\Seo\Twitter;
4
5
use Leogout\Bundle\SeoBundle\Model\MetaTag;
6
use Leogout\Bundle\SeoBundle\Seo\AbstractSeoGenerator;
7
use Leogout\Bundle\SeoBundle\Seo\TitleSeoInterface;
8
use Leogout\Bundle\SeoBundle\Seo\DescriptionSeoInterface;
9
use Leogout\Bundle\SeoBundle\Seo\ImageSeoInterface;
10
11
/**
12
 * Description of TwitterSeoGenerator.
13
 *
14
 * @author: leogout
15
 */
16
class TwitterSeoGenerator extends AbstractSeoGenerator
17
{
18
    /**
19
     * @param string $content
20
     *
21
     * @return $this
22
     */
23
    public function setCard($content)
24
    {
25
        return $this->set('twitter:card', $content);
26
    }
27
28
    /**
29
     * @return MetaTag
30
     */
31
    public function getCard()
32
    {
33
        return $this->get('twitter:card');
34
    }
35
36
    /**
37
     * @param string $content
38
     *
39
     * @return $this
40
     */
41
    public function setTitle($content)
42
    {
43
        return $this->set('twitter:title', $content);
44
    }
45
46
    /**
47
     * @return MetaTag
48
     */
49
    public function getTitle()
50
    {
51
        return $this->get('twitter:title');
52
    }
53
54
    /**
55
     * @param string $content
56
     *
57
     * @return $this
58
     */
59
    public function setSite($content)
60
    {
61
        return $this->set('twitter:site', $content);
62
    }
63
64
    /**
65
     * @return MetaTag
66
     */
67
    public function getSite()
68
    {
69
        return $this->get('twitter:site');
70
    }
71
72
    /**
73
     * @param string $content
74
     *
75
     * @return $this
76
     */
77
    public function setDescription($content)
78
    {
79
        return $this->set('twitter:description', $content);
80
    }
81
82
    /**
83
     * @return MetaTag
84
     */
85
    public function getDescription()
86
    {
87
        return $this->get('twitter:description');
88
    }
89
90
    /**
91
     * @param string $content
92
     *
93
     * @return $this
94
     */
95
    public function setImage($content)
96
    {
97
        return $this->set('twitter:image', $content);
98
    }
99
100
    /**
101
     * @return MetaTag
102
     */
103
    public function getImage()
104
    {
105
        return $this->get('twitter:image');
106
    }
107
108
    /**
109
     * Generate seo tags from given resource.
110
     *
111
     * @param TitleSeoInterface|DescriptionSeoInterface|ImageSeoInterface $resource
112
     *
113
     * @return $this
114
     */
115 View Code Duplication
    public function fromResource($resource)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        if ($resource instanceof TitleSeoInterface) {
118
            $this->setTitle($resource->getSeoTitle());
119
        }
120
        if ($resource instanceof DescriptionSeoInterface) {
121
            $this->setDescription($resource->getSeoDescription());
122
        }
123
        if ($resource instanceof ImageSeoInterface) {
124
            $this->setImage($resource->getSeoImage());
125
        }
126
127
        return $this;
128
    }
129
130
    /**
131
     * @param string $type
132
     *
133
     * @return MetaTag
134
     */
135
    public function get($type)
136
    {
137
        return $this->tagBuilder->getMeta($type);
138
    }
139
140
    /**
141
     * @param string $type
142
     * @param string $value
143
     *
144
     * @return $this
145
     */
146
    public function set($type, $value)
147
    {
148
        $this->tagBuilder->addMeta($type)
149
            ->setType(MetaTag::NAME_TYPE)
150
            ->setValue($type)
151
            ->setContent((string) $value);
152
153
        return $this;
154
    }
155
}
156