Completed
Push — master ( 9dd421...3802d8 )
by ARCANEDEV
15s
created

SeoOpenGraph   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 306
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 306
c 0
b 0
f 0
ccs 57
cts 57
cp 1
rs 10
wmc 21
lcom 1
cbo 3

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A setEnabled() 0 6 1
A setOpenGraph() 0 6 1
A setPrefix() 0 6 1
A setType() 0 6 1
A setTitle() 0 6 1
A setDescription() 0 6 1
A setUrl() 0 6 1
A setImage() 0 6 1
A setSiteName() 0 6 1
A setLocale() 0 6 1
A setAlternativeLocales() 0 6 1
A addProperties() 0 6 1
A addProperty() 0 6 1
A render() 0 4 2
A __toString() 0 4 1
A enable() 0 4 1
A disable() 0 4 1
A isEnabled() 0 4 1
A isDisabled() 0 4 1
1
<?php namespace Arcanedev\SeoHelper;
2
3
use Arcanedev\SeoHelper\Contracts\Entities\OpenGraph as OpenGraphContract;
4
use Arcanedev\SeoHelper\Contracts\SeoOpenGraph as SeoOpenGraphContract;
5
use Arcanedev\Support\Traits\Configurable;
6
7
/**
8
 * Class     SeoOpenGraph
9
 *
10
 * @package  Arcanedev\SeoHelper
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class SeoOpenGraph implements SeoOpenGraphContract
14
{
15
    /* -----------------------------------------------------------------
16
     |  Traits
17
     | -----------------------------------------------------------------
18
     */
19
20
    use Configurable;
21
22
    /* -----------------------------------------------------------------
23
     |  Properties
24
     | -----------------------------------------------------------------
25
     */
26
27
    /**
28
     * Enable or Disable the OpenGraph.
29
     *
30
     * @var bool
31
     */
32
    protected $enabled;
33
34
    /**
35
     * The Open Graph instance.
36
     *
37
     * @var \Arcanedev\SeoHelper\Contracts\Entities\OpenGraph
38
     */
39
    protected $openGraph;
40
41
    /* -----------------------------------------------------------------
42
     |  Constructor
43
     | -----------------------------------------------------------------
44
     */
45
46
    /**
47
     * Make SeoOpenGraph instance.
48
     *
49
     * @param  array  $configs
50
     */
51 70
    public function __construct(array $configs)
52
    {
53 70
        $this->setConfigs($configs);
54
55 70
        $this->setEnabled($this->getConfig('open-graph.enabled', false));
56 70
        $this->setOpenGraph(
57 70
            new Entities\OpenGraph\Graph($this->getConfig('open-graph', []))
58
        );
59 70
    }
60
61
    /* -----------------------------------------------------------------
62
     |  Getters & Setters
63
     | -----------------------------------------------------------------
64
     */
65
66
    /**
67
     * Set the enabled status for the OpenGraph.
68
     *
69
     * @param  bool  $enabled
70
     *
71
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
72
     */
73 70
    private function setEnabled($enabled)
74
    {
75 70
        $this->enabled = $enabled;
76
77 70
        return $this;
78
    }
79
80
    /**
81
     * Set the Open Graph instance.
82
     *
83
     * @param  \Arcanedev\SeoHelper\Contracts\Entities\OpenGraph  $openGraph
84
     *
85
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
86
     */
87 70
    public function setOpenGraph(OpenGraphContract $openGraph)
88
    {
89 70
        $this->openGraph = $openGraph;
90
91 70
        return $this;
92
    }
93
94
    /**
95
     * Set the open graph prefix.
96
     *
97
     * @param  string  $prefix
98
     *
99
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
100
     */
101 2
    public function setPrefix($prefix)
102
    {
103 2
        $this->openGraph->setPrefix($prefix);
104
105 2
        return $this;
106
    }
107
108
    /**
109
     * Set type property.
110
     *
111
     * @param  string  $type
112
     *
113
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
114
     */
115 2
    public function setType($type)
116
    {
117 2
        $this->openGraph->setType($type);
118
119 2
        return $this;
120
    }
