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.

TbSwitch   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 75
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 16 3
A registerClientScript() 0 17 4
1
<?php
2
/**
3
 *## TbToggleButton class file
4
 *
5
 * @author: amr bedair <[email protected]>
6
 */
7
8
/**
9
 *## Class TbToggleButton
10
 * @see <http://www.bootstrap-switch.org/>
11
 * @package booster.widgets.forms.buttons
12
 *
13
 */
14
class TbSwitch extends CInputWidget {
15
16
	/**
17
	 * @var TbActiveForm when created via TbActiveForm, this attribute is set to the form that renders the widget
18
	 * @see TbActionForm->inputRow
19
	 */
20
	public $form;
21
22
	/**
23
	 * @var array the javascript events
24
	 *
25
	 * Example:
26
	 * <pre>
27
	 *  'events'=>array(
28
	 * 		'switchChange'=>'js:function(event, state) {
29
	 *			console.log(this); // DOM element
30
	 *			console.log(event); // jQuery event
31
	 *			console.log(state); // true | false
32
 	 *		}'
33
	 *	)
34
	 * </pre>
35
	 */
36
	public $events = array();
37
38
	/**
39
	 * js widget options
40
	 * @see <http://www.bootstrap-switch.org/> options part
41
	 * @var array to contain the widget js options
42
	 */
43
	public $options = array();
44
45
	/**
46
	 * Widget's run function
47
	 */
48
	public function run() {
49
50
		list($name, $id) = $this->resolveNameID();
51
52
		if ($this->hasModel()) {
53
			if ($this->form) {
54
				echo $this->form->checkBox($this->model, $this->attribute, $this->htmlOptions);
55
			} else {
56
				echo CHtml::activeCheckBox($this->model, $this->attribute, $this->htmlOptions);
57
			}
58
		} else {
59
			echo CHtml::checkBox($name, $this->value, $this->htmlOptions);
60
		}
61
62
		$this->registerClientScript($id);
63
	}
64
65
	/**
66
	 * Registers required css and js files
67
	 *
68
	 * @param integer $id the id of the toggle button
69
	 */
70
	protected function registerClientScript($id) {
71
72
        $booster = Booster::getBooster();
73
        $booster->registerPackage('switch');
74
		$config = CJavaScript::encode($this->options);
75
76
		ob_start();
77
		echo "$('input#$id').bootstrapSwitch({$config})";
78
		foreach ($this->events as $event => $handler) {
79
			$event = $event.'.bootstrapSwitch';
80
			if (!$handler instanceof CJavaScriptExpression && strpos($handler, 'js:') === 0)
0 ignored issues
show
Bug introduced by
The class CJavaScriptExpression does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
81
				$handler = new CJavaScriptExpression($handler);
82
			echo ".on('{$event}', " . $handler . ")";
83
		}
84
85
		Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');
86
	}
87
88
}
89