Passed
Push — master ( dfafd9...336023 )
by Jean-Christophe
02:15
created
Ajax/semantic/widgets/base/InstanceViewer.php 1 patch
Spacing   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
 
30 30
 	protected $groupByFields;
31 31
 
32
-	public static $index = 0;
32
+	public static $index=0;
33 33
 
34
-	public function __construct($identifier, $instance = NULL, $captions = NULL) {
35
-		$this->widgetIdentifier = $identifier;
36
-		$this->values = [];
37
-		$this->afterCompile = [];
34
+	public function __construct($identifier, $instance=NULL, $captions=NULL) {
35
+		$this->widgetIdentifier=$identifier;
36
+		$this->values=[];
37
+		$this->afterCompile=[];
38 38
 		if (isset($instance))
39 39
 			$this->setInstance($instance);
40 40
 		$this->setCaptions($captions);
41
-		$this->captionCallback = NULL;
42
-		$this->defaultValueFunction = function ($name, $value) {
41
+		$this->captionCallback=NULL;
42
+		$this->defaultValueFunction=function($name, $value) {
43 43
 			return $value;
44 44
 		};
45 45
 	}
@@ -66,47 +66,47 @@  discard block
 block discarded – undo
66 66
 	}
67 67
 
68 68
 	public function getValues() {
69
-		$values = [];
70
-		$index = 0;
71
-		$count = $this->count();
72
-		$hasGroupby = is_array($this->groupByFields);
73
-		if (! $hasGroupby) {
74
-			while ($index < $count) {
75
-				$values[] = $this->getValue($index ++);
69
+		$values=[];
70
+		$index=0;
71
+		$count=$this->count();
72
+		$hasGroupby=is_array($this->groupByFields);
73
+		if (!$hasGroupby) {
74
+			while ($index<$count) {
75
+				$values[]=$this->getValue($index++);
76 76
 			}
77 77
 		} else {
78
-			while ($index < $count) {
79
-				if (array_search($index, $this->groupByFields) === false) {
80
-					$values[] = $this->getValue($index);
78
+			while ($index<$count) {
79
+				if (array_search($index, $this->groupByFields)===false) {
80
+					$values[]=$this->getValue($index);
81 81
 				}
82
-				$index ++;
82
+				$index++;
83 83
 			}
84 84
 		}
85 85
 		return $values;
86 86
 	}
87 87
 
88
-	public function getIdentifier($index = NULL) {
89
-		if (! isset($index))
90
-			$index = self::$index;
91
-		$value = $index;
88
+	public function getIdentifier($index=NULL) {
89
+		if (!isset($index))
90
+			$index=self::$index;
91
+		$value=$index;
92 92
 		if (isset($this->values["identifier"])) {
93 93
 			if (\is_string($this->values["identifier"]))
94
-				$value = JReflection::callMethod($this->instance, $this->values["identifier"], []);
94
+				$value=JReflection::callMethod($this->instance, $this->values["identifier"], []);
95 95
 			else
96
-				$value = $this->values["identifier"]($index, $this->instance);
96
+				$value=$this->values["identifier"]($index, $this->instance);
97 97
 		}
98 98
 		return $value;
99 99
 	}
100 100
 
101 101
 	public function getValue($index) {
102
-		$property = $this->properties[$index];
102
+		$property=$this->properties[$index];
103 103
 		return $this->_getValue($property, $index);
104 104
 	}
105 105
 
106 106
 	protected function _beforeAddProperty($index, &$field) {}
107 107
 
108 108
 	protected function _getDefaultValue($name, $value, $index) {
109
-		$func = $this->defaultValueFunction;
109
+		$func=$this->defaultValueFunction;
110 110
 		return $func($name, $value, $index, $this->instance);
111 111
 	}
112 112
 
@@ -116,27 +116,27 @@  discard block
 block discarded – undo
116 116
 	}
117 117
 
118 118
 	protected function _getValue($property, $index) {
119
-		$value = null;
120
-		$propertyName = $property;
119
+		$value=null;
120
+		$propertyName=$property;
121 121
 		if ($property instanceof \ReflectionProperty) {
122
-			$value = $this->_getPropertyValue($property);
123
-			$propertyName = $property->getName();
124
-		} elseif (\is_callable($property) && \array_search($property, ['system','date']) === false){
125
-			try{
126
-				$value = $property($this->instance);
127
-			}catch(\Error $e){}
122
+			$value=$this->_getPropertyValue($property);
123
+			$propertyName=$property->getName();
124
+		} elseif (\is_callable($property) && \array_search($property, ['system', 'date'])===false) {
125
+			try {
126
+				$value=$property($this->instance);
127
+			}catch (\Error $e) {}
128 128
 		}
129 129
 		elseif (\is_array($property)) {
130
-			$values = \array_map(function ($v) use ($index) {
130
+			$values=\array_map(function($v) use ($index) {
131 131
 				return $this->_getValue($v, $index);
132 132
 			}, $property);
133
-			$value = \implode('', $values);
133
+			$value=\implode('', $values);
134 134
 		} elseif (\is_string($property)) {
135
-			$value = '';
135
+			$value='';
136 136
 			if (isset($this->instance->{$property})) {
137
-				$value = $this->instance->{$property};
138
-			} elseif (\method_exists($this->instance, $getter = JReflection::getterName($property))) {
139
-				$value = JReflection::callMethod($this->instance, $getter, []);
137
+				$value=$this->instance->{$property};
138
+			} elseif (\method_exists($this->instance, $getter=JReflection::getterName($property))) {
139
+				$value=JReflection::callMethod($this->instance, $getter, []);
140 140
 			}
141 141
 		}
142 142
 
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
 
146 146
 	protected function _postGetValue($index, $propertyName, $value) {
147 147
 		if (isset($this->values[$index])) {
148
-			$value = $this->values[$index]($value, $this->instance, $index, self::$index);
148
+			$value=$this->values[$index]($value, $this->instance, $index, self::$index);
149 149
 		} else {
150
-			$value = $this->_getDefaultValue($propertyName, $value, $index);
150
+			$value=$this->_getDefaultValue($propertyName, $value, $index);
151 151
 		}
152 152
 		if (isset($this->afterCompile[$index])) {
153 153
 			if (\is_callable($this->afterCompile[$index])) {
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		return $value;
158 158
 	}
159 159
 
160
-	public function insertField($index, $field, $key = null) {
160
+	public function insertField($index, $field, $key=null) {
161 161
 		if (isset($key)) {
162 162
 			array_splice($this->visibleProperties, $index, 0, [
163 163
 				$key => $field
@@ -171,29 +171,29 @@  discard block
 block discarded – undo
171 171
 	public function sortColumnContent($index, $array) {
172 172
 		if (isset($this->visibleProperties[$index])) {
173 173
 			if (is_array($this->visibleProperties[$index])) {
174
-				$this->visibleProperties[$index] = JArray::sortAssociative($this->visibleProperties[$index], $array);
174
+				$this->visibleProperties[$index]=JArray::sortAssociative($this->visibleProperties[$index], $array);
175 175
 			}
176 176
 		}
177 177
 		return $this;
178 178
 	}
179 179
 
180
-	public function insertInField($index, $field, $key = null) {
181
-		$vb = $this->visibleProperties;
180
+	public function insertInField($index, $field, $key=null) {
181
+		$vb=$this->visibleProperties;
182 182
 		if (isset($vb[$index])) {
183 183
 			if (isset($key)) {
184 184
 				if (\is_array($vb[$index])) {
185
-					$this->visibleProperties[$index][$key] = $field;
185
+					$this->visibleProperties[$index][$key]=$field;
186 186
 				} else {
187
-					$this->visibleProperties[$index] = [
187
+					$this->visibleProperties[$index]=[
188 188
 						$vb[$index],
189 189
 						$key => $field
190 190
 					];
191 191
 				}
192 192
 			} else {
193 193
 				if (\is_array($vb[$index])) {
194
-					$this->visibleProperties[$index][] = $field;
194
+					$this->visibleProperties[$index][]=$field;
195 195
 				} else {
196
-					$this->visibleProperties[$index] = [
196
+					$this->visibleProperties[$index]=[
197 197
 						$vb[$index],
198 198
 						$field
199 199
 					];
@@ -205,19 +205,19 @@  discard block
 block discarded – undo
205 205
 		return $this;
206 206
 	}
207 207
 
208
-	public function addField($field, $key = null) {
208
+	public function addField($field, $key=null) {
209 209
 		if (isset($key)) {
210
-			$this->visibleProperties[] = [
210
+			$this->visibleProperties[]=[
211 211
 				$key => $field
212 212
 			];
213 213
 		} else {
214
-			$this->visibleProperties[] = $field;
214
+			$this->visibleProperties[]=$field;
215 215
 		}
216 216
 		return $this;
217 217
 	}
218 218
 
219 219
 	public function addFields($fields) {
220
-		$this->visibleProperties = \array_merge($this->visibleProperties, $fields);
220
+		$this->visibleProperties=\array_merge($this->visibleProperties, $fields);
221 221
 		return $this;
222 222
 	}
223 223
 
@@ -234,30 +234,30 @@  discard block
 block discarded – undo
234 234
 	}
235 235
 
236 236
 	public function getFieldName($index) {
237
-		$property = $this->getProperty($index);
237
+		$property=$this->getProperty($index);
238 238
 		if ($property instanceof \ReflectionProperty) {
239
-			$result = $property->getName();
239
+			$result=$property->getName();
240 240
 		} elseif (\is_callable($property)) {
241
-			$result = $this->visibleProperties[$index];
241
+			$result=$this->visibleProperties[$index];
242 242
 		} else {
243
-			$result = $property;
243
+			$result=$property;
244 244
 		}
245 245
 		return $result;
246 246
 	}
247 247
 
248 248
 	protected function showableProperty(\ReflectionProperty $rProperty) {
249
-		return JString::startswith($rProperty->getName(), "_") === false;
249
+		return JString::startswith($rProperty->getName(), "_")===false;
250 250
 	}
251 251
 
252 252
 	public function setInstance($instance) {
253 253
 		if (\is_string($instance)) {
254
-			$instance = new $instance();
254
+			$instance=new $instance();
255 255
 		}
256
-		$this->instance = $instance;
257
-		$this->properties = [];
258
-		$this->reflect = new \ReflectionClass($instance);
259
-		if (JArray::count($this->visibleProperties) === 0) {
260
-			$this->properties = $this->getDefaultProperties();
256
+		$this->instance=$instance;
257
+		$this->properties=[];
258
+		$this->reflect=new \ReflectionClass($instance);
259
+		if (JArray::count($this->visibleProperties)===0) {
260
+			$this->properties=$this->getDefaultProperties();
261 261
 		} else {
262 262
 			foreach ($this->visibleProperties as $property) {
263 263
 				$this->setInstanceProperty($property);
@@ -268,56 +268,56 @@  discard block
 block discarded – undo
268 268
 
269 269
 	private function setInstanceProperty($property) {
270 270
 		if (\is_callable($property)) {
271
-			$this->properties[] = $property;
271
+			$this->properties[]=$property;
272 272
 		} elseif (\is_string($property)) {
273 273
 			try {
274 274
 				$this->_beforeAddProperty(\sizeof($this->properties), $property);
275
-				$rProperty = $this->reflect->getProperty($property);
276
-				$this->properties[] = $rProperty;
277
-			} catch (\Exception $e) {
275
+				$rProperty=$this->reflect->getProperty($property);
276
+				$this->properties[]=$rProperty;
277
+			}catch (\Exception $e) {
278 278
 				$this->_beforeAddProperty(\sizeof($this->properties), $property);
279
-				$this->properties[] = $property;
279
+				$this->properties[]=$property;
280 280
 			}
281 281
 		} elseif (\is_int($property)) {
282
-			$props = $this->getDefaultProperties();
282
+			$props=$this->getDefaultProperties();
283 283
 			if (isset($props[$property]))
284
-				$this->properties[] = $props[$property];
284
+				$this->properties[]=$props[$property];
285 285
 			else
286
-				$this->properties[] = $property;
286
+				$this->properties[]=$property;
287 287
 		} else {
288
-			$this->properties[] = $property;
288
+			$this->properties[]=$property;
289 289
 		}
290 290
 	}
291 291
 
292 292
 	protected function getDefaultProperties() {
293
-		$result = [];
294
-		$properties = $this->reflect->getProperties();
293
+		$result=[];
294
+		$properties=$this->reflect->getProperties();
295 295
 		foreach ($properties as $property) {
296
-			$showable = $this->showableProperty($property);
297
-			if ($showable !== false) {
298
-				$result[] = $property;
296
+			$showable=$this->showableProperty($property);
297
+			if ($showable!==false) {
298
+				$result[]=$property;
299 299
 			}
300 300
 		}
301 301
 		return $result;
302 302
 	}
303 303
 
304 304
 	public function setVisibleProperties($visibleProperties) {
305
-		$this->visibleProperties = $visibleProperties;
305
+		$this->visibleProperties=$visibleProperties;
306 306
 		return $this;
307 307
 	}
308 308
 
309 309
 	public function setValueFunction($index, $callback) {
310
-		$this->values[$index] = $callback;
310
+		$this->values[$index]=$callback;
311 311
 		return $this;
312 312
 	}
313 313
 
314 314
 	public function setIdentifierFunction($callback) {
315
-		$this->values["identifier"] = $callback;
315
+		$this->values["identifier"]=$callback;
316 316
 		return $this;
317 317
 	}
318 318
 
319 319
 	public static function setIndex($index) {
320
-		self::$index = $index;
320
+		self::$index=$index;
321 321
 	}
322 322
 
323 323
 	public function getProperties() {
@@ -337,43 +337,43 @@  discard block
 block discarded – undo
337 337
 	}
338 338
 
339 339
 	public function getCaptions() {
340
-		$hasGroupby = is_array($this->groupByFields);
341
-		$count = $this->count();
342
-		$moreAdded = false;
340
+		$hasGroupby=is_array($this->groupByFields);
341
+		$count=$this->count();
342
+		$moreAdded=false;
343 343
 		if (isset($this->captions)) {
344
-			$captions = \array_values($this->captions);
345
-			$gbSize = $hasGroupby ? sizeof($this->groupByFields) : 0;
346
-			$captionsSize = \sizeof($captions);
347
-			for ($i = $captionsSize; $i < $count - $gbSize; $i ++) {
348
-				$captions[] = "";
349
-				$moreAdded = true;
344
+			$captions=\array_values($this->captions);
345
+			$gbSize=$hasGroupby ? sizeof($this->groupByFields) : 0;
346
+			$captionsSize=\sizeof($captions);
347
+			for ($i=$captionsSize; $i<$count-$gbSize; $i++) {
348
+				$captions[]="";
349
+				$moreAdded=true;
350 350
 			}
351 351
 		} else {
352
-			$captions = [];
353
-			$index = 0;
354
-			while ($index < $count) {
355
-				$captions[] = $this->getCaption($index ++);
352
+			$captions=[];
353
+			$index=0;
354
+			while ($index<$count) {
355
+				$captions[]=$this->getCaption($index++);
356 356
 			}
357 357
 		}
358
-		if ($hasGroupby && sizeof($captions) >= $count && ! $moreAdded) {
359
-			$captions = JArray::removeByKeys($captions, $this->groupByFields);
358
+		if ($hasGroupby && sizeof($captions)>=$count && !$moreAdded) {
359
+			$captions=JArray::removeByKeys($captions, $this->groupByFields);
360 360
 		}
361 361
 		if (isset($this->captionCallback) && \is_callable($this->captionCallback)) {
362
-			$callback = $this->captionCallback;
362
+			$callback=$this->captionCallback;
363 363
 			$callback($captions, $this->instance);
364 364
 		}
365 365
 		return $captions;
366 366
 	}
367 367
 
368 368
 	public function setCaption($index, $caption) {
369
-		if (isset($this->captions) === false)
370
-			$this->captions = [];
371
-		$this->captions[$index] = $caption;
369
+		if (isset($this->captions)===false)
370
+			$this->captions=[];
371
+		$this->captions[$index]=$caption;
372 372
 		return $this;
373 373
 	}
374 374
 
375 375
 	public function setCaptions($captions) {
376
-		$this->captions = $captions;
376
+		$this->captions=$captions;
377 377
 		return $this;
378 378
 	}
379 379
 
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 	 * @return InstanceViewer
389 389
 	 */
390 390
 	public function afterCompile($index, $callback) {
391
-		$this->afterCompile[$index] = $callback;
391
+		$this->afterCompile[$index]=$callback;
392 392
 		return $this;
393 393
 	}
394 394
 
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	 * @return \Ajax\semantic\widgets\base\InstanceViewer
401 401
 	 */
402 402
 	public function setCaptionCallback($captionCallback) {
403
-		$this->captionCallback = $captionCallback;
403
+		$this->captionCallback=$captionCallback;
404 404
 		return $this;
405 405
 	}
406 406
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 	 * @return \Ajax\semantic\widgets\base\InstanceViewer
413 413
 	 */
414 414
 	public function setDefaultValueFunction($defaultValueFunction) {
415
-		$this->defaultValueFunction = $defaultValueFunction;
415
+		$this->defaultValueFunction=$defaultValueFunction;
416 416
 		return $this;
417 417
 	}
418 418
 
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
 	}
422 422
 
423 423
 	public function getSimpleProperties() {
424
-		return array_filter($this->visibleProperties, function ($item) {
425
-			return ! (is_array($item) || is_object($item));
424
+		return array_filter($this->visibleProperties, function($item) {
425
+			return !(is_array($item) || is_object($item));
426 426
 		});
427 427
 	}
428 428
 
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 	 * @param mixed $groupByFields
448 448
 	 */
449 449
 	public function setGroupByFields($groupByFields) {
450
-		$this->groupByFields = $groupByFields;
450
+		$this->groupByFields=$groupByFields;
451 451
 	}
452 452
 
453 453
 	public function getGroupByFieldsCount() {
Please login to merge, or discard this patch.