Completed
Pull Request — master (#17)
by Vladimir
02:18
created

Configurator   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 16
eloc 39
dl 0
loc 157
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getSocialNetworks() 0 3 1
A getOptions() 0 5 2
A canRegisterMetaTags() 0 3 1
A getIconSelector() 0 3 2
A isDefaultAssetEnabled() 0 3 2
A isSeoEnabled() 0 3 1
A isIconsEnabled() 0 3 2
A init() 0 11 5
1
<?php
2
/**
3
 * @link https://github.com/yiimaker/yii2-social-share
4
 * @copyright Copyright (c) 2017-2018 Yii Maker
5
 * @license BSD 3-Clause License
6
 */
7
8
namespace ymaker\social\share\configurators;
9
10
use yii\base\BaseObject;
11
use yii\helpers\ArrayHelper;
12
use ymaker\social\share\drivers\Facebook;
13
use ymaker\social\share\drivers\GooglePlus;
14
use ymaker\social\share\drivers\LinkedIn;
15
use ymaker\social\share\drivers\Gmail;
16
use ymaker\social\share\drivers\Trello;
17
use ymaker\social\share\drivers\WhatsApp;
18
use ymaker\social\share\drivers\Telegram;
19
use ymaker\social\share\drivers\Pinterest;
20
use ymaker\social\share\drivers\Tumblr;
21
use ymaker\social\share\drivers\Twitter;
22
use ymaker\social\share\drivers\Vkontakte;
23
use ymaker\social\share\drivers\Yahoo;
24
use ymaker\social\share\drivers\Odnoklassniki;
25
26
/**
27
 * Configurator for social network drivers.
28
 *
29
 * @author Vladimir Kuprienko <[email protected]>
30
 * @since 1.0
31
 */
32
class Configurator extends BaseObject implements ConfiguratorInterface, IconsConfigInterface, SeoConfigInterface
33
{
34
    const DEFAULT_ICONS_MAP = [
35
        Vkontakte::class     => 'si si-vk',
36
        Facebook::class      => 'si si-facebook',
37
        Twitter::class       => 'si si-twitter',
38
        GooglePlus::class    => 'si si-google-plus',
39
        LinkedIn::class      => 'si si-linkedin',
40
        Pinterest::class     => 'si si-pinterest',
41
        Telegram::class      => 'si si-telegram',
42
        WhatsApp::class      => 'si si-whatsapp',
43
        Gmail::class         => 'si si-gmail',
44
        Tumblr::class        => 'si si-tumblr',
45
        Yahoo::class         => 'si si-yahoo',
46
        Odnoklassniki::class => 'si si-odnoklassniki',
47
        Trello::class        => 'si si-trello',
48
    ];
49
50
    /**
51
     * Configuration of social network drivers.
52
     *
53
     * @var array
54
     */
55
    public $socialNetworks = [];
56
    /**
57
     * CSS options for share links.
58
     *
59
     * @var array
60
     */
61
    public $options = [];
62
    /**
63
     * Enable SEO options for share links.
64
     *
65
     * @var bool
66
     */
67
    public $enableSeoOptions = true;
68
    /**
69
     * HTML attributes from this option will be applied if `enableSeoOptions` is true.
70
     *
71
     * @var array
72
     */
73
    public $seoOptions = [];
74
    /**
75
     * Enable default icons instead labels for social networks.
76
     *
77
     * @var bool
78
     *
79
     * @deprecated since 2.3
80
     */
81
    public $enableDefaultIcons = false;
82
    /**
83
     * Enable icons instead of text labels.
84
     *
85
     * @var bool
86
     *
87
     * @since 2.3
88
     */
89
    public $enableIcons = false;
90
    /**
91
     * Enable default icons asset.
92
     *
93
     * @var bool
94
     *
95
     * @since 2.3
96
     */
97
    public $enableDefaultAsset = true;
98
    /**
99
     * Configuration of icons for social network drivers.
100
     *
101
     * @var array
102
     */
103
    public $icons = [];
104
    /**
105
     * Enable registering of drivers meta tags.
106
     *
107
     * @var bool
108
     *
109
     * @since 2.1
110
     */
111
    public $registerMetaTags = true;
112
113
114
    /**
115
     * Set default values for special link options.
116
     */
117
    public function init()
118
    {
119
        if ($this->isSeoEnabled() && empty($this->seoOptions)) {
120
            $this->seoOptions = [
121
                'target' => '_blank',
122
                'rel'    => 'noopener',
123
            ];
124
        }
125
126
        if ($this->enableIcons || $this->enableDefaultIcons) {
0 ignored issues
show
Deprecated Code introduced by
The property ymaker\social\share\conf...or::$enableDefaultIcons has been deprecated: since 2.3 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

126
        if ($this->enableIcons || /** @scrutinizer ignore-deprecated */ $this->enableDefaultIcons) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
127
            $this->icons = ArrayHelper::merge(self::DEFAULT_ICONS_MAP, $this->icons);
128
        }
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function getSocialNetworks()
135
    {
136
        return $this->socialNetworks;
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142
    public function getOptions()
143
    {
144
        return $this->isSeoEnabled()
145
            ? ArrayHelper::merge($this->options, $this->seoOptions)
146
            : $this->options;
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function canRegisterMetaTags()
153
    {
154
        return $this->registerMetaTags;
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function isIconsEnabled()
161
    {
162
        return $this->enableIcons || $this->enableDefaultIcons;
0 ignored issues
show
Deprecated Code introduced by
The property ymaker\social\share\conf...or::$enableDefaultIcons has been deprecated: since 2.3 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

162
        return $this->enableIcons || /** @scrutinizer ignore-deprecated */ $this->enableDefaultIcons;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     */
168
    public function isDefaultAssetEnabled()
169
    {
170
        return $this->enableDefaultAsset || $this->enableDefaultIcons;
0 ignored issues
show
Deprecated Code introduced by
The property ymaker\social\share\conf...or::$enableDefaultIcons has been deprecated: since 2.3 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

170
        return $this->enableDefaultAsset || /** @scrutinizer ignore-deprecated */ $this->enableDefaultIcons;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
171
    }
172
173
    /**
174
     * {@inheritdoc}
175
     *
176
     * @param string $driverName Class name of the needed driver.
177
     */
178
    public function getIconSelector($driverName)
179
    {
180
        return isset($this->icons[$driverName]) ? $this->icons[$driverName] : '';
181
    }
182
183
    /**
184
     * {@inheritdoc}
185
     */
186
    public function isSeoEnabled()
187
    {
188
        return $this->enableSeoOptions;
189
    }
190
}
191