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::run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 0
cts 13
cp 0
rs 9.4285
cc 3
eloc 10
nc 3
nop 0
crap 12
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