Completed
Push — master ( 691772...2b1feb )
by Jean-Christophe
03:46
created
Ajax/semantic/widgets/base/InstanceViewer.php 1 patch
Braces   +42 added lines, -36 removed lines patch added patch discarded remove patch
@@ -23,8 +23,9 @@  discard block
 block discarded – undo
23 23
 		$this->widgetIdentifier=$identifier;
24 24
 		$this->values=[];
25 25
 		$this->afterCompile=[];
26
-		if(isset($instance))
27
-			$this->setInstance($instance);
26
+		if(isset($instance)) {
27
+					$this->setInstance($instance);
28
+		}
28 29
 		$this->setCaptions($captions);
29 30
 		$this->captionCallback=NULL;
30 31
 		$this->defaultValueFunction=function($name,$value){return $value;};
@@ -62,14 +63,16 @@  discard block
 block discarded – undo
62 63
 	}
63 64
 
64 65
 	public function getIdentifier($index=NULL){
65
-		if(!isset($index))
66
-			$index=self::$index;
66
+		if(!isset($index)) {
67
+					$index=self::$index;
68
+		}
67 69
 		$value=$index;
68 70
 		if(isset($this->values["identifier"])){
69
-			if(\is_string($this->values["identifier"]))
70
-				$value=JReflection::callMethod($this->instance, $this->values["identifier"], []);
71
-			else
72
-				$value=$this->values["identifier"]($index,$this->instance);
71
+			if(\is_string($this->values["identifier"])) {
72
+							$value=JReflection::callMethod($this->instance, $this->values["identifier"], []);
73
+			} else {
74
+							$value=$this->values["identifier"]($index,$this->instance);
75
+			}
73 76
 		}
74 77
 		return $value;
75 78
 	}
@@ -99,16 +102,16 @@  discard block
 block discarded – undo
99 102
 		if($property instanceof \ReflectionProperty){
100 103
 			$value=$this->_getPropertyValue($property, $index);
101 104
 			$propertyName=$property->getName();
102
-		}elseif(\is_callable($property))
103
-			$value=$property($this->instance);
104
-		elseif(\is_array($property)){
105
+		} elseif(\is_callable($property)) {
106
+					$value=$property($this->instance);
107
+		} elseif(\is_array($property)){
105 108
 			$values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property);
106 109
 			$value=\implode("", $values);
107
-		}elseif(\is_string($property)){
110
+		} elseif(\is_string($property)){
108 111
 			$value=$property;
109 112
 			if(isset($this->instance->{$property})){
110 113
 				$value=$this->instance->{$property};
111
-			}elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){
114
+			} elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){
112 115
 				$value=JReflection::callMethod($this->instance, $getter, []);
113 116
 			}
114 117
 		}
@@ -118,7 +121,7 @@  discard block
 block discarded – undo
118 121
 	protected function _postGetValue($index,$propertyName,$value){
119 122
 		if(isset($this->values[$index])){
120 123
 			$value= $this->values[$index]($value,$this->instance,$index);
121
-		}else{
124
+		} else{
122 125
 			$value=$this->_getDefaultValue($propertyName,$value, $index);
123 126
 		}
124 127
 		if(isset($this->afterCompile[$index])){
@@ -139,10 +142,10 @@  discard block
 block discarded – undo
139 142
 		if(isset($vb[$index])){
140 143
 			if(\is_array($vb[$index])){
141 144
 				$this->visibleProperties[$index][]=$field;
142
-			}else{
145
+			} else{
143 146
 				$this->visibleProperties[$index]=[$vb[$index],$field];
144 147
 			}
145
-		}else{
148
+		} else{
146 149
 			return $this->insertField($index, $field);
147 150
 		}
148 151
 		return $this;
@@ -169,9 +172,9 @@  discard block
 block discarded – undo
169 172
 		$property=$this->getProperty($index);
170 173
 		if($property instanceof \ReflectionProperty){
171 174
 			$result=$property->getName();
172
-		}elseif(\is_callable($property)){
175
+		} elseif(\is_callable($property)){
173 176
 			$result=$this->visibleProperties[$index];
174
-		}else{
177
+		} else{
175 178
 			$result=$property;
176 179
 		}
177 180
 		return $result;
@@ -191,7 +194,7 @@  discard block
 block discarded – undo
191 194
 		$this->reflect=new \ReflectionClass($instance);
192 195
 		if(\sizeof($this->visibleProperties)===0){
193 196
 			$this->properties=$this->getDefaultProperties();
194
-		}else{
197
+		} else{
195 198
 			foreach ($this->visibleProperties as $property){
196 199
 				$this->setInstanceProperty($property);
197 200
 			}
@@ -202,22 +205,23 @@  discard block
 block discarded – undo
202 205
 	private function setInstanceProperty($property){
203 206
 		if(\is_callable($property)){
204 207
 			$this->properties[]=$property;
205
-		}elseif(\is_string($property)){
208
+		} elseif(\is_string($property)){
206 209
 			try{
207 210
 				$this->_beforeAddProperty(\sizeof($this->properties), $property);
208 211
 				$rProperty=$this->reflect->getProperty($property);
209 212
 				$this->properties[]=$rProperty;
210
-			}catch(\Exception $e){
213
+			} catch(\Exception $e){
211 214
 				$this->_beforeAddProperty(\sizeof($this->properties), $property);
212 215
 				$this->properties[]=$property;
213 216
 			}
214
-		}elseif(\is_int($property)){
217
+		} elseif(\is_int($property)){
215 218
 			$props=$this->getDefaultProperties();
216
-			if(isset($props[$property]))
217
-				$this->properties[]=$props[$property];
218
-				else
219
-					$this->properties[]=$property;
220
-		}else{
219
+			if(isset($props[$property])) {
220
+							$this->properties[]=$props[$property];
221
+			} else {
222
+									$this->properties[]=$property;
223
+				}
224
+		} else{
221 225
 			$this->properties[]=$property;
222 226
 		}
223 227
 	}
@@ -261,12 +265,13 @@  discard block
 block discarded – undo
261 265
 		if(isset($this->captions[$index])){
262 266
 			return $this->captions[$index];
263 267
 		}
264
-		if($this->properties[$index] instanceof \ReflectionProperty)
265
-			return $this->properties[$index]->getName();
266
-		elseif(\is_callable($this->properties[$index]))
267
-			return "";
268
-		else
269
-			return $this->properties[$index];
268
+		if($this->properties[$index] instanceof \ReflectionProperty) {
269
+					return $this->properties[$index]->getName();
270
+		} elseif(\is_callable($this->properties[$index])) {
271
+					return "";
272
+		} else {
273
+					return $this->properties[$index];
274
+		}
270 275
 	}
271 276
 
272 277
 	public function getCaptions(){
@@ -276,7 +281,7 @@  discard block
 block discarded – undo
276 281
 			for($i=$captionsSize;$i<$this->count();$i++){
277 282
 				$captions[]="";
278 283
 			}
279
-		}else{
284
+		} else{
280 285
 			$captions=[];
281 286
 			$index=0;
282 287
 			$count=$this->count();
@@ -292,8 +297,9 @@  discard block
 block discarded – undo
292 297
 	}
293 298
 
294 299
 	public function setCaption($index,$caption){
295
-		if(isset($this->captions)===false)
296
-			$this->captions=[];
300
+		if(isset($this->captions)===false) {
301
+					$this->captions=[];
302
+		}
297 303
 		$this->captions[$index]=$caption;
298 304
 		return $this;
299 305
 	}
Please login to merge, or discard this patch.