121
122
    /**
123
     * Set title property.
124
     *
125
     * @param  string  $title
126
     *
127
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
128
     */
129 10
    public function setTitle($title)
130
    {
131 10
        $this->openGraph->setTitle($title);
132
133 10
        return $this;
134
    }
135
136
    /**
137
     * Set description property.
138
     *
139
     * @param  string  $description
140
     *
141
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
142
     */
143 6
    public function setDescription($description)
144
    {
145 6
        $this->openGraph->setDescription($description);
146
147 6
        return $this;
148
    }
149
150
    /**
151
     * Set url property.
152
     *
153
     * @param  string  $url
154
     *
155
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
156
     */
157 2
    public function setUrl($url)
158
    {
159 2
        $this->openGraph->setUrl($url);
160
161 2
        return $this;
162
    }
163
164
    /**
165
     * Set image property.
166
     *
167
     * @param  string  $image
168
     *
169
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
170
     */
171 4
    public function setImage($image)
172
    {
173 4
        $this->openGraph->setImage($image);
174
175 4
        return $this;
176
    }
177
178
    /**
179
     * Set site name property.
180
     *
181
     * @param  string  $siteName
182
     *
183
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
184
     */
185 10
    public function setSiteName($siteName)
186
    {
187 10
        $this->openGraph->setSiteName($siteName);
188
189 10
        return $this;
190
    }
191
192
    /**
193
     * Set the locale.
194
     *
195
     * @param  string  $locale
196
     *
197
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
198
     */
199 2
    public function setLocale($locale)
200
    {
201 2
        $this->openGraph->setLocale($locale);
202
203 2
        return $this;
204
    }
205
206
    /**
207
     * Set the alternative locales.
208
     *
209
     * @param  array  $locales
210
     *
211
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
212
     */
213 2
    public function setAlternativeLocales(array $locales)
214
    {
215 2
        $this->openGraph->setAlternativeLocales($locales);
216
217 2
        return $this;
218
    }
219
220
    /**
221
     * Add many open graph properties.
222
     *
223
     * @param  array  $properties
224
     *
225
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
226
     */
227 2
    public function addProperties(array $properties)
228
    {
229 2
        $this->openGraph->addProperties($properties);
230
231 2
        return $this;
232
    }
233
234
    /**
235
     * Add an open graph property.
236
     *
237
     * @param  string  $property
238
     * @param  string  $content
239
     *
240
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
241
     */
242 2
    public function addProperty($property, $content)
243
    {
244 2
        $this->openGraph->addProperty($property, $content);
245
246 2
        return $this;
247
    }
248
249
    /* -----------------------------------------------------------------
250
     |  Main Methods
251
     | -----------------------------------------------------------------
252
     */
253
254
    /**
255
     * Render the tag.
256
     *
257
     * @return string
258
     */
259 52
    public function render()
260
    {
261 52
        return $this->isEnabled() ? $this->openGraph->render() : '';
262
    }
263
264
    /**
265
     * Render the tag.
266
     *
267
     * @return string
268
     */
269 20
    public function __toString()
270
    {
271 20
        return $this->render();
272
    }
273
274
    /**
275
     * Enable the OpenGraph.
276
     *
277
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
278
     */
279 4
    public function enable()
280
    {
281 4
        return $this->setEnabled(true);
282
    }
283
284
    /**
285
     * Disable the OpenGraph.
286
     *
287
     * @return \Arcanedev\SeoHelper\SeoOpenGraph
288
     */
289 4
    public function disable()
290
    {
291 4
        return $this->setEnabled(false);
292
    }
293
294
    /* -----------------------------------------------------------------
295
     |  Check Methods
296
     | -----------------------------------------------------------------
297
     */
298
299
    /**
300
     * Check if the OpenGraph is enabled.
301
     *
302
     * @return bool
303
     */
304 52
    public function isEnabled()
305
    {
306 52
        return $this->enabled;
307
    }
308
309
    /**
310
     * Check if the OpenGraph is disabled.
311
     *
312
     * @return bool
313
     */
314 4
    public function isDisabled()
315
    {
316 4
        return ! $this->isEnabled();
317
    }
318
}
319