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.

TbFormInputElement::evaluateVisible()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
4
class TbFormInputElement extends CFormElement {
5
	
6
	/**
7
	 * Input types (alias => TbActiveForm method name).
8
	 * @var array
9
	 */
10
	public static $inputTypes = array(
11
		// standard fields
12
		'text' => 'textFieldGroup',
13
		'hidden' => 'hiddenField',
14
		'password' => 'passwordFieldGroup',
15
		'textarea' => 'textAreaGroup',
16
		'file' => 'fileFieldGroup',
17
		'radio' => 'radioButtonGroup',
18
		'checkbox' => 'checkBoxGroup',
19
		'listbox' => 'listBoxGroup',
20
		'dropdownlist' => 'dropDownListGroup',
21
		'checkboxlist' => 'checkBoxListGroup',
22
		'radiolist' => 'radioButtonListGroup',
23
		'url' => 'urlFieldGroup',
24
		'email' => 'emailFieldGroup',
25
		'number' => 'numberFieldGroup',
26
		'range' => 'rangeFieldGroup',
27
		'date' => 'dateFieldGroup',
28
		'time' => 'timeFieldGroup',
29
		'tel' => 'telFieldGroup',
30
		'search' => 'searchFieldGroup',
31
		// extended fields
32
		'switch' => 'switchGroup',
33
		'datepicker' => 'datePickerGroup',
34
		'daterange' => 'dateRangeGroup',
35
		'timepicker' => 'timePickerGroup',
36
		'datetimepicker' => 'dateTimePickerGroup',
37
		'select2' => 'select2Group',
38
		'redactor' => 'redactorGroup',
39
		'html5editor' => 'html5EditorGroup',
40
		'markdowneditor' => 'markdownEditorGroup',
41
		'ckeditor' => 'ckEditorGroup',
42
		'typeahead' => 'typeAheadGroup',
43
		'maskedtext' => 'maskedTextFieldGroup',
44
		'colorpicker' => 'colorPickerGroup',
45
		//'captcha' => 'captchaGroup',
46
		'pass' => 'passFieldGroup'
47
	);
48
	
49
	public $widgetOptions = array();
50
51
	/**
52
	 * The type of this input. This can be a widget class name, a path alias of a widget class name,
53
	 * or an input type alias (text, hidden, password, textarea, file, etc.).
54
	 * If a widget class, it must extend from {@link CInputWidget} or (@link CJuiInputWidget).
55
	 * @var string
56
	 */
57
	public $type;
58
59
	/**
60
	 * @var string Name of this input.
61
	 */
62
	public $name;
63
64
	/**
65
	 * Label for this input.
66
	 * @var string
67
	 */
68
	public $label;
69
70
	/**
71
	 * The options used when rendering label part. This property will be passed to the {@link CActiveForm::labelEx}
72
	 * or {@link CHtml::label} if $label is defined, method call as its $htmlOptions parameter.
73
	 * @var array
74
	 * @see CActiveForm::labelEx
75
	 * @see CHtml::label
76
	 */
77
	public $labelOptions;
78
79
	/**
80
	 * Hint text of this input.
81
	 * @var string
82
	 */
83
	public $hint;
84
85
	/**
86
	 * The options used when rendering hint part.
87
	 * This property will be passed as $htmlOptions parameter for hint wrapper tag.
88
	 * @var array
89
	 */
90
	public $hintOptions;
91
92
	/**
93
	 * Text/html prepended to input field.
94
	 * @var string
95
	 */
96
	public $prepend;
97
98
	/**
99
	 * The options used when rendering prepend part.
100
	 * This property will be passed as $htmlOptions parameter for prepend wrapper tag.
101
	 * @var array
102
	 */
103
	public $prependOptions;
104
105
	/**
106
	 * Text/html appended to input field.
107
	 * @var string
108
	 */
109
	public $append;
110
111
	/**
112
	 * The options used when rendering append part.
113
	 * This property will be passed as $htmlOptions parameter for append wrapper tag.
114
	 * @var array
115
	 */
116
	public $appendOptions;
117
118
	/**
119
	 * The options for this input when it is a list box, drop-down list, check box list, or radio button list.
120
	 * Please see {@link CHtml::listData} for details of generating this property value.
121
	 * @var array
122
	 */
123
	public $items = array();
124
125
	/**
126
	 * The options used when rendering the error part. This property will be passed
127
	 * to the {@link CActiveForm::error} method call as its $htmlOptions parameter.
128
	 * @var array
129
	 * @see CActiveForm::error
130
	 */
131
	public $errorOptions = array();
132
133
	/**
134
	 * Whether to allow AJAX-based validation for this input. Note that in order to use
135
	 * AJAX-based validation, {@link CForm::activeForm} must be configured with 'enableAjaxValidation'=>true.
136
	 * This property allows turning on or off  AJAX-based validation for individual input fields.
137
	 * Defaults to true.
138
	 * @var boolean
139
	 */
140
	public $enableAjaxValidation = true;
141
142
	/**
143
	 * Whether to allow client-side validation for this input. Note that in order to use
144
	 * client-side validation, {@link CForm::activeForm} must be configured with 'enableClientValidation'=>true.
145
	 * This property allows turning on or off  client-side validation for individual input fields.
146
	 * Defaults to true.
147
	 * @var boolean
148
	 */
149
	public $enableClientValidation = true;
150
151
	/**
152
	 * Generates row options array from this class properties.
153
	 * @return array The row options.
154
	 */
155 1
	protected function generateGroupOptions() {
156
		
157 1
		$options = array();
158 1
		$fields = array('widgetOptions, label', 'labelOptions', 'errorOptions', 'hint', 'hintOptions', 'prepend', 'prependOptions',
159 1
			'append', 'appendOptions', 'enableAjaxValidation', 'enableClientValidation');
160
161 1
		foreach ($fields as $prop) {
162 1
			if (isset($this->$prop)) {
163 1
				$options[$prop] = $this->$prop;
164 1
			}
165 1
		}
166
		
167 1
		$options['widgetOptions']['data'] = $this->items;
168
169 1
		return $options;
170
	}
171
172
	/**
173
	 * Render this element.
174
	 * @return string The rendered element.
175
	 */
176 1
	public function render() {
177
		
178 1
		$model = $this->getParent()->getModel();
179 1
		$attribute = $this->name;
180 1
		$options = $this->generateGroupOptions();
181
182 1
		if (isset(self::$inputTypes[$this->type])) {
183 1
			$method = self::$inputTypes[$this->type];
184
			// FIXME ... why we are passing $this->attributes ... most all TbActiveForm method only require $options 
185 1
			return $this->getParent()->getActiveFormWidget()->$method($model, $attribute, $this->attributes, $options);
186
			/* no need for this as now data goes inside $options['widgetOptions']['data']
187
			switch ($method) {
188
				case 'listBoxGroup':
189
				case 'dropDownListGroup':
190
				case 'checkBoxListGroup':
191
				case 'radioButtonListGroup': 
192
					return $this->getParent()->getActiveFormWidget()->$method($model, $attribute, $this->attributes, $this->items, $options);
193
194
				default:
195
					return $this->getParent()->getActiveFormWidget()->$method($model, $attribute, $this->attributes, $options);
196
			}
197
			*/
198
		} else {
199
			$attributes = $this->attributes;
200
			$attributes['model'] = $this->getParent()->getModel();
201
			$attributes['attribute'] = $this->name;
202
203
			return $this->getParent()->getActiveFormWidget()->customFieldGroup(
204
				array(array($this->getParent()->getOwner(), 'widget'), array($this->type, $attributes, true)),
205
				$model,
206
				$attribute,
207
				$options
208
			);
209
		}
210
	}
211
212
	/**
213
	 * Evaluates the visibility of this element. This method will check if the attribute associated with this
214
	 * input is safe for the current model scenario.
215
	 * @return bool Whether this element is visible.
216
	 */
217 1
	protected function evaluateVisible() {
218
		
219 1
		return $this->getParent()->getModel()->isAttributeSafe($this->name);
220
	}
221
}
222