Completed
Pull Request — master (#17)
by Vladimir
04:09
created

Configurator::isDefaultAssetEnabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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
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 (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->enableSeoOptions
145
            ? ArrayHelper::merge($this->options, $this->seoOptions)
146
            : $this->options;
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function isIconsEnabled()
153
    {
154
        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

154
        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...
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function isDefaultAssetEnabled()
161
    {
162
        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

162
        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...
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     *
168
     * @param string $driverName Class name of the needed driver.
169
     */
170
    public function getIconSelector($driverName)
171
    {
172
        return isset($this->icons[$driverName]) ? $this->icons[$driverName] : '';
173
    }
174
}
175