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

SeoTwitter::disable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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