GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 764334...261594 )
by Alexey
33:15
created

Bootstrap   A

Complexity

Total Complexity 37

Size/Duplication

Total Lines 307
Duplicated Lines 1.3 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 4
loc 307
rs 9.44
c 0
b 0
f 0
wmc 37
lcom 1
cbo 1

22 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCoreCss() 0 5 2
A registerResponsiveCss() 0 8 2
A registerYiiCss() 0 4 1
A registerAllCss() 0 6 1
A registerCoreScripts() 0 5 1
A registerJS() 0 8 2
A register() 0 5 1
A registerAffix() 0 4 1
A registerAlert() 0 4 1
A registerButton() 0 4 1
A registerCarousel() 0 4 1
A registerCollapse() 0 4 1
A registerDropdown() 0 4 1
A registerModal() 0 4 1
A registerScrollSpy() 0 4 1
A registerPopover() 2 7 3
A registerTabs() 0 4 1
A registerTooltip() 2 6 3
A registerTypeahead() 0 4 1
B registerPlugin() 0 18 8
A getAssetsUrl() 0 11 2
A getVersion() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Bootstrap class file.
4
 * @author Christoffer Niska <[email protected]>
5
 * @copyright Copyright &copy; Christoffer Niska 2011-
6
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
7
 * @version 2.0.3
8
 */
9
10
/**
11
 * Bootstrap application component.
12
 */
