Completed
Push — master ( 495378...410af9 )
by ARCANEDEV
04:10
created

SeoHelper::enableTwitter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php namespace Arcanedev\SeoHelper;
2
3
/**
4
 * Class     SeoHelper
5
 *
6
 * @package  Arcanedev\SeoHelper
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
class SeoHelper implements Contracts\SeoHelper
10
{
11
    /* ------------------------------------------------------------------------------------------------
12
     |  Properties
13
     | ------------------------------------------------------------------------------------------------
14
     */
15
    /**
16
     * The SeoMeta instance.
17
     *
18
     * @var Contracts\SeoMeta
19
     */
20
    private $seoMeta;
21
22
    /**
23
     * The SeoOpenGraph instance.
24
     *
25
     * @var Contracts\SeoOpenGraph
26
     */
27
    private $seoOpenGraph;
28
29
    /**
30
     * The SeoTwitter instance.
31
     *
32
     * @var Contracts\SeoTwitter
33
     */
34
    private $seoTwitter;
35
36
    /* ------------------------------------------------------------------------------------------------
37
     |  Constructor
38
     | ------------------------------------------------------------------------------------------------
39
     */
40
    /**
41
     * Make SeoHelper instance.
42
     *
43
     * @param  Contracts\SeoMeta       $seoMeta
44
     * @param  Contracts\SeoOpenGraph  $seoOpenGraph
45
     * @param  Contracts\SeoTwitter    $seoTwitter
46
     */
47 51
    public function __construct(
48
        Contracts\SeoMeta      $seoMeta,
49
        Contracts\SeoOpenGraph $seoOpenGraph,
50
        Contracts\SeoTwitter   $seoTwitter
51
    ) {
52 51
        $this->setSeoMeta($seoMeta);
53 51
        $this->setSeoOpenGraph($seoOpenGraph);
54 51
        $this->setSeoTwitter($seoTwitter);
55 51
    }
56
57
    /* ------------------------------------------------------------------------------------------------
58
     |  Getters & Setters
59
     | ------------------------------------------------------------------------------------------------
60
     */
61
    /**
62
     * Get SeoMeta instance.
63
     *
64
     * @return Contracts\SeoMeta
65
     */
66 33
    public function meta()
67
    {
68 33
        return $this->seoMeta;
69
    }
70
71
    /**
72
     * Set SeoMeta instance.
73
     *
74
     * @param  Contracts\SeoMeta  $seoMeta
75
     *
76
     * @return self
77
     */
78 51
    public function setSeoMeta(Contracts\SeoMeta $seoMeta)
79
    {
80 51
        $this->seoMeta = $seoMeta;
81
82 51
        return $this;
83
    }
84
85
    /**
86
     * Get SeoOpenGraph instance.
87
     *
88
     * @return Contracts\SeoOpenGraph
89
     */
90 33
    public function openGraph()
91
    {
92 33
        return $this->seoOpenGraph;
93
    }
94
95
    /**
96
     * Get SeoOpenGraph instance (alias).
97
     *
98
     * @see    \Arcanedev\SeoHelper\SeoHelper::openGraph()
99
     *
100
     * @return Contracts\SeoOpenGraph
101
     */
102 3
    public function og()
103
    {
104 3
        return $this->openGraph();
105
    }
106
107
    /**
108
     * Get SeoOpenGraph instance.
109
     *
110
     * @param  Contracts\SeoOpenGraph  $seoOpenGraph
111
     *
112
     * @return self
113
     */
114 51
    public function setSeoOpenGraph(Contracts\SeoOpenGraph $seoOpenGraph)
115
    {
116 51
        $this->seoOpenGraph = $seoOpenGraph;
117
118 51
        return $this;
119
    }
120
121
    /**
122
     * Get SeoTwitter instance.
123
     *
124
     * @return Contracts\SeoTwitter
125
     */
126 30
    public function twitter()
127
    {
128 30
        return $this->seoTwitter;
129
    }
130
131
    /**
132
     * Set SeoTwitter instance.
133
     *
134
     * @param  Contracts\SeoTwitter  $seoTwitter
135
     *
136
     * @return self
137
     */
138 51
    public function setSeoTwitter(Contracts\SeoTwitter $seoTwitter)
139
    {
140 51
        $this->seoTwitter = $seoTwitter;
141
142 51
        return $this;
143
    }
144
145
    /**
146
     * Set title.
147
     *
148
     * @param  string       $title
149
     * @param  string|null  $siteName
150
     * @param  string|null  $separator
151
     *
152
     * @return self
153
     */
154 6
    public function setTitle($title, $siteName = null, $separator = null)
155
    {
156 6
        $this->meta()->setTitle($title, $siteName, $separator);
157 6
        $this->openGraph()->setTitle($title);
158 6
        $this->openGraph()->setSiteName($siteName);
159 6
        $this->twitter()->setTitle($title);
160
161 6
        return $this;
162
    }
163
164
    /**
165
     * Set description.
166
     *
167
     * @param  string $description
168
     *
169
     * @return \Arcanedev\SeoHelper\Contracts\SeoHelper
170
     */
171 6
    public function setDescription($description)
172
    {
173 6
        $this->meta()->setDescription($description);
174 6
        $this->openGraph()->setDescription($description);
175 6
        $this->twitter()->setDescription($description);
176
177 6
        return $this;
178
    }
179
180
    /**
181
     * Set keywords.
182
     *
183
     * @param  array|string  $keywords
184
     *
185
     * @return self
186
     */
187 6
    public function setKeywords($keywords)
188
    {
189 6
        $this->meta()->setKeywords($keywords);
190
191 6
        return $this;
192
    }
193
194
    /* ------------------------------------------------------------------------------------------------
195
     |  Main Functions
196
     | ------------------------------------------------------------------------------------------------
197
     */
198
    /**
199
     * Render all seo tags.
200
     *
201
     * @return string
202
     */
203 27
    public function render()
204
    {
205 27
        return implode(PHP_EOL, array_filter([
206 27
            $this->meta()->render(),
207 27
            $this->openGraph()->render(),
208 27
            $this->twitter()->render(),
209 27
        ]));
210
    }
211
212
    /**
213
     * Render the tag.
214
     *
215
     * @return string
216
     */
217 18
    public function __toString()
218
    {
219 18
        return $this->render();
220
    }
221
222
    /**
223
     * Enable the OpenGraph.
224
     *
225
     * @return self
226
     */
227 3
    public function enableOpenGraph()
228
    {
229 3
        $this->openGraph()->enable();
230
231 3
        return $this;
232
    }
233
234
    /**
235
     * Disable the OpenGraph.
236
     *
237
     * @return self
238
     */
239 3
    public function disableOpenGraph()
240
    {
241 3
        $this->openGraph()->disable();
242
243 3
        return $this;
244
    }
245
246
    /**
247
     * Enable the Twitter Card.
248
     *
249
     * @return self
250
     */
251 3
    public function enableTwitter()
252
    {
253 3
        $this->twitter()->enable();
254
255 3
        return $this;
256
    }
257
258
    /**
259
     * Disable the Twitter Card.
260
     *
261
     * @return self
262
     */
263 3
    public function disableTwitter()
264
    {
265 3
        $this->twitter()->disable();
266
267 3
        return $this;
268
    }
269
}
270