13
class Bootstrap extends CApplicationComponent
14
{
15
	// Bootstrap plugins.
16
	const PLUGIN_AFFIX = 'affix';
17
	const PLUGIN_ALERT = 'alert';
18
    const PLUGIN_BUTTON = 'button';
19
    const PLUGIN_CAROUSEL = 'carousel';
20
    const PLUGIN_COLLAPSE = 'collapse';
21
    const PLUGIN_DROPDOWN = 'dropdown';
22
    const PLUGIN_MODAL = 'modal';
23
    const PLUGIN_POPOVER = 'popover';
24
    const PLUGIN_SCROLLSPY = 'scrollspy';
25
    const PLUGIN_TAB = 'tab';
26
    const PLUGIN_TOOLTIP = 'tooltip';
27
    const PLUGIN_TRANSITION = 'transition';
28
    const PLUGIN_TYPEAHEAD = 'typeahead';
29
30
	/**
31
	 * @var array plugin initial options (name=>options).
32
	 * Each array key-value pair represents the initial options for a single plugin class,
33
	 * with the array key being the plugin name, and array value being the initial options array.
34
	 * @since 0.9.8
35
	 */
36
	public $plugins = array();
37
	/**
38
	 * @var boolean indicates whether assets should be republished on every request.
39
	 */
40
	public $forceCopyAssets = false;
41
42
	protected $_assetsUrl;
43
44
	/**
45
	 * Registers the Bootstrap CSS.
46
	 */
47
	public function registerCoreCss()
48
	{
49
		$filename = YII_DEBUG ? 'bootstrap.css' : 'bootstrap.min.css';
50
		Yii::app()->clientScript->registerCssFile($this->getAssetsUrl().'/css/'.$filename);
51
	}
52
53
	/**
54
	 * Registers the Bootstrap responsive CSS.
55
	 * @since 0.9.8
56
	 */
57
	public function registerResponsiveCss()
58
	{
59
		/** @var CClientScript $cs */
60
		$cs = Yii::app()->getClientScript();
61
		$cs->registerMetaTag('width=device-width, initial-scale=1.0', 'viewport');
62
		$filename = YII_DEBUG ? 'bootstrap-responsive.css' : 'bootstrap-responsive.min.css';
63
		$cs->registerCssFile($this->getAssetsUrl().'/css/'.$filename);
64
	}
65
66
	/**
67
	 * Registers the Yii-specific CSS missing from Bootstrap.
68
	 * @since 0.9.11
69
	 */
70
	public function registerYiiCss()
71
	{
72
		Yii::app()->clientScript->registerCssFile($this->getAssetsUrl().'/css/yii.css');
73
	}
74
75
	/**
76
	 * Registers all Bootstrap CSS.
77
	 * @since 2.0.0
78
	 */
79
	public function registerAllCss()
80
	{
81
		$this->registerCoreCss();
82
		$this->registerResponsiveCss();
83
		$this->registerYiiCss();
84
	}
85
86
	/**
87
	 * Registers the core JavaScript.
88
	 * @since 0.9.8
89
	 */
90
	public function registerCoreScripts()
91
	{
92
		$this->registerJS(Yii::app()->clientScript->coreScriptPosition);
93
		$this->registerPopover(); // popover also registers tooltip
94
	}
95
96
	/**
97
	 * Registers the Bootstrap JavaScript.
98
	 * @param int $position the position of the JavaScript code.
99
	 */
100
	protected function registerJS($position = CClientScript::POS_HEAD)
101
	{
102
		/** @var CClientScript $cs */
103
		$cs = Yii::app()->getClientScript();
104
		$cs->registerCoreScript('jquery');
105
		$filename = YII_DEBUG ? 'bootstrap.js' : 'bootstrap.min.js';
106
		$cs->registerScriptFile($this->getAssetsUrl().'/js/'.$filename, $position);
107
	}
108
109
	/**
110
	 * Registers all Bootstrap CSS and JavaScript.
111
	 * @since 2.1.0
112
	 */
113
	public function register()
114
	{
115
		$this->registerAllCss();
116
		$this->registerCoreScripts();
117
	}
118
119
	/**
120
	 * Registers the Bootstrap affix plugin.
121
	 * @param string $selector the CSS selector
122
	 * @param array $options the plugin options
123
	 * @see http://twitter.github.com/bootstrap/javascript.html#affix
124
	 * @since 2.0.0
125
	 */
126
	public function registerAffix($selector = null, $options = array())
127
	{
128
		$this->registerPlugin(self::PLUGIN_AFFIX, $selector, $options);
129
	}
130
131
	/**
132
	 * Registers the Bootstrap alert plugin.
133
	 * @param string $selector the CSS selector
134
	 * @param array $options the plugin options
135
	 * @see http://twitter.github.com/bootstrap/javascript.html#alerts
136
	 * @since 0.9.8
137
	 */
138
	public function registerAlert($selector = null, $options = array())
139
	{
140
		$this->registerPlugin(self::PLUGIN_ALERT, $selector, $options);
141
	}
142
143
	/**
144
	 * Registers the Bootstrap buttons plugin.
145
	 * @param string $selector the CSS selector
146
	 * @param array $options the plugin options
147
	 * @see http://twitter.github.com/bootstrap/javascript.html#buttons
148
	 * @since 0.9.8
149
	 */
150
	public function registerButton($selector = null, $options = array())
151
	{
152
		$this->registerPlugin(self::PLUGIN_BUTTON, $selector, $options);
153
	}
154
155
	/**
156
	 * Registers the Bootstrap carousel plugin.
157
	 * @param string $selector the CSS selector
158
	 * @param array $options the plugin options
159
	 * @see http://twitter.github.com/bootstrap/javascript.html#carousel
160
	 * @since 0.9.8
161
	 */
162
	public function registerCarousel($selector = null, $options = array())
163
	{
164
		$this->registerPlugin(self::PLUGIN_CAROUSEL, $selector, $options);
165
	}
166
167
	/**
168
	 * Registers the Bootstrap collapse plugin.
169
	 * @param string $selector the CSS selector
170
	 * @param array $options the plugin options
171
	 * @see http://twitter.github.com/bootstrap/javascript.html#collapse
172
	 * @since 0.9.8
173
	 */
174
	public function registerCollapse($selector = null, $options = array())
175
	{
176
		$this->registerPlugin(self::PLUGIN_COLLAPSE, $selector, $options);
177
	}
178
179
	/**
180
	 * Registers the Bootstrap dropdowns plugin.
181
	 * @param string $selector the CSS selector
182
	 * @param array $options the plugin options
183
	 * @see http://twitter.github.com/bootstrap/javascript.html#dropdowns
184
	 * @since 0.9.8
185
	 */
186
	public function registerDropdown($selector = null, $options = array())
187
	{
188
		$this->registerPlugin(self::PLUGIN_DROPDOWN, $selector, $options);
189
	}
190
191
	/**
192
	 * Registers the Bootstrap modal plugin.
193
	 * @param string $selector the CSS selector
194
	 * @param array $options the plugin options
195
	 * @see http://twitter.github.com/bootstrap/javascript.html#modal
196
	 * @since 0.9.8
197
	 */
198
	public function registerModal($selector = null, $options = array())
199
	{
200
		$this->registerPlugin(self::PLUGIN_MODAL, $selector, $options);
201
	}
202
203
	/**
204
	 * Registers the Bootstrap scrollspy plugin.
205
	 * @param string $selector the CSS selector
206
	 * @param array $options the plugin options
207
	 * @see http://twitter.github.com/bootstrap/javascript.html#scrollspy
208
	 * @since 0.9.8
209
	 */
210
	public function registerScrollSpy($selector = null, $options = array())
211
	{
212
		$this->registerPlugin(self::PLUGIN_SCROLLSPY, $selector, $options);
213
	}
214
215
	/**
216
	 * Registers the Bootstrap popover plugin.
217
	 * @param string $selector the CSS selector
218
	 * @param array $options the plugin options
219
	 * @see http://twitter.github.com/bootstrap/javascript.html#popover
220
	 * @since 0.9.8
221
	 */
222
	public function registerPopover($selector = null, $options = array())
223
	{
224
		$this->registerTooltip(); // Popover requires the tooltip plugin
225 View Code Duplication
		if (!isset($options['selector']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
			$options['selector'] = $selector !== null ? $selector : 'a[rel=popover]';
227
		$this->registerPlugin(self::PLUGIN_POPOVER, 'body', $options);
228
	}
229
230
	/**
231
	 * Registers the Bootstrap tabs plugin.
232
	 * @param string $selector the CSS selector
233
	 * @param array $options the plugin options
234
	 * @see http://twitter.github.com/bootstrap/javascript.html#tabs
235
	 * @since 0.9.8
236
	 */
237
	public function registerTabs($selector = null, $options = array())
238
	{
239
		$this->registerPlugin(self::PLUGIN_TAB, $selector, $options);
240
	}
241
242
	/**
243
	 * Registers the Bootstrap tooltip plugin.
244
	 * @param string $selector the CSS selector
245
	 * @param array $options the plugin options
246
	 * @see http://twitter.github.com/bootstrap/javascript.html#tooltip
247
	 * @since 0.9.8
248
	 */
249
	public function registerTooltip($selector = null, $options = array())
250
	{
251 View Code Duplication
		if (!isset($options['selector']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
			$options['selector'] = $selector !== null ? $selector : 'a[rel=tooltip]';
253
		$this->registerPlugin(self::PLUGIN_TOOLTIP, 'body', $options);
254
	}
255
256
	/**
257
	 * Registers the Bootstrap typeahead plugin.
258
	 * @param string $selector the CSS selector
259
	 * @param array $options the plugin options
260
	 * @see http://twitter.github.com/bootstrap/javascript.html#typeahead
261
	 * @since 0.9.8
262
	 */
263
	public function registerTypeahead($selector = null, $options = array())
264
	{
265
		$this->registerPlugin(self::PLUGIN_TYPEAHEAD, $selector, $options);
266
	}
267
268
	/**
269
	 * Registers a Bootstrap JavaScript plugin.
270
	 * @param string $name the name of the plugin
271
	 * @param string $selector the CSS selector
272
	 * @param array $options the plugin options
273
	 * @param string $defaultSelector the default CSS selector
0 ignored issues
show
Documentation introduced by
There is no parameter named $defaultSelector. Did you maybe mean $selector?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
274
	 * @since 0.9.8
275
	 */
276
	protected function registerPlugin($name, $selector = null, $options = array())
277
	{
278
		// Initialization from extension configuration.
279
		$config = isset($this->plugins[$name]) ? $this->plugins[$name] : array();
280
281
		if ($selector === null && isset($config['selector']))
282
			$selector = $config['selector'];
283
284
		if (isset($config['options']))
285
			$options = !empty($options) ? CMap::mergeArray($options, $config['options']) : $config['options'];
286
287
		if ($selector !== null)
288
		{
289
			$key = __CLASS__.'.'.md5($name.$selector.serialize($options));
290
			$options = !empty($options) ? CJavaScript::encode($options) : '';
291
			Yii::app()->clientScript->registerScript($key, "jQuery('{$selector}').{$name}({$options});");
292
		}
293
	}
294
295
	/**
296
	* Returns the URL to the published assets folder.
297
	* @return string the URL
298
	*/
299
	protected function getAssetsUrl()
300
	{
301
		if (isset($this->_assetsUrl))
302
			return $this->_assetsUrl;
303
		else
304
		{
305
			$assetsPath = Yii::getPathOfAlias('bootstrap.assets');
306
			$assetsUrl = Yii::app()->assetManager->publish($assetsPath, true, -1, $this->forceCopyAssets);
307
			return $this->_assetsUrl = $assetsUrl;
308
		}
309
	}
310
311
    /**
312
     * Returns the extension version number.
313
     * @return string the version
314
     */
315
    public function getVersion()
316
    {
317
        return '2.0.3';
318
    }
319
}
320