Completed
Push — scrutinizer ( c2ef4a...84e9d0 )
by Fabio
22:07
created
framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -121,6 +121,7 @@
 block discarded – undo
121 121
 
122 122
 	/**
123 123
 	 * @param string search condition, the SQL string after the WHERE clause.
124
+	 * @param string|null $value
124 125
 	 */
125 126
 	public function setSearchCondition($value)
126 127
 	{
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 	protected function initializeSort()
55 55
 	{
56 56
 		$table = $this->getTableInfo();
57
-		$sorts = array('Sort By', str_repeat('-',15));
57
+		$sorts = array('Sort By', str_repeat('-', 15));
58 58
 		$headers = array();
59
-		foreach($table->getColumns() as $name=>$colum)
59
+		foreach ($table->getColumns() as $name=>$colum)
60 60
 		{
61 61
 			$fname = ucwords(str_replace('_', ' ', $name));
62
-			$sorts[$name.' ASC'] = $fname .' Ascending';
63
-			$sorts[$name.' DESC'] = $fname .' Descending';
64
-			$headers[] = $fname ;
62
+			$sorts[$name . ' ASC'] = $fname . ' Ascending';
63
+			$sorts[$name . ' DESC'] = $fname . ' Descending';
64
+			$headers[] = $fname;
65 65
 		}
66 66
 		$this->_sort->setDataSource($sorts);
67 67
 		$this->_sort->dataBind();
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	public function onPreRender($param)
76 76
 	{
77 77
 		parent::onPreRender($param);
78
-		if(!$this->getPage()->getIsPostBack() || $this->getViewState('CurrentClass')!=$this->getRecordClass())
78
+		if (!$this->getPage()->getIsPostBack() || $this->getViewState('CurrentClass') != $this->getRecordClass())
79 79
 		{
80 80
 			$this->initializeSort();
81 81
 			$this->setViewState('CurrentClass', $this->getRecordClass());
@@ -103,18 +103,18 @@  discard block
 block discarded – undo
103 103
 	{
104 104
 		$total = $this->_list->getVirtualItemCount();
105 105
 		$limit = $this->_list->getPageSize();
106
-		$offset = $this->_list->getCurrentPageIndex()*$limit;
107
-		if($offset + $limit > $total)
106
+		$offset = $this->_list->getCurrentPageIndex() * $limit;
107
+		if ($offset + $limit > $total)
108 108
 			$limit = $total - $offset;
109 109
 		$criteria = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters());
110
-		if($limit > 0)
110
+		if ($limit > 0)
111 111
 		{
112 112
 			$criteria->setLimit($limit);
113
-			if($offset <= $total)
113
+			if ($offset <= $total)
114 114
 				$criteria->setOffset($offset);
115 115
 		}
116
-		$order = explode(' ',$this->_sort->getSelectedValue(), 2);
117
-		if(is_array($order) && count($order) === 2)
116
+		$order = explode(' ', $this->_sort->getSelectedValue(), 2);
117
+		if (is_array($order) && count($order) === 2)
118 118
 			$criteria->OrdersBy[$order[0]] = $order[1];
119 119
 		return $criteria;
120 120
 	}
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public function setSearchParameters($value)
142 142
 	{
143
-		$this->setViewState('SearchParameters', TPropertyValue::ensureArray($value),array());
143
+		$this->setViewState('SearchParameters', TPropertyValue::ensureArray($value), array());
144 144
 	}
145 145
 
146 146
 	/**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 */
157 157
 	public function bubbleEvent($sender, $param)
158 158
 	{
159
-		switch(strtolower($param->getCommandName()))
159
+		switch (strtolower($param->getCommandName()))
160 160
 		{
161 161
 			case 'delete':
162 162
 				return $this->deleteRecord($sender, $param);
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
 	 */
173 173
 	protected function initializeEdit($sender, $param)
174 174
 	{
175
-		if(($ctrl=$this->getEditViewControl())!==null)
175
+		if (($ctrl = $this->getEditViewControl()) !== null)
176 176
 		{
177
-			if($param instanceof TRepeaterCommandEventParameter)
177
+			if ($param instanceof TRepeaterCommandEventParameter)
178 178
 			{
179 179
 				$pk = $param->getItem()->getCustomData();
180 180
 				$ctrl->setRecordPk($pk);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 */
189 189
 	protected function deleteRecord($sender, $param)
190 190
 	{
191
-		if($param instanceof TRepeaterCommandEventParameter)
191
+		if ($param instanceof TRepeaterCommandEventParameter)
192 192
 		{
193 193
 			$pk = $param->getItem()->getCustomData();
194 194
 			$this->getRecordFinder()->deleteByPk($pk);
@@ -201,10 +201,10 @@  discard block
 block discarded – undo
201 201
 	protected function listItemCreated($sender, $param)
202 202
 	{
203 203
 		$item = $param->getItem();
204
-		if($item instanceof IItemDataRenderer)
204
+		if ($item instanceof IItemDataRenderer)
205 205
 		{
206 206
 			$type = $item->getItemType();
207
-			if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
207
+			if ($type == TListItemType::Item || $type == TListItemType::AlternatingItem)
208 208
 				$this->populateField($sender, $param);
209 209
 		}
210 210
 	}
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
 	protected function populateField($sender, $param)
217 217
 	{
218 218
 		$item = $param->getItem();
219
-		if(($data = $item->getData()) !== null)
219
+		if (($data = $item->getData()) !== null)
220 220
 		{
221 221
 			$item->setCustomData($this->getRecordPkValues($data));
222
-			if(($prop = $item->findControl('_properties'))!==null)
222
+			if (($prop = $item->findControl('_properties')) !== null)
223 223
 			{
224 224
 				$item->_properties->setDataSource($this->getRecordPropertyValues($data));
225 225
 				$item->_properties->dataBind();
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
 	 */
293 293
 	protected function getEditViewControl()
294 294
 	{
295
-		if(($id=$this->getEditViewID())!==null)
295
+		if (($id = $this->getEditViewID()) !== null)
296 296
 		{
297 297
 			$ctrl = $this->getParent()->findControl($id);
298
-			if($ctrl===null)
298
+			if ($ctrl === null)
299 299
 				throw new TConfigurationException('scaffold_unable_to_find_edit_view', $id);
300 300
 			return $ctrl;
301 301
 		}
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -104,18 +104,21 @@  discard block
 block discarded – undo
104 104
 		$total = $this->_list->getVirtualItemCount();
105 105
 		$limit = $this->_list->getPageSize();
106 106
 		$offset = $this->_list->getCurrentPageIndex()*$limit;
107
-		if($offset + $limit > $total)
108
-			$limit = $total - $offset;
107
+		if($offset + $limit > $total) {
108
+					$limit = $total - $offset;
109
+		}
109 110
 		$criteria = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters());
110 111
 		if($limit > 0)
111 112
 		{
112 113
 			$criteria->setLimit($limit);
113
-			if($offset <= $total)
114
-				$criteria->setOffset($offset);
114
+			if($offset <= $total) {
115
+							$criteria->setOffset($offset);
116
+			}
115 117
 		}
116 118
 		$order = explode(' ',$this->_sort->getSelectedValue(), 2);
117
-		if(is_array($order) && count($order) === 2)
118
-			$criteria->OrdersBy[$order[0]] = $order[1];
119
+		if(is_array($order) && count($order) === 2) {
120
+					$criteria->OrdersBy[$order[0]] = $order[1];
121
+		}
119 122
 		return $criteria;
120 123
 	}
121 124
 
@@ -204,8 +207,9 @@  discard block
 block discarded – undo
204 207
 		if($item instanceof IItemDataRenderer)
205 208
 		{
206 209
 			$type = $item->getItemType();
207
-			if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
208
-				$this->populateField($sender, $param);
210
+			if($type==TListItemType::Item || $type==TListItemType::AlternatingItem) {
211
+							$this->populateField($sender, $param);
212
+			}
209 213
 		}
210 214
 	}
211 215
 
@@ -295,8 +299,9 @@  discard block
 block discarded – undo
295 299
 		if(($id=$this->getEditViewID())!==null)
296 300
 		{
297 301
 			$ctrl = $this->getParent()->findControl($id);
298
-			if($ctrl===null)
299
-				throw new TConfigurationException('scaffold_unable_to_find_edit_view', $id);
302
+			if($ctrl===null) {
303
+							throw new TConfigurationException('scaffold_unable_to_find_edit_view', $id);
304
+			}
300 305
 			return $ctrl;
301 306
 		}
302 307
 	}
Please login to merge, or discard this patch.
framework/Data/ActiveRecord/TActiveRecord.php 4 patches
Doc Comments   +6 added lines, -1 removed lines patch added patch discarded remove patch
@@ -651,6 +651,7 @@  discard block
 block discarded – undo
651 651
 	 * class.
652 652
 	 * @param string select SQL
653 653
 	 * @param array $parameters
654
+	 * @param string $sql
654 655
 	 * @return TActiveRecord, null if no result is returned.
655 656
 	 */
656 657
 	public function findBySql($sql,$parameters=array())
@@ -715,6 +716,7 @@  discard block
 block discarded – undo
715 716
 	 * value equal to the $property value.
716 717
 	 * @param string relationship/property name corresponding to keys in $RELATION array.
717 718
 	 * @param array method call arguments.
719
+	 * @param string $name
718 720
 	 * @return TActiveRecordRelation, null if the context or the handler doesn't exist
719 721
 	 */
720 722
 	protected function getRelationHandler($name,$args=array())
@@ -939,6 +941,7 @@  discard block
 block discarded – undo
939 941
 	 * Raised before the record attempt to insert its data into the database.
940 942
 	 * To prevent the insert operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false.
941 943
 	 * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers
944
+	 * @param TActiveRecordChangeEventParameter $param
942 945
 	 */
943 946
 	public function onInsert($param)
944 947
 	{
@@ -949,6 +952,7 @@  discard block
 block discarded – undo
949 952
 	 * Raised before the record attempt to delete its data from the database.
950 953
 	 * To prevent the delete operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false.
951 954
 	 * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers
955
+	 * @param TActiveRecordChangeEventParameter $param
952 956
 	 */
953 957
 	public function onDelete($param)
954 958
 	{
@@ -959,6 +963,7 @@  discard block
 block discarded – undo
959 963
 	 * Raised before the record attempt to update its data in the database.
960 964
 	 * To prevent the update operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false.
961 965
 	 * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers
966
+	 * @param TActiveRecordChangeEventParameter $param
962 967
 	 */
963 968
 	public function onUpdate($param)
964 969
 	{
@@ -1042,7 +1047,7 @@  discard block
 block discarded – undo
1042 1047
     
1043 1048
     	/**
1044 1049
      	* Return record data as JSON
1045
-     	* @return JSON
1050
+     	* @return string
1046 1051
      	* @since 3.2.4
1047 1052
      	*/
1048 1053
     	public function toJSON(){
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1026,28 +1026,28 @@
 block discarded – undo
1026 1026
 		return isset(self::$_relations[get_class($this)][strtolower($property)]);
1027 1027
 	}
1028 1028
 	
1029
-        /**
1030
-        * Return record data as array
1031
-        * @return array of column name and column values
1032
-        * @since 3.2.4
1033
-        */
1034
-        public function toArray(){
1035
-        	$result=array();
1036
-        	foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName){
1037
-            		$result[$columnName]=$this->getColumnValue($columnName);
1038
-           	}
1029
+		/**
1030
+		 * Return record data as array
1031
+		 * @return array of column name and column values
1032
+		 * @since 3.2.4
1033
+		 */
1034
+		public function toArray(){
1035
+			$result=array();
1036
+			foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName){
1037
+					$result[$columnName]=$this->getColumnValue($columnName);
1038
+		   	}
1039 1039
         
1040
-        	return $result;
1041
-    	}
1040
+			return $result;
1041
+		}
1042 1042
     
1043
-    	/**
1044
-     	* Return record data as JSON
1045
-     	* @return JSON
1046
-     	* @since 3.2.4
1047
-     	*/
1048
-    	public function toJSON(){
1049
-        	return json_encode($this->toArray());
1050
-    	}
1043
+		/**
1044
+		 * Return record data as JSON
1045
+		 * @return JSON
1046
+		 * @since 3.2.4
1047
+		 */
1048
+		public function toJSON(){
1049
+			return json_encode($this->toArray());
1050
+		}
1051 1051
 }
1052 1052
 
1053 1053
 /**
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -146,20 +146,20 @@  discard block
 block discarded – undo
146 146
  */
147 147
 abstract class TActiveRecord extends TComponent
148 148
 {
149
-	const BELONGS_TO='BELONGS_TO';
150
-	const HAS_ONE='HAS_ONE';
151
-	const HAS_MANY='HAS_MANY';
152
-	const MANY_TO_MANY='MANY_TO_MANY';
149
+	const BELONGS_TO = 'BELONGS_TO';
150
+	const HAS_ONE = 'HAS_ONE';
151
+	const HAS_MANY = 'HAS_MANY';
152
+	const MANY_TO_MANY = 'MANY_TO_MANY';
153 153
 
154
-	const STATE_NEW=0;
155
-	const STATE_LOADED=1;
156
-	const STATE_DELETED=2;
154
+	const STATE_NEW = 0;
155
+	const STATE_LOADED = 1;
156
+	const STATE_DELETED = 2;
157 157
 
158 158
 	/**
159 159
 	 * @var integer record state: 0 = new, 1 = loaded, 2 = deleted.
160 160
 	 * @since 3.1.2
161 161
 	 */
162
-	protected $_recordState=0; // use protected so that serialization is fine
162
+	protected $_recordState = 0; // use protected so that serialization is fine
163 163
 
164 164
 	/**
165 165
 	 * This static variable defines the column mapping.
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 	 * @var array column mapping. Keys: physical column names, values: logical column names.
170 170
 	 * @since 3.1.1
171 171
 	 */
172
-	public static $COLUMN_MAPPING=array();
173
-	private static $_columnMapping=array();
172
+	public static $COLUMN_MAPPING = array();
173
+	private static $_columnMapping = array();
174 174
 
175 175
 	/**
176 176
 	 * This static variable defines the relationships.
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 	 * @var array relationship.
180 180
 	 * @since 3.1.1
181 181
 	 */
182
-	public static $RELATIONS=array();
183
-	private static $_relations=array();
182
+	public static $RELATIONS = array();
183
+	private static $_relations = array();
184 184
 
185 185
 	/**
186 186
 	 * @var TDbConnection database connection object.
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 */
202 202
 	public function __sleep()
203 203
 	{
204
-		return array_diff(parent::__sleep(),array("\0*\0_connection"));
204
+		return array_diff(parent::__sleep(), array("\0*\0_connection"));
205 205
 	}
206 206
 
207 207
 	/**
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
 	 * @param array optional name value pair record data.
221 221
 	 * @param TDbConnection optional database connection this object record use.
222 222
 	 */
223
-	public function __construct($data=array(), $connection=null)
223
+	public function __construct($data = array(), $connection = null)
224 224
 	{
225
-		if($connection!==null)
225
+		if ($connection !== null)
226 226
 			$this->setDbConnection($connection);
227 227
 		$this->setupColumnMapping();
228 228
 		$this->setupRelations();
229
-		if(!empty($data)) //$data may be an object
229
+		if (!empty($data)) //$data may be an object
230 230
 			$this->copyFrom($data);
231 231
 	}
232 232
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 */
241 241
 	public function __get($name)
242 242
 	{
243
-		if($this->hasRecordRelation($name) && !$this->canGetProperty($name))
243
+		if ($this->hasRecordRelation($name) && !$this->canGetProperty($name))
244 244
 		{
245 245
 			$this->fetchResultsFor($name);
246 246
 			return $this->$name;
@@ -256,12 +256,12 @@  discard block
 block discarded – undo
256 256
 	 * @param mixed property value.
257 257
 	 * @since 3.1.2
258 258
 	 */
259
-	public function __set($name,$value)
259
+	public function __set($name, $value)
260 260
 	{
261
-		if($this->hasRecordRelation($name) && !$this->canSetProperty($name))
262
-			$this->$name=$value;
261
+		if ($this->hasRecordRelation($name) && !$this->canSetProperty($name))
262
+			$this->$name = $value;
263 263
 		else
264
-			parent::__set($name,$value);
264
+			parent::__set($name, $value);
265 265
 	}
266 266
 
267 267
 	/**
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 	 */
270 270
 	private function setupColumnMapping()
271 271
 	{
272
-		$className=get_class($this);
273
-		if(!isset(self::$_columnMapping[$className]))
272
+		$className = get_class($this);
273
+		if (!isset(self::$_columnMapping[$className]))
274 274
 		{
275
-			$class=new ReflectionClass($className);
276
-			self::$_columnMapping[$className]=$class->getStaticPropertyValue('COLUMN_MAPPING');
275
+			$class = new ReflectionClass($className);
276
+			self::$_columnMapping[$className] = $class->getStaticPropertyValue('COLUMN_MAPPING');
277 277
 		}
278 278
 	}
279 279
 
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
 	 */
283 283
 	private function setupRelations()
284 284
 	{
285
-		$className=get_class($this);
286
-		if(!isset(self::$_relations[$className]))
285
+		$className = get_class($this);
286
+		if (!isset(self::$_relations[$className]))
287 287
 		{
288
-			$class=new ReflectionClass($className);
289
-			$relations=array();
290
-			foreach($class->getStaticPropertyValue('RELATIONS') as $key=>$value)
291
-				$relations[strtolower($key)]=array($key,$value);
292
-			self::$_relations[$className]=$relations;
288
+			$class = new ReflectionClass($className);
289
+			$relations = array();
290
+			foreach ($class->getStaticPropertyValue('RELATIONS') as $key=>$value)
291
+				$relations[strtolower($key)] = array($key, $value);
292
+			self::$_relations[$className] = $relations;
293 293
 		}
294 294
 	}
295 295
 
@@ -299,18 +299,18 @@  discard block
 block discarded – undo
299 299
 	 */
300 300
 	public function copyFrom($data)
301 301
 	{
302
-		if(is_object($data))
303
-			$data=get_object_vars($data);
304
-		if(!is_array($data))
302
+		if (is_object($data))
303
+			$data = get_object_vars($data);
304
+		if (!is_array($data))
305 305
 			throw new TActiveRecordException('ar_data_invalid', get_class($this));
306
-		foreach($data as $name=>$value)
307
-			$this->setColumnValue($name,$value);
306
+		foreach ($data as $name=>$value)
307
+			$this->setColumnValue($name, $value);
308 308
 	}
309 309
 
310 310
 
311 311
 	public static function getActiveDbConnection()
312 312
 	{
313
-		if(($db=self::getRecordManager()->getDbConnection())!==null)
313
+		if (($db = self::getRecordManager()->getDbConnection()) !== null)
314 314
 			$db->setActive(true);
315 315
 		return $db;
316 316
 	}
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
 	 */
323 323
 	public function getDbConnection()
324 324
 	{
325
-		if($this->_connection===null)
326
-			$this->_connection=self::getActiveDbConnection();
325
+		if ($this->_connection === null)
326
+			$this->_connection = self::getActiveDbConnection();
327 327
 		return $this->_connection;
328 328
 	}
329 329
 
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 */
333 333
 	public function setDbConnection($connection)
334 334
 	{
335
-		$this->_connection=$connection;
335
+		$this->_connection = $connection;
336 336
 	}
337 337
 
338 338
 	/**
@@ -351,21 +351,21 @@  discard block
 block discarded – undo
351 351
 	 * @param boolean true to perform strict identity comparison
352 352
 	 * @return boolean true if $record equals, false otherwise.
353 353
 	 */
354
-	public function equals(TActiveRecord $record, $strict=false)
354
+	public function equals(TActiveRecord $record, $strict = false)
355 355
 	{
356
-		if($record===null || get_class($this)!==get_class($record))
356
+		if ($record === null || get_class($this) !== get_class($record))
357 357
 			return false;
358 358
 		$tableInfo = $this->getRecordTableInfo();
359 359
 		$pks = $tableInfo->getPrimaryKeys();
360 360
 		$properties = count($pks) > 0 ? $pks : $tableInfo->getColumns()->getKeys();
361
-		$equals=true;
362
-		foreach($properties as $prop)
361
+		$equals = true;
362
+		foreach ($properties as $prop)
363 363
 		{
364
-			if($strict)
364
+			if ($strict)
365 365
 				$equals = $equals && $this->getColumnValue($prop) === $record->getColumnValue($prop);
366 366
 			else
367 367
 				$equals = $equals && $this->getColumnValue($prop) == $record->getColumnValue($prop);
368
-			if(!$equals)
368
+			if (!$equals)
369 369
 				return false;
370 370
 		}
371 371
 		return $equals;
@@ -380,13 +380,13 @@  discard block
 block discarded – undo
380 380
 	 * @param string active record class name.
381 381
 	 * @return TActiveRecord active record finder instance.
382 382
 	 */
383
-	public static function finder($className=__CLASS__)
383
+	public static function finder($className = __CLASS__)
384 384
 	{
385 385
 		static $finders = array();
386
-		if(!isset($finders[$className]))
386
+		if (!isset($finders[$className]))
387 387
 		{
388 388
 			$f = Prado::createComponent($className);
389
-			$finders[$className]=$f;
389
+			$finders[$className] = $f;
390 390
 		}
391 391
 		return $finders[$className];
392 392
 	}
@@ -417,19 +417,19 @@  discard block
 block discarded – undo
417 417
 	{
418 418
 		$gateway = $this->getRecordGateway();
419 419
 		$param = new TActiveRecordChangeEventParameter();
420
-		if($this->_recordState===self::STATE_NEW)
420
+		if ($this->_recordState === self::STATE_NEW)
421 421
 		{
422 422
 			$this->onInsert($param);
423
-			if($param->getIsValid() && $gateway->insert($this))
423
+			if ($param->getIsValid() && $gateway->insert($this))
424 424
 			{
425 425
 				$this->_recordState = self::STATE_LOADED;
426 426
 				return true;
427 427
 			}
428 428
 		}
429
-		else if($this->_recordState===self::STATE_LOADED)
429
+		else if ($this->_recordState === self::STATE_LOADED)
430 430
 		{
431 431
 			$this->onUpdate($param);
432
-			if($param->getIsValid() && $gateway->update($this))
432
+			if ($param->getIsValid() && $gateway->update($this))
433 433
 				return true;
434 434
 		}
435 435
 		else
@@ -445,14 +445,14 @@  discard block
 block discarded – undo
445 445
 	 */
446 446
 	public function delete()
447 447
 	{
448
-		if($this->_recordState===self::STATE_LOADED)
448
+		if ($this->_recordState === self::STATE_LOADED)
449 449
 		{
450 450
 			$gateway = $this->getRecordGateway();
451 451
 			$param = new TActiveRecordChangeEventParameter();
452 452
 			$this->onDelete($param);
453
-			if($param->getIsValid() && $gateway->delete($this))
453
+			if ($param->getIsValid() && $gateway->delete($this))
454 454
 			{
455
-				$this->_recordState=self::STATE_DELETED;
455
+				$this->_recordState = self::STATE_DELETED;
456 456
 				return true;
457 457
 			}
458 458
 		}
@@ -487,9 +487,9 @@  discard block
 block discarded – undo
487 487
 	 */
488 488
 	public function deleteByPk($keys)
489 489
 	{
490
-		if(func_num_args() > 1)
490
+		if (func_num_args() > 1)
491 491
 			$keys = func_get_args();
492
-		return $this->getRecordGateway()->deleteRecordsByPk($this,(array)$keys);
492
+		return $this->getRecordGateway()->deleteRecordsByPk($this, (array) $keys);
493 493
 	}
494 494
 
495 495
 	/**
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 	 */
498 498
 	public function deleteAllByPks($keys)
499 499
 	{
500
-		if(func_num_args() > 1)
500
+		if (func_num_args() > 1)
501 501
 			$keys = func_get_args();
502 502
 		return $this->deleteByPk($keys);
503 503
 	}
@@ -507,10 +507,10 @@  discard block
 block discarded – undo
507 507
 	 * @param mixed parameter values.
508 508
 	 * @return int number of records deleted.
509 509
 	 */
510
-	public function deleteAll($criteria=null, $parameters=array())
510
+	public function deleteAll($criteria = null, $parameters = array())
511 511
 	{
512
-		$args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
513
-		$criteria = $this->getRecordCriteria($criteria,$parameters, $args);
512
+		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
513
+		$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
514 514
 		return $this->getRecordGateway()->deleteRecordsByCriteria($this, $criteria);
515 515
 	}
516 516
 
@@ -532,8 +532,8 @@  discard block
 block discarded – undo
532 532
 	 */
533 533
 	protected function populateObjects($reader)
534 534
 	{
535
-		$result=array();
536
-		foreach($reader as $data)
535
+		$result = array();
536
+		foreach ($reader as $data)
537 537
 			$result[] = $this->populateObject($data);
538 538
 		return $result;
539 539
 	}
@@ -549,10 +549,10 @@  discard block
 block discarded – undo
549 549
 	 */
550 550
 	public static function createRecord($type, $data)
551 551
 	{
552
-		if(empty($data))
552
+		if (empty($data))
553 553
 			return null;
554
-		$record=new $type($data);
555
-		$record->_recordState=self::STATE_LOADED;
554
+		$record = new $type($data);
555
+		$record->_recordState = self::STATE_LOADED;
556 556
 		return $record;
557 557
 	}
558 558
 
@@ -573,12 +573,12 @@  discard block
 block discarded – undo
573 573
 	 * @param mixed parameter values.
574 574
 	 * @return TActiveRecord matching record object. Null if no result is found.
575 575
 	 */
576
-	public function find($criteria,$parameters=array())
576
+	public function find($criteria, $parameters = array())
577 577
 	{
578
-		$args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
579
-		$criteria = $this->getRecordCriteria($criteria,$parameters, $args);
578
+		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
579
+		$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
580 580
 		$criteria->setLimit(1);
581
-		$data = $this->getRecordGateway()->findRecordsByCriteria($this,$criteria);
581
+		$data = $this->getRecordGateway()->findRecordsByCriteria($this, $criteria);
582 582
 		return $this->populateObject($data);
583 583
 	}
584 584
 
@@ -589,12 +589,12 @@  discard block
 block discarded – undo
589 589
 	 * @param mixed parameter values.
590 590
 	 * @return array matching record objects. Empty array if no result is found.
591 591
 	 */
592
-	public function findAll($criteria=null,$parameters=array())
592
+	public function findAll($criteria = null, $parameters = array())
593 593
 	{
594
-		$args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
595
-		if($criteria!==null)
596
-			$criteria = $this->getRecordCriteria($criteria,$parameters, $args);
597
-		$result = $this->getRecordGateway()->findRecordsByCriteria($this,$criteria,true);
594
+		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
595
+		if ($criteria !== null)
596
+			$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
597
+		$result = $this->getRecordGateway()->findRecordsByCriteria($this, $criteria, true);
598 598
 		return $this->populateObjects($result);
599 599
 	}
600 600
 
@@ -612,11 +612,11 @@  discard block
 block discarded – undo
612 612
 	 */
613 613
 	public function findByPk($keys)
614 614
 	{
615
-		if($keys === null)
615
+		if ($keys === null)
616 616
 			return null;
617
-		if(func_num_args() > 1)
617
+		if (func_num_args() > 1)
618 618
 			$keys = func_get_args();
619
-		$data = $this->getRecordGateway()->findRecordByPK($this,$keys);
619
+		$data = $this->getRecordGateway()->findRecordByPK($this, $keys);
620 620
 		return $this->populateObject($data);
621 621
 	}
622 622
 
@@ -639,9 +639,9 @@  discard block
 block discarded – undo
639 639
 	 */
640 640
 	public function findAllByPks($keys)
641 641
 	{
642
-		if(func_num_args() > 1)
642
+		if (func_num_args() > 1)
643 643
 			$keys = func_get_args();
644
-		$result = $this->getRecordGateway()->findRecordsByPks($this,(array)$keys);
644
+		$result = $this->getRecordGateway()->findRecordsByPks($this, (array) $keys);
645 645
 		return $this->populateObjects($result);
646 646
 	}
647 647
 
@@ -653,12 +653,12 @@  discard block
 block discarded – undo
653 653
 	 * @param array $parameters
654 654
 	 * @return TActiveRecord, null if no result is returned.
655 655
 	 */
656
-	public function findBySql($sql,$parameters=array())
656
+	public function findBySql($sql, $parameters = array())
657 657
 	{
658
-		$args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
659
-		$criteria = $this->getRecordCriteria($sql,$parameters, $args);
658
+		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
659
+		$criteria = $this->getRecordCriteria($sql, $parameters, $args);
660 660
 		$criteria->setLimit(1);
661
-		$data = $this->getRecordGateway()->findRecordBySql($this,$criteria);
661
+		$data = $this->getRecordGateway()->findRecordBySql($this, $criteria);
662 662
 		return $this->populateObject($data);
663 663
 	}
664 664
 
@@ -670,11 +670,11 @@  discard block
 block discarded – undo
670 670
 	 * @param array $parameters
671 671
 	 * @return array matching active records. Empty array is returned if no result is found.
672 672
 	 */
673
-	public function findAllBySql($sql,$parameters=array())
673
+	public function findAllBySql($sql, $parameters = array())
674 674
 	{
675
-		$args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
676
-		$criteria = $this->getRecordCriteria($sql,$parameters, $args);
677
-		$result = $this->getRecordGateway()->findRecordsBySql($this,$criteria);
675
+		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
676
+		$criteria = $this->getRecordCriteria($sql, $parameters, $args);
677
+		$result = $this->getRecordGateway()->findRecordsBySql($this, $criteria);
678 678
 		return $this->populateObjects($result);
679 679
 	}
680 680
 
@@ -690,9 +690,9 @@  discard block
 block discarded – undo
690 690
 	 * @param array matching field values.
691 691
 	 * @return array matching active records. Empty array is returned if no result is found.
692 692
 	 */
693
-	public function findAllByIndex($criteria,$fields,$values)
693
+	public function findAllByIndex($criteria, $fields, $values)
694 694
 	{
695
-		$result = $this->getRecordGateway()->findRecordsByIndex($this,$criteria,$fields,$values);
695
+		$result = $this->getRecordGateway()->findRecordsByIndex($this, $criteria, $fields, $values);
696 696
 		return $this->populateObjects($result);
697 697
 	}
698 698
 
@@ -702,12 +702,12 @@  discard block
 block discarded – undo
702 702
 	 * @param mixed parameter values.
703 703
 	 * @return int number of records.
704 704
 	 */
705
-	public function count($criteria=null,$parameters=array())
705
+	public function count($criteria = null, $parameters = array())
706 706
 	{
707
-		$args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
708
-		if($criteria!==null)
709
-			$criteria = $this->getRecordCriteria($criteria,$parameters, $args);
710
-		return $this->getRecordGateway()->countRecords($this,$criteria);
707
+		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
708
+		if ($criteria !== null)
709
+			$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
710
+		return $this->getRecordGateway()->countRecords($this, $criteria);
711 711
 	}
712 712
 
713 713
 	/**
@@ -717,11 +717,11 @@  discard block
 block discarded – undo
717 717
 	 * @param array method call arguments.
718 718
 	 * @return TActiveRecordRelation, null if the context or the handler doesn't exist
719 719
 	 */
720
-	protected function getRelationHandler($name,$args=array())
720
+	protected function getRelationHandler($name, $args = array())
721 721
 	{
722
-		if(($context=$this->createRelationContext($name)) !== null)
722
+		if (($context = $this->createRelationContext($name)) !== null)
723 723
 		{
724
-			$criteria = $this->getRecordCriteria(count($args)>0 ? $args[0] : null, array_slice($args,1));
724
+			$criteria = $this->getRecordCriteria(count($args) > 0 ? $args[0] : null, array_slice($args, 1));
725 725
 			return $context->getRelationHandler($criteria);
726 726
 		}
727 727
 		else
@@ -739,10 +739,10 @@  discard block
 block discarded – undo
739 739
 	 */
740 740
 	protected function createRelationContext($name)
741 741
 	{
742
-		if(($definition=$this->getRecordRelation($name))!==null)
742
+		if (($definition = $this->getRecordRelation($name)) !== null)
743 743
 		{
744 744
 			list($property, $relation) = $definition;
745
-			return new TActiveRecordRelationContext($this,$property,$relation);
745
+			return new TActiveRecordRelationContext($this, $property, $relation);
746 746
 		}
747 747
 		else
748 748
 			return null;
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 	 */
786 786
 	protected function fetchResultsFor($property)
787 787
 	{
788
-		if( ($context=$this->createRelationContext($property)) !== null)
788
+		if (($context = $this->createRelationContext($property)) !== null)
789 789
 			return $context->getRelationHandler()->fetchResultsInto($this);
790 790
 		else
791 791
 			return false;
@@ -820,32 +820,32 @@  discard block
 block discarded – undo
820 820
 	 * @return mixed single record if method name starts with "findBy", 0 or more records
821 821
 	 * if method name starts with "findAllBy"
822 822
 	 */
823
-	public function __call($method,$args)
823
+	public function __call($method, $args)
824 824
 	{
825
-		$delete =false;
826
-		if(strncasecmp($method,'with',4)===0)
825
+		$delete = false;
826
+		if (strncasecmp($method, 'with', 4) === 0)
827 827
 		{
828
-			$property= $method[4]==='_' ? substr($method,5) : substr($method,4);
828
+			$property = $method[4] === '_' ? substr($method, 5) : substr($method, 4);
829 829
 			return $this->getRelationHandler($property, $args);
830 830
 		}
831
-		else if($findOne=strncasecmp($method,'findby',6)===0)
832
-			$condition = $method[6]==='_' ? substr($method,7) : substr($method,6);
833
-		else if(strncasecmp($method,'findallby',9)===0)
834
-			$condition = $method[9]==='_' ? substr($method,10) : substr($method,9);
835
-		else if($delete=strncasecmp($method,'deleteby',8)===0)
836
-			$condition = $method[8]==='_' ? substr($method,9) : substr($method,8);
837
-		else if($delete=strncasecmp($method,'deleteallby',11)===0)
838
-			$condition = $method[11]==='_' ? substr($method,12) : substr($method,11);
831
+		else if ($findOne = strncasecmp($method, 'findby', 6) === 0)
832
+			$condition = $method[6] === '_' ? substr($method, 7) : substr($method, 6);
833
+		else if (strncasecmp($method, 'findallby', 9) === 0)
834
+			$condition = $method[9] === '_' ? substr($method, 10) : substr($method, 9);
835
+		else if ($delete = strncasecmp($method, 'deleteby', 8) === 0)
836
+			$condition = $method[8] === '_' ? substr($method, 9) : substr($method, 8);
837
+		else if ($delete = strncasecmp($method, 'deleteallby', 11) === 0)
838
+			$condition = $method[11] === '_' ? substr($method, 12) : substr($method, 11);
839 839
 		else
840 840
 		{
841
-			if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception)
842
-				throw new TActiveRecordException('ar_invalid_finder_method',$method);
841
+			if ($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception)
842
+				throw new TActiveRecordException('ar_invalid_finder_method', $method);
843 843
 			else
844 844
 				return null;
845 845
 		}
846 846
 
847 847
 		$criteria = $this->getRecordGateway()->getCommand($this)->createCriteriaFromString($method, $condition, $args);
848
-		if($delete)
848
+		if ($delete)
849 849
 			return $this->deleteAll($criteria);
850 850
 		else
851 851
 			return $findOne ? $this->find($criteria) : $this->findAll($criteria);
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function getInvalidFinderResult()
860 860
 	{
861
-		if($this->_invalidFinderResult !== null)
861
+		if ($this->_invalidFinderResult !== null)
862 862
 			return $this->_invalidFinderResult;
863 863
 
864 864
 		return self::getRecordManager()->getInvalidFinderResult();
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 	 */
874 874
 	public function setInvalidFinderResult($value)
875 875
 	{
876
-		if($value === null)
876
+		if ($value === null)
877 877
 			$this->_invalidFinderResult = null;
878 878
 		else
879 879
 			$this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
@@ -888,14 +888,14 @@  discard block
 block discarded – undo
888 888
 	 * @param array additional parameters obtained from function_get_args().
889 889
 	 * @return TSqlCriteria criteria object.
890 890
 	 */
891
-	protected function getRecordCriteria($criteria, $parameters, $args=array())
891
+	protected function getRecordCriteria($criteria, $parameters, $args = array())
892 892
 	{
893
-		if(is_string($criteria))
893
+		if (is_string($criteria))
894 894
 		{
895 895
 			$useArgs = !is_array($parameters) && is_array($args);
896
-			return new TActiveRecordCriteria($criteria,$useArgs ? $args : $parameters);
896
+			return new TActiveRecordCriteria($criteria, $useArgs ? $args : $parameters);
897 897
 		}
898
-		else if($criteria instanceof TSqlCriteria)
898
+		else if ($criteria instanceof TSqlCriteria)
899 899
 			return $criteria;
900 900
 		else
901 901
 			return new TActiveRecordCriteria();
@@ -974,9 +974,9 @@  discard block
 block discarded – undo
974 974
 	 */
975 975
 	public function getColumnValue($columnName)
976 976
 	{
977
-		$className=get_class($this);
978
-		if(isset(self::$_columnMapping[$className][$columnName]))
979
-			$columnName=self::$_columnMapping[$className][$columnName];
977
+		$className = get_class($this);
978
+		if (isset(self::$_columnMapping[$className][$columnName]))
979
+			$columnName = self::$_columnMapping[$className][$columnName];
980 980
 		return $this->$columnName;
981 981
 	}
982 982
 
@@ -987,12 +987,12 @@  discard block
 block discarded – undo
987 987
 	 * @param mixed the corresponding column value
988 988
 	 * @since 3.1.1
989 989
 	 */
990
-	public function setColumnValue($columnName,$value)
990
+	public function setColumnValue($columnName, $value)
991 991
 	{
992
-		$className=get_class($this);
993
-		if(isset(self::$_columnMapping[$className][$columnName]))
994
-			$columnName=self::$_columnMapping[$className][$columnName];
995
-		$this->$columnName=$value;
992
+		$className = get_class($this);
993
+		if (isset(self::$_columnMapping[$className][$columnName]))
994
+			$columnName = self::$_columnMapping[$className][$columnName];
995
+		$this->$columnName = $value;
996 996
 	}
997 997
 
998 998
 	/**
@@ -1002,9 +1002,9 @@  discard block
 block discarded – undo
1002 1002
 	 */
1003 1003
 	public function getRecordRelation($property)
1004 1004
 	{
1005
-		$className=get_class($this);
1006
-		$property=strtolower($property);
1007
-		return isset(self::$_relations[$className][$property])?self::$_relations[$className][$property]:null;
1005
+		$className = get_class($this);
1006
+		$property = strtolower($property);
1007
+		return isset(self::$_relations[$className][$property]) ? self::$_relations[$className][$property] : null;
1008 1008
 	}
1009 1009
 
1010 1010
 	/**
@@ -1031,10 +1031,10 @@  discard block
 block discarded – undo
1031 1031
         * @return array of column name and column values
1032 1032
         * @since 3.2.4
1033 1033
         */
1034
-        public function toArray(){
1035
-        	$result=array();
1036
-        	foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName){
1037
-            		$result[$columnName]=$this->getColumnValue($columnName);
1034
+        public function toArray() {
1035
+        	$result = array();
1036
+        	foreach ($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName) {
1037
+            		$result[$columnName] = $this->getColumnValue($columnName);
1038 1038
            	}
1039 1039
         
1040 1040
         	return $result;
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
      	* @return JSON
1046 1046
      	* @since 3.2.4
1047 1047
      	*/
1048
-    	public function toJSON(){
1048
+    	public function toJSON() {
1049 1049
         	return json_encode($this->toArray());
1050 1050
     	}
1051 1051
 }
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
  */
1066 1066
 class TActiveRecordChangeEventParameter extends TEventParameter
1067 1067
 {
1068
-	private $_isValid=true;
1068
+	private $_isValid = true;
1069 1069
 
1070 1070
 	/**
1071 1071
 	 * @return boolean whether the event should be performed.
Please login to merge, or discard this patch.
Braces   +121 added lines, -93 removed lines patch added patch discarded remove patch
@@ -222,12 +222,15 @@  discard block
 block discarded – undo
222 222
 	 */
223 223
 	public function __construct($data=array(), $connection=null)
224 224
 	{
225
-		if($connection!==null)
226
-			$this->setDbConnection($connection);
225
+		if($connection!==null) {
226
+					$this->setDbConnection($connection);
227
+		}
227 228
 		$this->setupColumnMapping();
228 229
 		$this->setupRelations();
229
-		if(!empty($data)) //$data may be an object
230
+		if(!empty($data)) {
231
+			//$data may be an object
230 232
 			$this->copyFrom($data);
233
+		}
231 234
 	}
232 235
 
233 236
 	/**
@@ -258,10 +261,11 @@  discard block
 block discarded – undo
258 261
 	 */
259 262
 	public function __set($name,$value)
260 263
 	{
261
-		if($this->hasRecordRelation($name) && !$this->canSetProperty($name))
262
-			$this->$name=$value;
263
-		else
264
-			parent::__set($name,$value);
264
+		if($this->hasRecordRelation($name) && !$this->canSetProperty($name)) {
265
+					$this->$name=$value;
266
+		} else {
267
+					parent::__set($name,$value);
268
+		}
265 269
 	}
266 270
 
267 271
 	/**
@@ -287,8 +291,9 @@  discard block
 block discarded – undo
287 291
 		{
288 292
 			$class=new ReflectionClass($className);
289 293
 			$relations=array();
290
-			foreach($class->getStaticPropertyValue('RELATIONS') as $key=>$value)
291
-				$relations[strtolower($key)]=array($key,$value);
294
+			foreach($class->getStaticPropertyValue('RELATIONS') as $key=>$value) {
295
+							$relations[strtolower($key)]=array($key,$value);
296
+			}
292 297
 			self::$_relations[$className]=$relations;
293 298
 		}
294 299
 	}
@@ -299,19 +304,23 @@  discard block
 block discarded – undo
299 304
 	 */
300 305
 	public function copyFrom($data)
301 306
 	{
302
-		if(is_object($data))
303
-			$data=get_object_vars($data);
304
-		if(!is_array($data))
305
-			throw new TActiveRecordException('ar_data_invalid', get_class($this));
306
-		foreach($data as $name=>$value)
307
-			$this->setColumnValue($name,$value);
307
+		if(is_object($data)) {
308
+					$data=get_object_vars($data);
309
+		}
310
+		if(!is_array($data)) {
311
+					throw new TActiveRecordException('ar_data_invalid', get_class($this));
312
+		}
313
+		foreach($data as $name=>$value) {
314
+					$this->setColumnValue($name,$value);
315
+		}
308 316
 	}
309 317
 
310 318
 
311 319
 	public static function getActiveDbConnection()
312 320
 	{
313
-		if(($db=self::getRecordManager()->getDbConnection())!==null)
314
-			$db->setActive(true);
321
+		if(($db=self::getRecordManager()->getDbConnection())!==null) {
322
+					$db->setActive(true);
323
+		}
315 324
 		return $db;
316 325
 	}
317 326
 
@@ -322,8 +331,9 @@  discard block
 block discarded – undo
322 331
 	 */
323 332
 	public function getDbConnection()
324 333
 	{
325
-		if($this->_connection===null)
326
-			$this->_connection=self::getActiveDbConnection();
334
+		if($this->_connection===null) {
335
+					$this->_connection=self::getActiveDbConnection();
336
+		}
327 337
 		return $this->_connection;
328 338
 	}
329 339
 
@@ -353,20 +363,23 @@  discard block
 block discarded – undo
353 363
 	 */
354 364
 	public function equals(TActiveRecord $record, $strict=false)
355 365
 	{
356
-		if($record===null || get_class($this)!==get_class($record))
357
-			return false;
366
+		if($record===null || get_class($this)!==get_class($record)) {
367
+					return false;
368
+		}
358 369
 		$tableInfo = $this->getRecordTableInfo();
359 370
 		$pks = $tableInfo->getPrimaryKeys();
360 371
 		$properties = count($pks) > 0 ? $pks : $tableInfo->getColumns()->getKeys();
361 372
 		$equals=true;
362 373
 		foreach($properties as $prop)
363 374
 		{
364
-			if($strict)
365
-				$equals = $equals && $this->getColumnValue($prop) === $record->getColumnValue($prop);
366
-			else
367
-				$equals = $equals && $this->getColumnValue($prop) == $record->getColumnValue($prop);
368
-			if(!$equals)
369
-				return false;
375
+			if($strict) {
376
+							$equals = $equals && $this->getColumnValue($prop) === $record->getColumnValue($prop);
377
+			} else {
378
+							$equals = $equals && $this->getColumnValue($prop) == $record->getColumnValue($prop);
379
+			}
380
+			if(!$equals) {
381
+							return false;
382
+			}
370 383
 		}
371 384
 		return $equals;
372 385
 	}
@@ -425,15 +438,15 @@  discard block
 block discarded – undo
425 438
 				$this->_recordState = self::STATE_LOADED;
426 439
 				return true;
427 440
 			}
428
-		}
429
-		else if($this->_recordState===self::STATE_LOADED)
441
+		} else if($this->_recordState===self::STATE_LOADED)
430 442
 		{
431 443
 			$this->onUpdate($param);
432
-			if($param->getIsValid() && $gateway->update($this))
433
-				return true;
444
+			if($param->getIsValid() && $gateway->update($this)) {
445
+							return true;
446
+			}
447
+		} else {
448
+					throw new TActiveRecordException('ar_save_invalid', get_class($this));
434 449
 		}
435
-		else
436
-			throw new TActiveRecordException('ar_save_invalid', get_class($this));
437 450
 
438 451
 		return false;
439 452
 	}
@@ -455,9 +468,9 @@  discard block
 block discarded – undo
455 468
 				$this->_recordState=self::STATE_DELETED;
456 469
 				return true;
457 470
 			}
471
+		} else {
472
+					throw new TActiveRecordException('ar_delete_invalid', get_class($this));
458 473
 		}
459
-		else
460
-			throw new TActiveRecordException('ar_delete_invalid', get_class($this));
461 474
 
462 475
 		return false;
463 476
 	}
@@ -487,8 +500,9 @@  discard block
 block discarded – undo
487 500
 	 */
488 501
 	public function deleteByPk($keys)
489 502
 	{
490
-		if(func_num_args() > 1)
491
-			$keys = func_get_args();
503
+		if(func_num_args() > 1) {
504
+					$keys = func_get_args();
505
+		}
492 506
 		return $this->getRecordGateway()->deleteRecordsByPk($this,(array)$keys);
493 507
 	}
494 508
 
@@ -497,8 +511,9 @@  discard block
 block discarded – undo
497 511
 	 */
498 512
 	public function deleteAllByPks($keys)
499 513
 	{
500
-		if(func_num_args() > 1)
501
-			$keys = func_get_args();
514
+		if(func_num_args() > 1) {
515
+					$keys = func_get_args();
516
+		}
502 517
 		return $this->deleteByPk($keys);
503 518
 	}
504 519
 	/**
@@ -533,8 +548,9 @@  discard block
 block discarded – undo
533 548
 	protected function populateObjects($reader)
534 549
 	{
535 550
 		$result=array();
536
-		foreach($reader as $data)
537
-			$result[] = $this->populateObject($data);
551
+		foreach($reader as $data) {
552
+					$result[] = $this->populateObject($data);
553
+		}
538 554
 		return $result;
539 555
 	}
540 556
 
@@ -549,8 +565,9 @@  discard block
 block discarded – undo
549 565
 	 */
550 566
 	public static function createRecord($type, $data)
551 567
 	{
552
-		if(empty($data))
553
-			return null;
568
+		if(empty($data)) {
569
+					return null;
570
+		}
554 571
 		$record=new $type($data);
555 572
 		$record->_recordState=self::STATE_LOADED;
556 573
 		return $record;
@@ -592,8 +609,9 @@  discard block
 block discarded – undo
592 609
 	public function findAll($criteria=null,$parameters=array())
593 610
 	{
594 611
 		$args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
595
-		if($criteria!==null)
596
-			$criteria = $this->getRecordCriteria($criteria,$parameters, $args);
612
+		if($criteria!==null) {
613
+					$criteria = $this->getRecordCriteria($criteria,$parameters, $args);
614
+		}
597 615
 		$result = $this->getRecordGateway()->findRecordsByCriteria($this,$criteria,true);
598 616
 		return $this->populateObjects($result);
599 617
 	}
@@ -612,10 +630,12 @@  discard block
 block discarded – undo
612 630
 	 */
613 631
 	public function findByPk($keys)
614 632
 	{
615
-		if($keys === null)
616
-			return null;
617
-		if(func_num_args() > 1)
618
-			$keys = func_get_args();
633
+		if($keys === null) {
634
+					return null;
635
+		}
636
+		if(func_num_args() > 1) {
637
+					$keys = func_get_args();
638
+		}
619 639
 		$data = $this->getRecordGateway()->findRecordByPK($this,$keys);
620 640
 		return $this->populateObject($data);
621 641
 	}
@@ -639,8 +659,9 @@  discard block
 block discarded – undo
639 659
 	 */
640 660
 	public function findAllByPks($keys)
641 661
 	{
642
-		if(func_num_args() > 1)
643
-			$keys = func_get_args();
662
+		if(func_num_args() > 1) {
663
+					$keys = func_get_args();
664
+		}
644 665
 		$result = $this->getRecordGateway()->findRecordsByPks($this,(array)$keys);
645 666
 		return $this->populateObjects($result);
646 667
 	}
@@ -705,8 +726,9 @@  discard block
 block discarded – undo
705 726
 	public function count($criteria=null,$parameters=array())
706 727
 	{
707 728
 		$args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null;
708
-		if($criteria!==null)
709
-			$criteria = $this->getRecordCriteria($criteria,$parameters, $args);
729
+		if($criteria!==null) {
730
+					$criteria = $this->getRecordCriteria($criteria,$parameters, $args);
731
+		}
710 732
 		return $this->getRecordGateway()->countRecords($this,$criteria);
711 733
 	}
712 734
 
@@ -723,9 +745,9 @@  discard block
 block discarded – undo
723 745
 		{
724 746
 			$criteria = $this->getRecordCriteria(count($args)>0 ? $args[0] : null, array_slice($args,1));
725 747
 			return $context->getRelationHandler($criteria);
748
+		} else {
749
+					return null;
726 750
 		}
727
-		else
728
-			return null;
729 751
 	}
730 752
 
731 753
 	/**
@@ -743,9 +765,9 @@  discard block
 block discarded – undo
743 765
 		{
744 766
 			list($property, $relation) = $definition;
745 767
 			return new TActiveRecordRelationContext($this,$property,$relation);
768
+		} else {
769
+					return null;
746 770
 		}
747
-		else
748
-			return null;
749 771
 	}
750 772
 
751 773
 	/**
@@ -785,10 +807,11 @@  discard block
 block discarded – undo
785 807
 	 */
786 808
 	protected function fetchResultsFor($property)
787 809
 	{
788
-		if( ($context=$this->createRelationContext($property)) !== null)
789
-			return $context->getRelationHandler()->fetchResultsInto($this);
790
-		else
791
-			return false;
810
+		if( ($context=$this->createRelationContext($property)) !== null) {
811
+					return $context->getRelationHandler()->fetchResultsInto($this);
812
+		} else {
813
+					return false;
814
+		}
792 815
 	}
793 816
 
794 817
 	/**
@@ -827,28 +850,29 @@  discard block
 block discarded – undo
827 850
 		{
828 851
 			$property= $method[4]==='_' ? substr($method,5) : substr($method,4);
829 852
 			return $this->getRelationHandler($property, $args);
830
-		}
831
-		else if($findOne=strncasecmp($method,'findby',6)===0)
832
-			$condition = $method[6]==='_' ? substr($method,7) : substr($method,6);
833
-		else if(strncasecmp($method,'findallby',9)===0)
834
-			$condition = $method[9]==='_' ? substr($method,10) : substr($method,9);
835
-		else if($delete=strncasecmp($method,'deleteby',8)===0)
836
-			$condition = $method[8]==='_' ? substr($method,9) : substr($method,8);
837
-		else if($delete=strncasecmp($method,'deleteallby',11)===0)
838
-			$condition = $method[11]==='_' ? substr($method,12) : substr($method,11);
839
-		else
853
+		} else if($findOne=strncasecmp($method,'findby',6)===0) {
854
+					$condition = $method[6]==='_' ? substr($method,7) : substr($method,6);
855
+		} else if(strncasecmp($method,'findallby',9)===0) {
856
+					$condition = $method[9]==='_' ? substr($method,10) : substr($method,9);
857
+		} else if($delete=strncasecmp($method,'deleteby',8)===0) {
858
+					$condition = $method[8]==='_' ? substr($method,9) : substr($method,8);
859
+		} else if($delete=strncasecmp($method,'deleteallby',11)===0) {
860
+					$condition = $method[11]==='_' ? substr($method,12) : substr($method,11);
861
+		} else
840 862
 		{
841
-			if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception)
842
-				throw new TActiveRecordException('ar_invalid_finder_method',$method);
843
-			else
844
-				return null;
863
+			if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception) {
864
+							throw new TActiveRecordException('ar_invalid_finder_method',$method);
865
+			} else {
866
+							return null;
867
+			}
845 868
 		}
846 869
 
847 870
 		$criteria = $this->getRecordGateway()->getCommand($this)->createCriteriaFromString($method, $condition, $args);
848
-		if($delete)
849
-			return $this->deleteAll($criteria);
850
-		else
851
-			return $findOne ? $this->find($criteria) : $this->findAll($criteria);
871
+		if($delete) {
872
+					return $this->deleteAll($criteria);
873
+		} else {
874
+					return $findOne ? $this->find($criteria) : $this->findAll($criteria);
875
+		}
852 876
 	}
853 877
 
854 878
 	/**
@@ -858,8 +882,9 @@  discard block
 block discarded – undo
858 882
 	 */
859 883
 	public function getInvalidFinderResult()
860 884
 	{
861
-		if($this->_invalidFinderResult !== null)
862
-			return $this->_invalidFinderResult;
885
+		if($this->_invalidFinderResult !== null) {
886
+					return $this->_invalidFinderResult;
887
+		}
863 888
 
864 889
 		return self::getRecordManager()->getInvalidFinderResult();
865 890
 	}
@@ -873,10 +898,11 @@  discard block
 block discarded – undo
873 898
 	 */
874 899
 	public function setInvalidFinderResult($value)
875 900
 	{
876
-		if($value === null)
877
-			$this->_invalidFinderResult = null;
878
-		else
879
-			$this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
901
+		if($value === null) {
902
+					$this->_invalidFinderResult = null;
903
+		} else {
904
+					$this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
905
+		}
880 906
 	}
881 907
 
882 908
 	/**
@@ -894,11 +920,11 @@  discard block
 block discarded – undo
894 920
 		{
895 921
 			$useArgs = !is_array($parameters) && is_array($args);
896 922
 			return new TActiveRecordCriteria($criteria,$useArgs ? $args : $parameters);
923
+		} else if($criteria instanceof TSqlCriteria) {
924
+					return $criteria;
925
+		} else {
926
+					return new TActiveRecordCriteria();
897 927
 		}
898
-		else if($criteria instanceof TSqlCriteria)
899
-			return $criteria;
900
-		else
901
-			return new TActiveRecordCriteria();
902 928
 			//throw new TActiveRecordException('ar_invalid_criteria');
903 929
 	}
904 930
 
@@ -975,8 +1001,9 @@  discard block
 block discarded – undo
975 1001
 	public function getColumnValue($columnName)
976 1002
 	{
977 1003
 		$className=get_class($this);
978
-		if(isset(self::$_columnMapping[$className][$columnName]))
979
-			$columnName=self::$_columnMapping[$className][$columnName];
1004
+		if(isset(self::$_columnMapping[$className][$columnName])) {
1005
+					$columnName=self::$_columnMapping[$className][$columnName];
1006
+		}
980 1007
 		return $this->$columnName;
981 1008
 	}
982 1009
 
@@ -990,8 +1017,9 @@  discard block
 block discarded – undo
990 1017
 	public function setColumnValue($columnName,$value)
991 1018
 	{
992 1019
 		$className=get_class($this);
993
-		if(isset(self::$_columnMapping[$className][$columnName]))
994
-			$columnName=self::$_columnMapping[$className][$columnName];
1020
+		if(isset(self::$_columnMapping[$className][$columnName])) {
1021
+					$columnName=self::$_columnMapping[$className][$columnName];
1022
+		}
995 1023
 		$this->$columnName=$value;
996 1024
 	}
997 1025
 
Please login to merge, or discard this patch.
framework/Data/ActiveRecord/TActiveRecordGateway.php 3 patches
Doc Comments   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 * Returns records matching the list of given primary keys.
202 202
 	 * @param TActiveRecord active record instance.
203 203
 	 * @param array list of primary name value pairs
204
-	 * @return array matching data.
204
+	 * @return TDbDataReader matching data.
205 205
 	 */
206 206
 	public function findRecordsByPks(TActiveRecord $record, $keys)
207 207
 	{
@@ -227,7 +227,8 @@  discard block
 block discarded – undo
227 227
 	 * Return record data from sql query.
228 228
 	 * @param TActiveRecord active record finder instance.
229 229
 	 * @param TActiveRecordCriteria sql query
230
-	 * @return array result.
230
+	 * @param TSqlCriteria $criteria
231
+	 * @return TDbDataReader result.
231 232
 	 */
232 233
 	public function findRecordBySql(TActiveRecord $record, $criteria)
233 234
 	{
@@ -238,6 +239,7 @@  discard block
 block discarded – undo
238 239
 	 * Return record data from sql query.
239 240
 	 * @param TActiveRecord active record finder instance.
240 241
 	 * @param TActiveRecordCriteria sql query
242
+	 * @param TSqlCriteria $criteria
241 243
 	 * @return TDbDataReader result iterator.
242 244
 	 */
243 245
 	public function findRecordsBySql(TActiveRecord $record, $criteria)
@@ -264,7 +266,7 @@  discard block
 block discarded – undo
264 266
 	/**
265 267
 	 * Insert a new record.
266 268
 	 * @param TActiveRecord new record.
267
-	 * @return int number of rows affected.
269
+	 * @return string|boolean number of rows affected.
268 270
 	 */
269 271
 	public function insert(TActiveRecord $record)
270 272
 	{
@@ -279,6 +281,7 @@  discard block
 block discarded – undo
279 281
 	/**
280 282
 	 * Sets the last insert ID to the corresponding property of the record if available.
281 283
 	 * @param TActiveRecord record for insertion
284
+	 * @param TActiveRecord $record
282 285
 	 */
283 286
 	protected function updatePostInsert($record)
284 287
 	{
@@ -396,6 +399,7 @@  discard block
 block discarded – undo
396 399
 	 * Delete multiple records by criteria.
397 400
 	 * @param TActiveRecord active record finder instance.
398 401
 	 * @param TActiveRecordCriteria search criteria
402
+	 * @param TSqlCriteria $criteria
399 403
 	 * @return int number of records.
400 404
 	 */
401 405
 	public function deleteRecordsByCriteria(TActiveRecord $record, $criteria)
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -20,19 +20,19 @@  discard block
 block discarded – undo
20 20
 class TActiveRecordGateway extends TComponent
21 21
 {
22 22
 	private $_manager;
23
-	private $_tables=array(); //table cache
24
-	private $_meta=array(); //meta data cache.
25
-	private $_commandBuilders=array();
23
+	private $_tables = array(); //table cache
24
+	private $_meta = array(); //meta data cache.
25
+	private $_commandBuilders = array();
26 26
 	private $_currentRecord;
27 27
 
28 28
 	/**
29 29
 	 * Constant name for specifying optional table name in TActiveRecord.
30 30
 	 */
31
-	const TABLE_CONST='TABLE';
31
+	const TABLE_CONST = 'TABLE';
32 32
 	/**
33 33
 	 * Method name for returning optional table name in in TActiveRecord
34 34
 	 */
35
-	const TABLE_METHOD='table';
35
+	const TABLE_METHOD = 'table';
36 36
 
37 37
 	/**
38 38
 	 * Record gateway constructor.
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	public function __construct(TActiveRecordManager $manager)
42 42
 	{
43
-		$this->_manager=$manager;
43
+		$this->_manager = $manager;
44 44
 	}
45 45
 
46 46
 	/**
@@ -60,20 +60,20 @@  discard block
 block discarded – undo
60 60
 	protected function getRecordTableName(TActiveRecord $record)
61 61
 	{
62 62
 		$class = new ReflectionClass($record);
63
-		if($class->hasConstant(self::TABLE_CONST))
63
+		if ($class->hasConstant(self::TABLE_CONST))
64 64
 		{
65 65
 			$value = $class->getConstant(self::TABLE_CONST);
66
-			if(empty($value))
66
+			if (empty($value))
67 67
 				throw new TActiveRecordException('ar_invalid_tablename_property',
68
-					get_class($record),self::TABLE_CONST);
68
+					get_class($record), self::TABLE_CONST);
69 69
 			return $value;
70 70
 		}
71 71
 		elseif ($class->hasMethod(self::TABLE_METHOD))
72 72
 		{
73 73
 			$value = $record->{self::TABLE_METHOD}();
74
-			if(empty($value))
74
+			if (empty($value))
75 75
 				throw new TActiveRecordException('ar_invalid_tablename_method',
76
-					get_class($record),self::TABLE_METHOD);
76
+					get_class($record), self::TABLE_METHOD);
77 77
 			return $value;
78 78
 		}
79 79
 		else
@@ -100,24 +100,24 @@  discard block
 block discarded – undo
100 100
 	public function getTableInfo(TDbConnection $connection, $tableName)
101 101
 	{
102 102
 		$connStr = $connection->getConnectionString();
103
-		$key = $connStr.$tableName;
104
-		if(!isset($this->_tables[$key]))
103
+		$key = $connStr . $tableName;
104
+		if (!isset($this->_tables[$key]))
105 105
 		{
106 106
 			//call this first to ensure that unserializing the cache
107 107
 			//will find the correct driver dependent classes.
108
-			if(!isset($this->_meta[$connStr]))
108
+			if (!isset($this->_meta[$connStr]))
109 109
 			{
110 110
 				Prado::using('System.Data.Common.TDbMetaData');
111 111
 				$this->_meta[$connStr] = TDbMetaData::getInstance($connection);
112 112
 			}
113 113
 
114 114
 			$tableInfo = null;
115
-			if(($cache=$this->getManager()->getCache())!==null)
115
+			if (($cache = $this->getManager()->getCache()) !== null)
116 116
 				$tableInfo = $cache->get($key);
117
-			if(empty($tableInfo))
117
+			if (empty($tableInfo))
118 118
 			{
119 119
 				$tableInfo = $this->_meta[$connStr]->getTableInfo($tableName);
120
-				if($cache!==null)
120
+				if ($cache !== null)
121 121
 					$cache->set($key, $tableInfo);
122 122
 			}
123 123
 			$this->_tables[$key] = $tableInfo;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		$conn = $record->getDbConnection();
135 135
 		$connStr = $conn->getConnectionString();
136 136
 		$tableInfo = $this->getRecordTableInfo($record);
137
-		if(!isset($this->_commandBuilders[$connStr]))
137
+		if (!isset($this->_commandBuilders[$connStr]))
138 138
 		{
139 139
 			$builder = $tableInfo->createCommandBuilder($record->getDbConnection());
140 140
 			Prado::using('System.Data.DataGateway.TDataGatewayCommand');
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 
146 146
 		}
147 147
 		$this->_commandBuilders[$connStr]->getBuilder()->setTableInfo($tableInfo);
148
-		$this->_currentRecord=$record;
148
+		$this->_currentRecord = $record;
149 149
 		return $this->_commandBuilders[$connStr];
150 150
 	}
151 151
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	public function onCreateCommand($sender, $param)
163 163
 	{
164 164
 		$this->raiseEvent('OnCreateCommand', $this, $param);
165
-		if($this->_currentRecord!==null)
165
+		if ($this->_currentRecord !== null)
166 166
 			$this->_currentRecord->onCreateCommand($param);
167 167
 	}
168 168
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	public function onExecuteCommand($sender, $param)
181 181
 	{
182 182
 		$this->raiseEvent('OnExecuteCommand', $this, $param);
183
-		if($this->_currentRecord!==null)
183
+		if ($this->_currentRecord !== null)
184 184
 			$this->_currentRecord->onExecuteCommand($param);
185 185
 	}
186 186
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 * @param array primary name value pairs
192 192
 	 * @return array record data
193 193
 	 */
194
-	public function findRecordByPK(TActiveRecord $record,$keys)
194
+	public function findRecordByPK(TActiveRecord $record, $keys)
195 195
 	{
196 196
 		$command = $this->getCommand($record);
197 197
 		return $command->findByPk($keys);
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @param boolean true to return multiple rows as iterator, false returns first row.
218 218
 	 * @return mixed matching data.
219 219
 	 */
220
-	public function findRecordsByCriteria(TActiveRecord $record, $criteria, $iterator=false)
220
+	public function findRecordsByCriteria(TActiveRecord $record, $criteria, $iterator = false)
221 221
 	{
222 222
 		$command = $this->getCommand($record);
223 223
 		return $iterator ? $command->findAll($criteria) : $command->find($criteria);
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 
248 248
 	public function findRecordsByIndex(TActiveRecord $record, $criteria, $fields, $values)
249 249
 	{
250
-		return $this->getCommand($record)->findAllByIndex($criteria,$fields,$values);
250
+		return $this->getCommand($record)->findAllByIndex($criteria, $fields, $values);
251 251
 	}
252 252
 
253 253
 	/**
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	{
271 271
 		//$this->updateAssociatedRecords($record,true);
272 272
 		$result = $this->getCommand($record)->insert($this->getInsertValues($record));
273
-		if($result)
273
+		if ($result)
274 274
 			$this->updatePostInsert($record);
275 275
 		//$this->updateAssociatedRecords($record);
276 276
 		return $result;
@@ -284,10 +284,10 @@  discard block
 block discarded – undo
284 284
 	{
285 285
 		$command = $this->getCommand($record);
286 286
 		$tableInfo = $command->getTableInfo();
287
-		foreach($tableInfo->getColumns() as $name => $column)
287
+		foreach ($tableInfo->getColumns() as $name => $column)
288 288
 		{
289
-			if($column->hasSequence())
290
-				$record->setColumnValue($name,$command->getLastInsertID($column->getSequenceName()));
289
+			if ($column->hasSequence())
290
+				$record->setColumnValue($name, $command->getLastInsertID($column->getSequenceName()));
291 291
 		}
292 292
 	}
293 293
 
@@ -297,20 +297,20 @@  discard block
 block discarded – undo
297 297
 	 */
298 298
 	protected function getInsertValues(TActiveRecord $record)
299 299
 	{
300
-		$values=array();
300
+		$values = array();
301 301
 		$tableInfo = $this->getCommand($record)->getTableInfo();
302
-		foreach($tableInfo->getColumns() as $name=>$column)
302
+		foreach ($tableInfo->getColumns() as $name=>$column)
303 303
 		{
304
-			if($column->getIsExcluded())
304
+			if ($column->getIsExcluded())
305 305
 				continue;
306 306
 			$value = $record->getColumnValue($name);
307
-			if(!$column->getAllowNull() && $value===null && !$column->hasSequence() && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
307
+			if (!$column->getAllowNull() && $value === null && !$column->hasSequence() && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
308 308
 			{
309 309
 				throw new TActiveRecordException(
310 310
 					'ar_value_must_not_be_null', get_class($record),
311 311
 					$tableInfo->getTableFullName(), $name);
312 312
 			}
313
-			if($value!==null)
313
+			if ($value !== null)
314 314
 				$values[$name] = $value;
315 315
 		}
316 316
 		return $values;
@@ -332,29 +332,29 @@  discard block
 block discarded – undo
332 332
 
333 333
 	protected function getUpdateValues(TActiveRecord $record)
334 334
 	{
335
-		$values=array();
335
+		$values = array();
336 336
 		$tableInfo = $this->getCommand($record)->getTableInfo();
337
-		$primary=array();
338
-		foreach($tableInfo->getColumns() as $name=>$column)
337
+		$primary = array();
338
+		foreach ($tableInfo->getColumns() as $name=>$column)
339 339
 		{
340
-			if($column->getIsExcluded())
340
+			if ($column->getIsExcluded())
341 341
 				continue;
342 342
 			$value = $record->getColumnValue($name);
343
-			if(!$column->getAllowNull() && $value===null && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
343
+			if (!$column->getAllowNull() && $value === null && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
344 344
 			{
345 345
 				throw new TActiveRecordException(
346 346
 					'ar_value_must_not_be_null', get_class($record),
347 347
 					$tableInfo->getTableFullName(), $name);
348 348
 			}
349
-			if($column->getIsPrimaryKey())
349
+			if ($column->getIsPrimaryKey())
350 350
 				$primary[$name] = $value;
351 351
 			else
352 352
 				$values[$name] = $value;
353 353
 		}
354
-		return array($values,$primary);
354
+		return array($values, $primary);
355 355
 	}
356 356
 
357
-	protected function updateAssociatedRecords(TActiveRecord $record,$updateBelongsTo=false)
357
+	protected function updateAssociatedRecords(TActiveRecord $record, $updateBelongsTo = false)
358 358
 	{
359 359
 		$context = new TActiveRecordRelationContext($record);
360 360
 		return $context->updateAssociatedRecords($updateBelongsTo);
@@ -373,10 +373,10 @@  discard block
 block discarded – undo
373 373
 	protected function getPrimaryKeyValues(TActiveRecord $record)
374 374
 	{
375 375
 		$tableInfo = $this->getCommand($record)->getTableInfo();
376
-		$primary=array();
377
-		foreach($tableInfo->getColumns() as $name=>$column)
376
+		$primary = array();
377
+		foreach ($tableInfo->getColumns() as $name=>$column)
378 378
 		{
379
-			if($column->getIsPrimaryKey())
379
+			if ($column->getIsPrimaryKey())
380 380
 				$primary[$name] = $record->getColumnValue($name);
381 381
 		}
382 382
 		return $primary;
@@ -410,11 +410,11 @@  discard block
 block discarded – undo
410 410
 	 * @param TActiveRecord active record
411 411
 	 * @param TActiveRecordCriteria data for the command.
412 412
 	 */
413
-	protected function raiseCommandEvent($event,$command,$record,$criteria)
413
+	protected function raiseCommandEvent($event, $command, $record, $criteria)
414 414
 	{
415
-		if(!($criteria instanceof TSqlCriteria))
416
-			$criteria = new TActiveRecordCriteria(null,$criteria);
417
-		$param = new TActiveRecordEventParameter($command,$record,$criteria);
415
+		if (!($criteria instanceof TSqlCriteria))
416
+			$criteria = new TActiveRecordCriteria(null, $criteria);
417
+		$param = new TActiveRecordEventParameter($command, $record, $criteria);
418 418
 		$manager = $record->getRecordManager();
419 419
 		$manager->{$event}($param);
420 420
 		$record->{$event}($param);
Please login to merge, or discard this patch.
Braces   +47 added lines, -34 removed lines patch added patch discarded remove patch
@@ -63,21 +63,22 @@  discard block
 block discarded – undo
63 63
 		if($class->hasConstant(self::TABLE_CONST))
64 64
 		{
65 65
 			$value = $class->getConstant(self::TABLE_CONST);
66
-			if(empty($value))
67
-				throw new TActiveRecordException('ar_invalid_tablename_property',
66
+			if(empty($value)) {
67
+							throw new TActiveRecordException('ar_invalid_tablename_property',
68 68
 					get_class($record),self::TABLE_CONST);
69
+			}
69 70
 			return $value;
70
-		}
71
-		elseif ($class->hasMethod(self::TABLE_METHOD))
71
+		} elseif ($class->hasMethod(self::TABLE_METHOD))
72 72
 		{
73 73
 			$value = $record->{self::TABLE_METHOD}();
74
-			if(empty($value))
75
-				throw new TActiveRecordException('ar_invalid_tablename_method',
74
+			if(empty($value)) {
75
+							throw new TActiveRecordException('ar_invalid_tablename_method',
76 76
 					get_class($record),self::TABLE_METHOD);
77
+			}
77 78
 			return $value;
79
+		} else {
80
+					return strtolower(get_class($record));
78 81
 		}
79
-		else
80
-			return strtolower(get_class($record));
81 82
 	}
82 83
 
83 84
 	/**
@@ -112,13 +113,15 @@  discard block
 block discarded – undo
112 113
 			}
113 114
 
114 115
 			$tableInfo = null;
115
-			if(($cache=$this->getManager()->getCache())!==null)
116
-				$tableInfo = $cache->get($key);
116
+			if(($cache=$this->getManager()->getCache())!==null) {
117
+							$tableInfo = $cache->get($key);
118
+			}
117 119
 			if(empty($tableInfo))
118 120
 			{
119 121
 				$tableInfo = $this->_meta[$connStr]->getTableInfo($tableName);
120
-				if($cache!==null)
121
-					$cache->set($key, $tableInfo);
122
+				if($cache!==null) {
123
+									$cache->set($key, $tableInfo);
124
+				}
122 125
 			}
123 126
 			$this->_tables[$key] = $tableInfo;
124 127
 		}
@@ -162,8 +165,9 @@  discard block
 block discarded – undo
162 165
 	public function onCreateCommand($sender, $param)
163 166
 	{
164 167
 		$this->raiseEvent('OnCreateCommand', $this, $param);
165
-		if($this->_currentRecord!==null)
166
-			$this->_currentRecord->onCreateCommand($param);
168
+		if($this->_currentRecord!==null) {
169
+					$this->_currentRecord->onCreateCommand($param);
170
+		}
167 171
 	}
168 172
 
169 173
 	/**
@@ -180,8 +184,9 @@  discard block
 block discarded – undo
180 184
 	public function onExecuteCommand($sender, $param)
181 185
 	{
182 186
 		$this->raiseEvent('OnExecuteCommand', $this, $param);
183
-		if($this->_currentRecord!==null)
184
-			$this->_currentRecord->onExecuteCommand($param);
187
+		if($this->_currentRecord!==null) {
188
+					$this->_currentRecord->onExecuteCommand($param);
189
+		}
185 190
 	}
186 191
 
187 192
 	/**
@@ -270,8 +275,9 @@  discard block
 block discarded – undo
270 275
 	{
271 276
 		//$this->updateAssociatedRecords($record,true);
272 277
 		$result = $this->getCommand($record)->insert($this->getInsertValues($record));
273
-		if($result)
274
-			$this->updatePostInsert($record);
278
+		if($result) {
279
+					$this->updatePostInsert($record);
280
+		}
275 281
 		//$this->updateAssociatedRecords($record);
276 282
 		return $result;
277 283
 	}
@@ -286,8 +292,9 @@  discard block
 block discarded – undo
286 292
 		$tableInfo = $command->getTableInfo();
287 293
 		foreach($tableInfo->getColumns() as $name => $column)
288 294
 		{
289
-			if($column->hasSequence())
290
-				$record->setColumnValue($name,$command->getLastInsertID($column->getSequenceName()));
295
+			if($column->hasSequence()) {
296
+							$record->setColumnValue($name,$command->getLastInsertID($column->getSequenceName()));
297
+			}
291 298
 		}
292 299
 	}
293 300
 
@@ -301,8 +308,9 @@  discard block
 block discarded – undo
301 308
 		$tableInfo = $this->getCommand($record)->getTableInfo();
302 309
 		foreach($tableInfo->getColumns() as $name=>$column)
303 310
 		{
304
-			if($column->getIsExcluded())
305
-				continue;
311
+			if($column->getIsExcluded()) {
312
+							continue;
313
+			}
306 314
 			$value = $record->getColumnValue($name);
307 315
 			if(!$column->getAllowNull() && $value===null && !$column->hasSequence() && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
308 316
 			{
@@ -310,8 +318,9 @@  discard block
 block discarded – undo
310 318
 					'ar_value_must_not_be_null', get_class($record),
311 319
 					$tableInfo->getTableFullName(), $name);
312 320
 			}
313
-			if($value!==null)
314
-				$values[$name] = $value;
321
+			if($value!==null) {
322
+							$values[$name] = $value;
323
+			}
315 324
 		}
316 325
 		return $values;
317 326
 	}
@@ -337,8 +346,9 @@  discard block
 block discarded – undo
337 346
 		$primary=array();
338 347
 		foreach($tableInfo->getColumns() as $name=>$column)
339 348
 		{
340
-			if($column->getIsExcluded())
341
-				continue;
349
+			if($column->getIsExcluded()) {
350
+							continue;
351
+			}
342 352
 			$value = $record->getColumnValue($name);
343 353
 			if(!$column->getAllowNull() && $value===null && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
344 354
 			{
@@ -346,10 +356,11 @@  discard block
 block discarded – undo
346 356
 					'ar_value_must_not_be_null', get_class($record),
347 357
 					$tableInfo->getTableFullName(), $name);
348 358
 			}
349
-			if($column->getIsPrimaryKey())
350
-				$primary[$name] = $value;
351
-			else
352
-				$values[$name] = $value;
359
+			if($column->getIsPrimaryKey()) {
360
+							$primary[$name] = $value;
361
+			} else {
362
+							$values[$name] = $value;
363
+			}
353 364
 		}
354 365
 		return array($values,$primary);
355 366
 	}
@@ -376,8 +387,9 @@  discard block
 block discarded – undo
376 387
 		$primary=array();
377 388
 		foreach($tableInfo->getColumns() as $name=>$column)
378 389
 		{
379
-			if($column->getIsPrimaryKey())
380
-				$primary[$name] = $record->getColumnValue($name);
390
+			if($column->getIsPrimaryKey()) {
391
+							$primary[$name] = $record->getColumnValue($name);
392
+			}
381 393
 		}
382 394
 		return $primary;
383 395
 	}
@@ -412,8 +424,9 @@  discard block
 block discarded – undo
412 424
 	 */
413 425
 	protected function raiseCommandEvent($event,$command,$record,$criteria)
414 426
 	{
415
-		if(!($criteria instanceof TSqlCriteria))
416
-			$criteria = new TActiveRecordCriteria(null,$criteria);
427
+		if(!($criteria instanceof TSqlCriteria)) {
428
+					$criteria = new TActiveRecordCriteria(null,$criteria);
429
+		}
417 430
 		$param = new TActiveRecordEventParameter($command,$record,$criteria);
418 431
 		$manager = $record->getRecordManager();
419 432
 		$manager->{$event}($param);
Please login to merge, or discard this patch.
framework/Data/ActiveRecord/TActiveRecordManager.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -67,6 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
 	/**
69 69
 	 * @param ICache application cache
70
+	 * @param ICache $value
70 71
 	 */
71 72
 	public function setCache($value)
72 73
 	{
@@ -90,6 +91,7 @@  discard block
 block discarded – undo
90 91
 	}
91 92
 
92 93
 	/**
94
+	 * @param TComponent $self
93 95
 	 * @return TActiveRecordManager static instance of record manager.
94 96
 	 */
95 97
 	public static function getInstance($self=null)
@@ -152,6 +154,7 @@  discard block
 block discarded – undo
152 154
 	/**
153 155
 	 * Define the way an active record finder react if an invalid magic-finder invoked
154 156
 	 * @param TActiveRecordInvalidFinderResult
157
+	 * @param TActiveRecordInvalidFinderResult $value
155 158
 	 * @since 3.1.5
156 159
 	 * @see getInvalidFinderResult
157 160
 	 */
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * TActiveRecordManager class file.
4
- *
5
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6
- * @link https://github.com/pradosoft/prado
7
- * @copyright Copyright &copy; 2005-2015 The PRADO Group
8
- * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
- * @package System.Data.ActiveRecord
10
- */
3
+	 * TActiveRecordManager class file.
4
+	 *
5
+	 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6
+	 * @link https://github.com/pradosoft/prado
7
+	 * @copyright Copyright &copy; 2005-2015 The PRADO Group
8
+	 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
+	 * @package System.Data.ActiveRecord
10
+	 */
11 11
 
12 12
 Prado::using('System.Data.TDbConnection');
13 13
 Prado::using('System.Data.ActiveRecord.TActiveRecord');
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	private $_gatewayClass = self::DEFAULT_GATEWAY_CLASS;
45 45
 
46 46
 	private $_gateway;
47
-	private $_meta=array();
47
+	private $_meta = array();
48 48
 	private $_connection;
49 49
 
50 50
 	private $_cache;
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function setCache($value)
72 72
 	{
73
-		$this->_cache=$value;
73
+		$this->_cache = $value;
74 74
 	}
75 75
 
76 76
 	/**
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	public function setDbConnection($conn)
80 80
 	{
81
-		$this->_connection=$conn;
81
+		$this->_connection = $conn;
82 82
 	}
83 83
 
84 84
 	/**
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 	/**
93 93
 	 * @return TActiveRecordManager static instance of record manager.
94 94
 	 */
95
-	public static function getInstance($self=null)
95
+	public static function getInstance($self = null)
96 96
 	{
97 97
 		static $instance;
98
-		if($self!==null)
99
-			$instance=$self;
100
-		else if($instance===null)
98
+		if ($self !== null)
99
+			$instance = $self;
100
+		else if ($instance === null)
101 101
 			$instance = new self;
102 102
 		return $instance;
103 103
 	}
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	public function getRecordGateway()
109 109
 	{
110
-		if($this->_gateway === null) {
110
+		if ($this->_gateway === null) {
111 111
 			$this->_gateway = $this->createRecordGateway();
112 112
 		}
113 113
 		return $this->_gateway;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	public function setGatewayClass($value)
129 129
 	{
130 130
 		$this->_gateway = null;
131
-		$this->_gatewayClass = (string)$value;
131
+		$this->_gatewayClass = (string) $value;
132 132
 	}
133 133
 
134 134
 	/**
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -95,10 +95,11 @@
 block discarded – undo
95 95
 	public static function getInstance($self=null)
96 96
 	{
97 97
 		static $instance;
98
-		if($self!==null)
99
-			$instance=$self;
100
-		else if($instance===null)
101
-			$instance = new self;
98
+		if($self!==null) {
99
+					$instance=$self;
100
+		} else if($instance===null) {
101
+					$instance = new self;
102
+		}
102 103
 		return $instance;
103 104
 	}
104 105
 
Please login to merge, or discard this patch.
framework/Data/Common/Mssql/TMssqlMetaData.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -123,6 +123,7 @@
 block discarded – undo
123 123
 	/**
124 124
 	 * @param TMssqlTableInfo table information.
125 125
 	 * @param array column information.
126
+	 * @param TMssqlTableInfo $tableInfo
126 127
 	 */
127 128
 	protected function processColumn($tableInfo, $col)
128 129
 	{
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -259,15 +259,15 @@
 block discarded – undo
259 259
 		return false;
260 260
 	}
261 261
 
262
-        /**
263
-	 * Returns all table names in the database.
264
-	 * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
265
-	 * If not empty, the returned table names will be prefixed with the schema name.
266
-	 * @return array all table names in the database.
267
-	 */
262
+		/**
263
+		 * Returns all table names in the database.
264
+		 * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
265
+		 * If not empty, the returned table names will be prefixed with the schema name.
266
+		 * @return array all table names in the database.
267
+		 */
268 268
 	public function findTableNames($schema='dbo')
269 269
 	{
270
-                $condition="TABLE_TYPE='BASE TABLE'";
270
+				$condition="TABLE_TYPE='BASE TABLE'";
271 271
 		$sql=<<<EOD
272 272
 SELECT TABLE_NAME, TABLE_SCHEMA FROM [INFORMATION_SCHEMA].[TABLES]
273 273
 WHERE TABLE_SCHEMA=:schema AND $condition
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	protected function createTableInfo($table)
71 71
 	{
72
-		list($catalogName,$schemaName,$tableName) = $this->getCatalogSchemaTableName($table);
72
+		list($catalogName, $schemaName, $tableName) = $this->getCatalogSchemaTableName($table);
73 73
 		$this->getDbConnection()->setActive(true);
74 74
 		$sql = <<<EOD
75 75
 				SELECT t.*,
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
 									WHERE t.table_name = c.table_name
81 81
 										AND t.table_name = :table
82 82
 EOD;
83
-		if($schemaName!==null)
83
+		if ($schemaName !== null)
84 84
 			$sql .= ' AND t.table_schema = :schema';
85
-		if($catalogName!==null)
85
+		if ($catalogName !== null)
86 86
 			$sql .= ' AND t.table_catalog = :catalog';
87 87
 
88 88
 		$command = $this->getDbConnection()->createCommand($sql);
89 89
 		$command->bindValue(':table', $tableName);
90
-		if($schemaName!==null)
90
+		if ($schemaName !== null)
91 91
 			$command->bindValue(':schema', $schemaName);
92
-		if($catalogName!==null)
92
+		if ($catalogName !== null)
93 93
 			$command->bindValue(':catalog', $catalogName);
94 94
 
95
-		$tableInfo=null;
96
-		foreach($command->query() as $col)
95
+		$tableInfo = null;
96
+		foreach ($command->query() as $col)
97 97
 		{
98
-			if($tableInfo===null)
98
+			if ($tableInfo === null)
99 99
 				$tableInfo = $this->createNewTableInfo($col);
100
-			$this->processColumn($tableInfo,$col);
100
+			$this->processColumn($tableInfo, $col);
101 101
 		}
102
-		if($tableInfo===null)
102
+		if ($tableInfo === null)
103 103
 			throw new TDbException('dbmetadata_invalid_table_view', $table);
104 104
 		return $tableInfo;
105 105
 	}
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 	{
113 113
 		//remove possible delimiters
114 114
 		$result = explode('.', preg_replace('/\[|\]|"/', '', $table));
115
-		if(count($result)===1)
116
-			return array(null,null,$result[0]);
117
-		if(count($result)===2)
118
-			return array(null,$result[0],$result[1]);
119
-		if(count($result)>2)
120
-			return array($result[0],$result[1],$result[2]);
115
+		if (count($result) === 1)
116
+			return array(null, null, $result[0]);
117
+		if (count($result) === 2)
118
+			return array(null, $result[0], $result[1]);
119
+		if (count($result) > 2)
120
+			return array($result[0], $result[1], $result[2]);
121 121
 	}
122 122
 
123 123
 	/**
@@ -130,25 +130,25 @@  discard block
 block discarded – undo
130 130
 
131 131
 		$info['ColumnName'] = "[$columnId]"; //quote the column names!
132 132
 		$info['ColumnId'] = $columnId;
133
-		$info['ColumnIndex'] = intval($col['ORDINAL_POSITION'])-1; //zero-based index
134
-		if($col['IS_NULLABLE']!=='NO')
133
+		$info['ColumnIndex'] = intval($col['ORDINAL_POSITION']) - 1; //zero-based index
134
+		if ($col['IS_NULLABLE'] !== 'NO')
135 135
 			$info['AllowNull'] = true;
136
-		if($col['COLUMN_DEFAULT']!==null)
136
+		if ($col['COLUMN_DEFAULT'] !== null)
137 137
 			$info['DefaultValue'] = $col['COLUMN_DEFAULT'];
138 138
 
139
-		if(in_array($columnId, $tableInfo->getPrimaryKeys()))
139
+		if (in_array($columnId, $tableInfo->getPrimaryKeys()))
140 140
 			$info['IsPrimaryKey'] = true;
141
-		if($this->isForeignKeyColumn($columnId, $tableInfo))
141
+		if ($this->isForeignKeyColumn($columnId, $tableInfo))
142 142
 			$info['IsForeignKey'] = true;
143 143
 
144
-		if($col['IsIdentity']==='1')
144
+		if ($col['IsIdentity'] === '1')
145 145
 			$info['AutoIncrement'] = true;
146 146
 		$info['DbType'] = $col['DATA_TYPE'];
147
-		if($col['CHARACTER_MAXIMUM_LENGTH']!==null)
147
+		if ($col['CHARACTER_MAXIMUM_LENGTH'] !== null)
148 148
 			$info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']);
149
-		if($col['NUMERIC_PRECISION'] !== null)
149
+		if ($col['NUMERIC_PRECISION'] !== null)
150 150
 			$info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']);
151
-		if($col['NUMERIC_SCALE']!==null)
151
+		if ($col['NUMERIC_SCALE'] !== null)
152 152
 			$info['NumericScale'] = intval($col['NUMERIC_SCALE']);
153 153
 		$tableInfo->Columns[$columnId] = new TMssqlTableColumn($info);
154 154
 	}
@@ -163,11 +163,11 @@  discard block
 block discarded – undo
163 163
 		$info['CatalogName'] = $col['TABLE_CATALOG'];
164 164
 		$info['SchemaName'] = $col['TABLE_SCHEMA'];
165 165
 		$info['TableName'] = $col['TABLE_NAME'];
166
-		if($col['TABLE_TYPE']==='VIEW')
166
+		if ($col['TABLE_TYPE'] === 'VIEW')
167 167
 			$info['IsView'] = true;
168 168
 		list($primary, $foreign) = $this->getConstraintKeys($col);
169 169
 		$class = $this->getTableInfoClass();
170
-		return new $class($info,$primary,$foreign);
170
+		return new $class($info, $primary, $foreign);
171 171
 	}
172 172
 
173 173
 	/**
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
 		$command = $this->getDbConnection()->createCommand($sql);
193 193
 		$command->bindValue(':table', $col['TABLE_NAME']);
194 194
 		$primary = array();
195
-		foreach($command->query()->readAll() as $field)
195
+		foreach ($command->query()->readAll() as $field)
196 196
 			$primary[] = $field['field_name'];
197 197
 		$foreign = $this->getForeignConstraints($col);
198
-		return array($primary,$foreign);
198
+		return array($primary, $foreign);
199 199
 	}
200 200
 
201 201
 	/**
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 EOD;
235 235
 		$command = $this->getDbConnection()->createCommand($sql);
236 236
 		$command->bindValue(':table', $col['TABLE_NAME']);
237
-		$fkeys=array();
237
+		$fkeys = array();
238 238
 		$catalogSchema = "[{$col['TABLE_CATALOG']}].[{$col['TABLE_SCHEMA']}]";
239
-		foreach($command->query() as $info)
239
+		foreach ($command->query() as $info)
240 240
 		{
241 241
 			$fkeys[$info['FK_CONSTRAINT_NAME']]['keys'][$info['FK_COLUMN_NAME']] = $info['UQ_COLUMN_NAME'];
242 242
 			$fkeys[$info['FK_CONSTRAINT_NAME']]['table'] = $info['UQ_TABLE_NAME'];
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
 	 */
252 252
 	protected function isForeignKeyColumn($columnId, $tableInfo)
253 253
 	{
254
-		foreach($tableInfo->getForeignKeys() as $fk)
254
+		foreach ($tableInfo->getForeignKeys() as $fk)
255 255
 		{
256
-			if(in_array($columnId, array_keys($fk['keys'])))
256
+			if (in_array($columnId, array_keys($fk['keys'])))
257 257
 				return true;
258 258
 		}
259 259
 		return false;
@@ -265,23 +265,23 @@  discard block
 block discarded – undo
265 265
 	 * If not empty, the returned table names will be prefixed with the schema name.
266 266
 	 * @return array all table names in the database.
267 267
 	 */
268
-	public function findTableNames($schema='dbo')
268
+	public function findTableNames($schema = 'dbo')
269 269
 	{
270
-                $condition="TABLE_TYPE='BASE TABLE'";
271
-		$sql=<<<EOD
270
+                $condition = "TABLE_TYPE='BASE TABLE'";
271
+		$sql = <<<EOD
272 272
 SELECT TABLE_NAME, TABLE_SCHEMA FROM [INFORMATION_SCHEMA].[TABLES]
273 273
 WHERE TABLE_SCHEMA=:schema AND $condition
274 274
 EOD;
275
-		$command=$this->getDbConnection()->createCommand($sql);
275
+		$command = $this->getDbConnection()->createCommand($sql);
276 276
 		$command->bindParam(":schema", $schema);
277
-		$rows=$command->queryAll();
278
-		$names=array();
277
+		$rows = $command->queryAll();
278
+		$names = array();
279 279
 		foreach ($rows as $row)
280 280
 		{
281 281
 			if ($schema == self::DEFAULT_SCHEMA)
282
-				$names[]=$row['TABLE_NAME'];
282
+				$names[] = $row['TABLE_NAME'];
283 283
 			else
284
-				$names[]=$schema.'.'.$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME'];
284
+				$names[] = $schema . '.' . $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME'];
285 285
 		}
286 286
 
287 287
 		return $names;
Please login to merge, or discard this patch.
Braces   +65 added lines, -44 removed lines patch added patch discarded remove patch
@@ -80,27 +80,33 @@  discard block
 block discarded – undo
80 80
 									WHERE t.table_name = c.table_name
81 81
 										AND t.table_name = :table
82 82
 EOD;
83
-		if($schemaName!==null)
84
-			$sql .= ' AND t.table_schema = :schema';
85
-		if($catalogName!==null)
86
-			$sql .= ' AND t.table_catalog = :catalog';
83
+		if($schemaName!==null) {
84
+					$sql .= ' AND t.table_schema = :schema';
85
+		}
86
+		if($catalogName!==null) {
87
+					$sql .= ' AND t.table_catalog = :catalog';
88
+		}
87 89
 
88 90
 		$command = $this->getDbConnection()->createCommand($sql);
89 91
 		$command->bindValue(':table', $tableName);
90
-		if($schemaName!==null)
91
-			$command->bindValue(':schema', $schemaName);
92
-		if($catalogName!==null)
93
-			$command->bindValue(':catalog', $catalogName);
92
+		if($schemaName!==null) {
93
+					$command->bindValue(':schema', $schemaName);
94
+		}
95
+		if($catalogName!==null) {
96
+					$command->bindValue(':catalog', $catalogName);
97
+		}
94 98
 
95 99
 		$tableInfo=null;
96 100
 		foreach($command->query() as $col)
97 101
 		{
98
-			if($tableInfo===null)
99
-				$tableInfo = $this->createNewTableInfo($col);
102
+			if($tableInfo===null) {
103
+							$tableInfo = $this->createNewTableInfo($col);
104
+			}
100 105
 			$this->processColumn($tableInfo,$col);
101 106
 		}
102
-		if($tableInfo===null)
103
-			throw new TDbException('dbmetadata_invalid_table_view', $table);
107
+		if($tableInfo===null) {
108
+					throw new TDbException('dbmetadata_invalid_table_view', $table);
109
+		}
104 110
 		return $tableInfo;
105 111
 	}
106 112
 
@@ -112,12 +118,15 @@  discard block
 block discarded – undo
112 118
 	{
113 119
 		//remove possible delimiters
114 120
 		$result = explode('.', preg_replace('/\[|\]|"/', '', $table));
115
-		if(count($result)===1)
116
-			return array(null,null,$result[0]);
117
-		if(count($result)===2)
118
-			return array(null,$result[0],$result[1]);
119
-		if(count($result)>2)
120
-			return array($result[0],$result[1],$result[2]);
121
+		if(count($result)===1) {
122
+					return array(null,null,$result[0]);
123
+		}
124
+		if(count($result)===2) {
125
+					return array(null,$result[0],$result[1]);
126
+		}
127
+		if(count($result)>2) {
128
+					return array($result[0],$result[1],$result[2]);
129
+		}
121 130
 	}
122 131
 
123 132
 	/**
@@ -131,25 +140,33 @@  discard block
 block discarded – undo
131 140
 		$info['ColumnName'] = "[$columnId]"; //quote the column names!
132 141
 		$info['ColumnId'] = $columnId;
133 142
 		$info['ColumnIndex'] = intval($col['ORDINAL_POSITION'])-1; //zero-based index
134
-		if($col['IS_NULLABLE']!=='NO')
135
-			$info['AllowNull'] = true;
136
-		if($col['COLUMN_DEFAULT']!==null)
137
-			$info['DefaultValue'] = $col['COLUMN_DEFAULT'];
143
+		if($col['IS_NULLABLE']!=='NO') {
144
+					$info['AllowNull'] = true;
145
+		}
146
+		if($col['COLUMN_DEFAULT']!==null) {
147
+					$info['DefaultValue'] = $col['COLUMN_DEFAULT'];
148
+		}
138 149
 
139
-		if(in_array($columnId, $tableInfo->getPrimaryKeys()))
140
-			$info['IsPrimaryKey'] = true;
141
-		if($this->isForeignKeyColumn($columnId, $tableInfo))
142
-			$info['IsForeignKey'] = true;
150
+		if(in_array($columnId, $tableInfo->getPrimaryKeys())) {
151
+					$info['IsPrimaryKey'] = true;
152
+		}
153
+		if($this->isForeignKeyColumn($columnId, $tableInfo)) {
154
+					$info['IsForeignKey'] = true;
155
+		}
143 156
 
144
-		if($col['IsIdentity']==='1')
145
-			$info['AutoIncrement'] = true;
157
+		if($col['IsIdentity']==='1') {
158
+					$info['AutoIncrement'] = true;
159
+		}
146 160
 		$info['DbType'] = $col['DATA_TYPE'];
147
-		if($col['CHARACTER_MAXIMUM_LENGTH']!==null)
148
-			$info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']);
149
-		if($col['NUMERIC_PRECISION'] !== null)
150
-			$info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']);
151
-		if($col['NUMERIC_SCALE']!==null)
152
-			$info['NumericScale'] = intval($col['NUMERIC_SCALE']);
161
+		if($col['CHARACTER_MAXIMUM_LENGTH']!==null) {
162
+					$info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']);
163
+		}
164
+		if($col['NUMERIC_PRECISION'] !== null) {
165
+					$info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']);
166
+		}
167
+		if($col['NUMERIC_SCALE']!==null) {
168
+					$info['NumericScale'] = intval($col['NUMERIC_SCALE']);
169
+		}
153 170
 		$tableInfo->Columns[$columnId] = new TMssqlTableColumn($info);
154 171
 	}
155 172
 
@@ -163,8 +180,9 @@  discard block
 block discarded – undo
163 180
 		$info['CatalogName'] = $col['TABLE_CATALOG'];
164 181
 		$info['SchemaName'] = $col['TABLE_SCHEMA'];
165 182
 		$info['TableName'] = $col['TABLE_NAME'];
166
-		if($col['TABLE_TYPE']==='VIEW')
167
-			$info['IsView'] = true;
183
+		if($col['TABLE_TYPE']==='VIEW') {
184
+					$info['IsView'] = true;
185
+		}
168 186
 		list($primary, $foreign) = $this->getConstraintKeys($col);
169 187
 		$class = $this->getTableInfoClass();
170 188
 		return new $class($info,$primary,$foreign);
@@ -192,8 +210,9 @@  discard block
 block discarded – undo
192 210
 		$command = $this->getDbConnection()->createCommand($sql);
193 211
 		$command->bindValue(':table', $col['TABLE_NAME']);
194 212
 		$primary = array();
195
-		foreach($command->query()->readAll() as $field)
196
-			$primary[] = $field['field_name'];
213
+		foreach($command->query()->readAll() as $field) {
214
+					$primary[] = $field['field_name'];
215
+		}
197 216
 		$foreign = $this->getForeignConstraints($col);
198 217
 		return array($primary,$foreign);
199 218
 	}
@@ -253,8 +272,9 @@  discard block
 block discarded – undo
253 272
 	{
254 273
 		foreach($tableInfo->getForeignKeys() as $fk)
255 274
 		{
256
-			if(in_array($columnId, array_keys($fk['keys'])))
257
-				return true;
275
+			if(in_array($columnId, array_keys($fk['keys']))) {
276
+							return true;
277
+			}
258 278
 		}
259 279
 		return false;
260 280
 	}
@@ -278,10 +298,11 @@  discard block
 block discarded – undo
278 298
 		$names=array();
279 299
 		foreach ($rows as $row)
280 300
 		{
281
-			if ($schema == self::DEFAULT_SCHEMA)
282
-				$names[]=$row['TABLE_NAME'];
283
-			else
284
-				$names[]=$schema.'.'.$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME'];
301
+			if ($schema == self::DEFAULT_SCHEMA) {
302
+							$names[]=$row['TABLE_NAME'];
303
+			} else {
304
+							$names[]=$schema.'.'.$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME'];
305
+			}
285 306
 		}
286 307
 
287 308
 		return $names;
Please login to merge, or discard this patch.
framework/Data/Common/Mssql/TMssqlTableColumn.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 
28 28
 	/**
29 29
 	 * Overrides parent implementation, returns PHP type from the db type.
30
-	 * @return boolean derived PHP primitive type from the column db type.
30
+	 * @return string derived PHP primitive type from the column db type.
31 31
 	 */
32 32
 	public function getPHPType()
33 33
 	{
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	public function getAutoIncrement()
42 42
 	{
43
-		return $this->getInfo('AutoIncrement',false);
43
+		return $this->getInfo('AutoIncrement', false);
44 44
 	}
45 45
 
46 46
 	/**
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public function getIsExcluded()
58 58
 	{
59
-		return strtolower($this->getDbType())==='timestamp';
59
+		return strtolower($this->getDbType()) === 'timestamp';
60 60
 	}
61 61
 }
62 62
 
Please login to merge, or discard this patch.
framework/Data/Common/Mysql/TMysqlMetaData.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -114,6 +114,7 @@
 block discarded – undo
114 114
 	/**
115 115
 	 * @param TMysqlTableInfo table information.
116 116
 	 * @param array column information.
117
+	 * @param TMysqlTableInfo $tableInfo
117 118
 	 */
118 119
 	protected function processColumn($tableInfo, $col)
119 120
 	{
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  */
28 28
 class TMysqlMetaData extends TDbMetaData
29 29
 {
30
-	private $_serverVersion=0;
30
+	private $_serverVersion = 0;
31 31
 
32 32
 	/**
33 33
 	 * @return string TDbTableInfo class name.
@@ -74,24 +74,24 @@  discard block
 block discarded – undo
74 74
 	 */
75 75
 	protected function createTableInfo($table)
76 76
 	{
77
-		list($schemaName,$tableName) = $this->getSchemaTableName($table);
78
-		$find = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
77
+		list($schemaName, $tableName) = $this->getSchemaTableName($table);
78
+		$find = $schemaName === null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
79 79
 		$colCase = $this->getDbConnection()->getColumnCase();
80
-		if($colCase != TDbColumnCaseMode::Preserved)
80
+		if ($colCase != TDbColumnCaseMode::Preserved)
81 81
 			$this->getDbConnection()->setColumnCase('Preserved');
82 82
 		$this->getDbConnection()->setActive(true);
83 83
 		$sql = "SHOW FULL FIELDS FROM {$find}";
84 84
 		$command = $this->getDbConnection()->createCommand($sql);
85 85
 		$tableInfo = $this->createNewTableInfo($table);
86
-		$index=0;
87
-		foreach($command->query() as $col)
86
+		$index = 0;
87
+		foreach ($command->query() as $col)
88 88
 		{
89 89
 			$col['index'] = $index++;
90
-			$this->processColumn($tableInfo,$col);
90
+			$this->processColumn($tableInfo, $col);
91 91
 		}
92
-		if($index===0)
92
+		if ($index === 0)
93 93
 			throw new TDbException('dbmetadata_invalid_table_view', $table);
94
-		if($colCase != TDbColumnCaseMode::Preserved)
94
+		if ($colCase != TDbColumnCaseMode::Preserved)
95 95
 			$this->getDbConnection()->setColumnCase($colCase);
96 96
 		return $tableInfo;
97 97
 	}
@@ -101,12 +101,12 @@  discard block
 block discarded – undo
101 101
 	 */
102 102
 	protected function getServerVersion()
103 103
 	{
104
-		if(!$this->_serverVersion)
104
+		if (!$this->_serverVersion)
105 105
 		{
106 106
 			$version = $this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION);
107
-			$digits=array();
107
+			$digits = array();
108 108
 			preg_match('/(\d+)\.(\d+)\.(\d+)/', $version, $digits);
109
-			$this->_serverVersion=floatval($digits[1].'.'.$digits[2].$digits[3]);
109
+			$this->_serverVersion = floatval($digits[1] . '.' . $digits[2] . $digits[3]);
110 110
 		}
111 111
 		return $this->_serverVersion;
112 112
 	}
@@ -122,37 +122,37 @@  discard block
 block discarded – undo
122 122
 		$info['ColumnName'] = "`$columnId`"; //quote the column names!
123 123
 		$info['ColumnId'] = $columnId;
124 124
 		$info['ColumnIndex'] = $col['index'];
125
-		if($col['Null']==='YES')
125
+		if ($col['Null'] === 'YES')
126 126
 			$info['AllowNull'] = true;
127
-		if(is_int(strpos(strtolower($col['Extra']), 'auto_increment')))
128
-			$info['AutoIncrement']=true;
129
-		if($col['Default']!=="")
127
+		if (is_int(strpos(strtolower($col['Extra']), 'auto_increment')))
128
+			$info['AutoIncrement'] = true;
129
+		if ($col['Default'] !== "")
130 130
 			$info['DefaultValue'] = $col['Default'];
131 131
 
132
-		if($col['Key']==='PRI' || in_array($columnId, $tableInfo->getPrimaryKeys()))
132
+		if ($col['Key'] === 'PRI' || in_array($columnId, $tableInfo->getPrimaryKeys()))
133 133
 			$info['IsPrimaryKey'] = true;
134
-		if($this->isForeignKeyColumn($columnId, $tableInfo))
134
+		if ($this->isForeignKeyColumn($columnId, $tableInfo))
135 135
 			$info['IsForeignKey'] = true;
136 136
 
137 137
 		$info['DbType'] = $col['Type'];
138
-		$match=array();
138
+		$match = array();
139 139
 		//find SET/ENUM values, column size, precision, and scale
140
-		if(preg_match('/\((.*)\)/', $col['Type'], $match))
140
+		if (preg_match('/\((.*)\)/', $col['Type'], $match))
141 141
 		{
142
-			$info['DbType']= preg_replace('/\(.*\)/', '', $col['Type']);
142
+			$info['DbType'] = preg_replace('/\(.*\)/', '', $col['Type']);
143 143
 
144 144
 			//find SET/ENUM values
145
-			if($this->isEnumSetType($info['DbType']))
145
+			if ($this->isEnumSetType($info['DbType']))
146 146
 				$info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY);
147 147
 
148 148
 			//find column size, precision and scale
149 149
 			$pscale = array();
150
-			if(preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale))
150
+			if (preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale))
151 151
 			{
152
-				if($this->isPrecisionType($info['DbType']))
152
+				if ($this->isPrecisionType($info['DbType']))
153 153
 				{
154 154
 					$info['NumericPrecision'] = intval($pscale[1]);
155
-					if(count($pscale) > 2)
155
+					if (count($pscale) > 2)
156 156
 						$info['NumericScale'] = intval($pscale[2]);
157 157
 				}
158 158
 				else
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 	protected function isPrecisionType($type)
170 170
 	{
171 171
 		$type = strtolower(trim($type));
172
-		return $type==='decimal' || $type==='dec'
173
-				|| $type==='float' || $type==='double'
174
-				|| $type==='double precision' || $type==='real';
172
+		return $type === 'decimal' || $type === 'dec'
173
+				|| $type === 'float' || $type === 'double'
174
+				|| $type === 'double precision' || $type === 'real';
175 175
 	}
176 176
 
177 177
 	/**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	protected function isEnumSetType($type)
181 181
 	{
182 182
 		$type = strtolower(trim($type));
183
-		return $type==='set' || $type==='enum';
183
+		return $type === 'set' || $type === 'enum';
184 184
 	}
185 185
 
186 186
 	/**
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
 	{
193 193
 		//remove the back ticks and separate out the "database.table"
194 194
 		$result = explode('.', str_replace('`', '', $table));
195
-		foreach($result as $name)
195
+		foreach ($result as $name)
196 196
 		{
197
-			if(!$this->isValidIdentifier($name))
197
+			if (!$this->isValidIdentifier($name))
198 198
 			{
199 199
 				$ref = 'http://dev.mysql.com/doc/refman/5.0/en/identifiers.html';
200 200
 				throw new TDbException('dbcommon_invalid_identifier_name', $table, $ref);
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
 	 */
221 221
 	protected function createNewTableInfo($table)
222 222
 	{
223
-		list($schemaName,$tableName) = $this->getSchemaTableName($table);
223
+		list($schemaName, $tableName) = $this->getSchemaTableName($table);
224 224
 		$info['SchemaName'] = $schemaName;
225 225
 		$info['TableName'] = $tableName;
226
-		if($this->getIsView($schemaName,$tableName))
226
+		if ($this->getIsView($schemaName, $tableName))
227 227
 			$info['IsView'] = true;
228 228
 		list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
229 229
 		$class = $this->getTableInfoClass();
230
-		return new $class($info,$primary,$foreign);
230
+		return new $class($info, $primary, $foreign);
231 231
 	}
232 232
 
233 233
 	/**
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
 	 * @return boolean true if is view, false otherwise.
241 241
 	 * @throws TDbException if table or view does not exist.
242 242
 	 */
243
-	protected function getIsView($schemaName,$tableName)
243
+	protected function getIsView($schemaName, $tableName)
244 244
 	{
245
-		if($this->getServerVersion()<5.01)
245
+		if ($this->getServerVersion() < 5.01)
246 246
 			return false;
247
-		if($schemaName!==null)
247
+		if ($schemaName !== null)
248 248
 			$sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table";
249 249
 		else
250 250
 			$sql = "SHOW FULL TABLES LIKE :table";
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
 		$command->bindValue(':table', $tableName);
254 254
 		try
255 255
 		{
256
-			return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW';
256
+			return count($result = $command->queryRow()) > 0 && $result['Table_type'] === 'VIEW';
257 257
 		}
258
-		catch(TDbException $e)
258
+		catch (TDbException $e)
259 259
 		{
260
-			$table = $schemaName===null?$tableName:$schemaName.'.'.$tableName;
261
-			throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage());
260
+			$table = $schemaName === null ? $tableName : $schemaName . '.' . $tableName;
261
+			throw new TDbException('dbcommon_invalid_table_name', $table, $e->getMessage());
262 262
 		}
263 263
 	}
264 264
 
@@ -270,22 +270,22 @@  discard block
 block discarded – undo
270 270
 	 */
271 271
 	protected function getConstraintKeys($schemaName, $tableName)
272 272
 	{
273
-		$table = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
273
+		$table = $schemaName === null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
274 274
 		$sql = "SHOW INDEX FROM {$table}";
275 275
 		$command = $this->getDbConnection()->createCommand($sql);
276 276
 		$primary = array();
277
-		foreach($command->query() as $row)
277
+		foreach ($command->query() as $row)
278 278
 		{
279
-			if($row['Key_name']==='PRIMARY')
279
+			if ($row['Key_name'] === 'PRIMARY')
280 280
 				$primary[] = $row['Column_name'];
281 281
 		}
282 282
 				// MySQL version was increased to >=5.1.21 instead of 5.x
283 283
 				// due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588)
284
-		if($this->getServerVersion() >= 5.121)
285
-			$foreign = $this->getForeignConstraints($schemaName,$tableName);
284
+		if ($this->getServerVersion() >= 5.121)
285
+			$foreign = $this->getForeignConstraints($schemaName, $tableName);
286 286
 		else
287
-			$foreign = $this->findForeignConstraints($schemaName,$tableName);
288
-		return array($primary,$foreign);
287
+			$foreign = $this->findForeignConstraints($schemaName, $tableName);
288
+		return array($primary, $foreign);
289 289
 	}
290 290
 
291 291
 	/**
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
 EOD;
314 314
 		$command = $this->getDbConnection()->createCommand($sql);
315 315
 		$command->bindValue(':table', $tableName);
316
-		if($schemaName!==null)
316
+		if ($schemaName !== null)
317 317
 			$command->bindValue(':schema', $schemaName);
318
-		$fkeys=array();
319
-		foreach($command->query() as $col)
318
+		$fkeys = array();
319
+		foreach ($command->query() as $col)
320 320
 		{
321 321
 			$fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol'];
322 322
 			$fkeys[$col['con']]['table'] = $col['fktable'];
@@ -332,12 +332,12 @@  discard block
 block discarded – undo
332 332
 	 */
333 333
 	protected function getShowCreateTable($schemaName, $tableName)
334 334
 	{
335
-		if(version_compare(PHP_VERSION,'5.1.3','<'))
335
+		if (version_compare(PHP_VERSION, '5.1.3', '<'))
336 336
 			throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3');
337 337
 
338 338
 		//See http://netevil.org/node.php?nid=795&SC=1
339 339
 		$this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
340
-		if($schemaName!==null)
340
+		if ($schemaName !== null)
341 341
 			$sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`";
342 342
 		else
343 343
 			$sql = "SHOW CREATE TABLE `{$tableName}`";
@@ -355,16 +355,16 @@  discard block
 block discarded – undo
355 355
 	protected function findForeignConstraints($schemaName, $tableName)
356 356
 	{
357 357
 		$sql = $this->getShowCreateTable($schemaName, $tableName);
358
-		$matches =array();
358
+		$matches = array();
359 359
 		$regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi';
360
-		preg_match_all($regexp,$sql,$matches,PREG_SET_ORDER);
360
+		preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER);
361 361
 		$foreign = array();
362
-		foreach($matches as $match)
362
+		foreach ($matches as $match)
363 363
 		{
364
-			$fields = array_map('trim',explode(',',str_replace('`','',$match[1])));
365
-			$fk_fields = array_map('trim',explode(',',str_replace('`','',$match[3])));
366
-			$keys=array();
367
-			foreach($fields as $k=>$v)
364
+			$fields = array_map('trim', explode(',', str_replace('`', '', $match[1])));
365
+			$fk_fields = array_map('trim', explode(',', str_replace('`', '', $match[3])));
366
+			$keys = array();
367
+			foreach ($fields as $k=>$v)
368 368
 				$keys[$v] = $fk_fields[$k];
369 369
 			$foreign[] = array('keys' => $keys, 'table' => trim($match[2]));
370 370
 		}
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
 	 */
379 379
 	protected function isForeignKeyColumn($columnId, $tableInfo)
380 380
 	{
381
-		foreach($tableInfo->getForeignKeys() as $fk)
381
+		foreach ($tableInfo->getForeignKeys() as $fk)
382 382
 		{
383
-			if(in_array($columnId, array_keys($fk['keys'])))
383
+			if (in_array($columnId, array_keys($fk['keys'])))
384 384
 				return true;
385 385
 		}
386 386
 		return false;
@@ -392,13 +392,13 @@  discard block
 block discarded – undo
392 392
 	 * If not empty, the returned table names will be prefixed with the schema name.
393 393
 	 * @return array all table names in the database.
394 394
 	 */
395
-	public function findTableNames($schema='')
395
+	public function findTableNames($schema = '')
396 396
 	{
397
-		if($schema==='')
397
+		if ($schema === '')
398 398
 			return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn();
399
-		$names=$this->getDbConnection()->createCommand('SHOW TABLES FROM '.$this->quoteTableName($schema))->queryColumn();
400
-		foreach($names as &$name)
401
-			$name=$schema.'.'.$name;
399
+		$names = $this->getDbConnection()->createCommand('SHOW TABLES FROM ' . $this->quoteTableName($schema))->queryColumn();
400
+		foreach ($names as &$name)
401
+			$name = $schema . '.' . $name;
402 402
 		return $names;
403 403
 	}
404 404
 }
Please login to merge, or discard this patch.
Braces   +75 added lines, -54 removed lines patch added patch discarded remove patch
@@ -77,8 +77,9 @@  discard block
 block discarded – undo
77 77
 		list($schemaName,$tableName) = $this->getSchemaTableName($table);
78 78
 		$find = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
79 79
 		$colCase = $this->getDbConnection()->getColumnCase();
80
-		if($colCase != TDbColumnCaseMode::Preserved)
81
-			$this->getDbConnection()->setColumnCase('Preserved');
80
+		if($colCase != TDbColumnCaseMode::Preserved) {
81
+					$this->getDbConnection()->setColumnCase('Preserved');
82
+		}
82 83
 		$this->getDbConnection()->setActive(true);
83 84
 		$sql = "SHOW FULL FIELDS FROM {$find}";
84 85
 		$command = $this->getDbConnection()->createCommand($sql);
@@ -89,10 +90,12 @@  discard block
 block discarded – undo
89 90
 			$col['index'] = $index++;
90 91
 			$this->processColumn($tableInfo,$col);
91 92
 		}
92
-		if($index===0)
93
-			throw new TDbException('dbmetadata_invalid_table_view', $table);
94
-		if($colCase != TDbColumnCaseMode::Preserved)
95
-			$this->getDbConnection()->setColumnCase($colCase);
93
+		if($index===0) {
94
+					throw new TDbException('dbmetadata_invalid_table_view', $table);
95
+		}
96
+		if($colCase != TDbColumnCaseMode::Preserved) {
97
+					$this->getDbConnection()->setColumnCase($colCase);
98
+		}
96 99
 		return $tableInfo;
97 100
 	}
98 101
 
@@ -122,17 +125,22 @@  discard block
 block discarded – undo
122 125
 		$info['ColumnName'] = "`$columnId`"; //quote the column names!
123 126
 		$info['ColumnId'] = $columnId;
124 127
 		$info['ColumnIndex'] = $col['index'];
125
-		if($col['Null']==='YES')
126
-			$info['AllowNull'] = true;
127
-		if(is_int(strpos(strtolower($col['Extra']), 'auto_increment')))
128
-			$info['AutoIncrement']=true;
129
-		if($col['Default']!=="")
130
-			$info['DefaultValue'] = $col['Default'];
128
+		if($col['Null']==='YES') {
129
+					$info['AllowNull'] = true;
130
+		}
131
+		if(is_int(strpos(strtolower($col['Extra']), 'auto_increment'))) {
132
+					$info['AutoIncrement']=true;
133
+		}
134
+		if($col['Default']!=="") {
135
+					$info['DefaultValue'] = $col['Default'];
136
+		}
131 137
 
132
-		if($col['Key']==='PRI' || in_array($columnId, $tableInfo->getPrimaryKeys()))
133
-			$info['IsPrimaryKey'] = true;
134
-		if($this->isForeignKeyColumn($columnId, $tableInfo))
135
-			$info['IsForeignKey'] = true;
138
+		if($col['Key']==='PRI' || in_array($columnId, $tableInfo->getPrimaryKeys())) {
139
+					$info['IsPrimaryKey'] = true;
140
+		}
141
+		if($this->isForeignKeyColumn($columnId, $tableInfo)) {
142
+					$info['IsForeignKey'] = true;
143
+		}
136 144
 
137 145
 		$info['DbType'] = $col['Type'];
138 146
 		$match=array();
@@ -142,8 +150,9 @@  discard block
 block discarded – undo
142 150
 			$info['DbType']= preg_replace('/\(.*\)/', '', $col['Type']);
143 151
 
144 152
 			//find SET/ENUM values
145
-			if($this->isEnumSetType($info['DbType']))
146
-				$info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY);
153
+			if($this->isEnumSetType($info['DbType'])) {
154
+							$info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY);
155
+			}
147 156
 
148 157
 			//find column size, precision and scale
149 158
 			$pscale = array();
@@ -152,11 +161,12 @@  discard block
 block discarded – undo
152 161
 				if($this->isPrecisionType($info['DbType']))
153 162
 				{
154 163
 					$info['NumericPrecision'] = intval($pscale[1]);
155
-					if(count($pscale) > 2)
156
-						$info['NumericScale'] = intval($pscale[2]);
164
+					if(count($pscale) > 2) {
165
+											$info['NumericScale'] = intval($pscale[2]);
166
+					}
167
+				} else {
168
+									$info['ColumnSize'] = intval($pscale[1]);
157 169
 				}
158
-				else
159
-					$info['ColumnSize'] = intval($pscale[1]);
160 170
 			}
161 171
 		}
162 172
 
@@ -223,8 +233,9 @@  discard block
 block discarded – undo
223 233
 		list($schemaName,$tableName) = $this->getSchemaTableName($table);
224 234
 		$info['SchemaName'] = $schemaName;
225 235
 		$info['TableName'] = $tableName;
226
-		if($this->getIsView($schemaName,$tableName))
227
-			$info['IsView'] = true;
236
+		if($this->getIsView($schemaName,$tableName)) {
237
+					$info['IsView'] = true;
238
+		}
228 239
 		list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
229 240
 		$class = $this->getTableInfoClass();
230 241
 		return new $class($info,$primary,$foreign);
@@ -242,20 +253,21 @@  discard block
 block discarded – undo
242 253
 	 */
243 254
 	protected function getIsView($schemaName,$tableName)
244 255
 	{
245
-		if($this->getServerVersion()<5.01)
246
-			return false;
247
-		if($schemaName!==null)
248
-			$sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table";
249
-		else
250
-			$sql = "SHOW FULL TABLES LIKE :table";
256
+		if($this->getServerVersion()<5.01) {
257
+					return false;
258
+		}
259
+		if($schemaName!==null) {
260
+					$sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table";
261
+		} else {
262
+					$sql = "SHOW FULL TABLES LIKE :table";
263
+		}
251 264
 
252 265
 		$command = $this->getDbConnection()->createCommand($sql);
253 266
 		$command->bindValue(':table', $tableName);
254 267
 		try
255 268
 		{
256 269
 			return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW';
257
-		}
258
-		catch(TDbException $e)
270
+		} catch(TDbException $e)
259 271
 		{
260 272
 			$table = $schemaName===null?$tableName:$schemaName.'.'.$tableName;
261 273
 			throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage());
@@ -276,15 +288,17 @@  discard block
 block discarded – undo
276 288
 		$primary = array();
277 289
 		foreach($command->query() as $row)
278 290
 		{
279
-			if($row['Key_name']==='PRIMARY')
280
-				$primary[] = $row['Column_name'];
291
+			if($row['Key_name']==='PRIMARY') {
292
+							$primary[] = $row['Column_name'];
293
+			}
281 294
 		}
282 295
 				// MySQL version was increased to >=5.1.21 instead of 5.x
283 296
 				// due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588)
284
-		if($this->getServerVersion() >= 5.121)
285
-			$foreign = $this->getForeignConstraints($schemaName,$tableName);
286
-		else
287
-			$foreign = $this->findForeignConstraints($schemaName,$tableName);
297
+		if($this->getServerVersion() >= 5.121) {
298
+					$foreign = $this->getForeignConstraints($schemaName,$tableName);
299
+		} else {
300
+					$foreign = $this->findForeignConstraints($schemaName,$tableName);
301
+		}
288 302
 		return array($primary,$foreign);
289 303
 	}
290 304
 
@@ -313,8 +327,9 @@  discard block
 block discarded – undo
313 327
 EOD;
314 328
 		$command = $this->getDbConnection()->createCommand($sql);
315 329
 		$command->bindValue(':table', $tableName);
316
-		if($schemaName!==null)
317
-			$command->bindValue(':schema', $schemaName);
330
+		if($schemaName!==null) {
331
+					$command->bindValue(':schema', $schemaName);
332
+		}
318 333
 		$fkeys=array();
319 334
 		foreach($command->query() as $col)
320 335
 		{
@@ -332,15 +347,17 @@  discard block
 block discarded – undo
332 347
 	 */
333 348
 	protected function getShowCreateTable($schemaName, $tableName)
334 349
 	{
335
-		if(version_compare(PHP_VERSION,'5.1.3','<'))
336
-			throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3');
350
+		if(version_compare(PHP_VERSION,'5.1.3','<')) {
351
+					throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3');
352
+		}
337 353
 
338 354
 		//See http://netevil.org/node.php?nid=795&SC=1
339 355
 		$this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
340
-		if($schemaName!==null)
341
-			$sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`";
342
-		else
343
-			$sql = "SHOW CREATE TABLE `{$tableName}`";
356
+		if($schemaName!==null) {
357
+					$sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`";
358
+		} else {
359
+					$sql = "SHOW CREATE TABLE `{$tableName}`";
360
+		}
344 361
 		$command = $this->getDbConnection()->createCommand($sql);
345 362
 		$result = $command->queryRow();
346 363
 		return isset($result['Create Table']) ? $result['Create Table'] : (isset($result['Create View']) ? $result['Create View'] : '');
@@ -364,8 +381,9 @@  discard block
 block discarded – undo
364 381
 			$fields = array_map('trim',explode(',',str_replace('`','',$match[1])));
365 382
 			$fk_fields = array_map('trim',explode(',',str_replace('`','',$match[3])));
366 383
 			$keys=array();
367
-			foreach($fields as $k=>$v)
368
-				$keys[$v] = $fk_fields[$k];
384
+			foreach($fields as $k=>$v) {
385
+							$keys[$v] = $fk_fields[$k];
386
+			}
369 387
 			$foreign[] = array('keys' => $keys, 'table' => trim($match[2]));
370 388
 		}
371 389
 		return $foreign;
@@ -380,8 +398,9 @@  discard block
 block discarded – undo
380 398
 	{
381 399
 		foreach($tableInfo->getForeignKeys() as $fk)
382 400
 		{
383
-			if(in_array($columnId, array_keys($fk['keys'])))
384
-				return true;
401
+			if(in_array($columnId, array_keys($fk['keys']))) {
402
+							return true;
403
+			}
385 404
 		}
386 405
 		return false;
387 406
 	}
@@ -394,11 +413,13 @@  discard block
 block discarded – undo
394 413
 	 */
395 414
 	public function findTableNames($schema='')
396 415
 	{
397
-		if($schema==='')
398
-			return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn();
416
+		if($schema==='') {
417
+					return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn();
418
+		}
399 419
 		$names=$this->getDbConnection()->createCommand('SHOW TABLES FROM '.$this->quoteTableName($schema))->queryColumn();
400
-		foreach($names as &$name)
401
-			$name=$schema.'.'.$name;
420
+		foreach($names as &$name) {
421
+					$name=$schema.'.'.$name;
422
+		}
402 423
 		return $names;
403 424
 	}
404 425
 }
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -417,12 +417,12 @@
 block discarded – undo
417 417
 		return false;
418 418
 	}
419 419
 
420
-        /**
421
-	 * Returns all table names in the database.
422
-	 * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
423
-	 * If not empty, the returned table names will be prefixed with the schema name.
424
-	 * @return array all table names in the database.
425
-	 */
420
+		/**
421
+		 * Returns all table names in the database.
422
+		 * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
423
+		 * If not empty, the returned table names will be prefixed with the schema name.
424
+		 * @return array all table names in the database.
425
+		 */
426 426
 	public function findTableNames($schema='public')
427 427
 	{
428 428
 		if($schema==='')
Please login to merge, or discard this patch.
framework/Data/Common/Oracle/TOracleMetaData.php 4 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	/**
146 146
 	 * @param string table schema name
147 147
 	 * @param string table name.
148
-	 * @return boolean true if the table is a view.
148
+	 * @return integer true if the table is a view.
149 149
 	 */
150 150
 	protected function getIsView($schemaName,$tableName)
151 151
 	{
@@ -167,6 +167,7 @@  discard block
 block discarded – undo
167 167
 	/**
168 168
 	 * @param TOracleTableInfo table information.
169 169
 	 * @param array column information.
170
+	 * @param TOracleTableInfo $tableInfo
170 171
 	 */
171 172
 	protected function processColumn($tableInfo, $col)
172 173
 	{
@@ -322,6 +323,7 @@  discard block
 block discarded – undo
322 323
 	/**
323 324
 	 * @param string column name.
324 325
 	 * @param TOracleTableInfo table information.
326
+	 * @param string $columnId
325 327
 	 * @return boolean true if column is a foreign key.
326 328
 	 */
327 329
 	protected function isForeignKeyColumn($columnId, $tableInfo)
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function setDefaultSchema($schema)
43 43
 	{
44
-		$this->_defaultSchema=$schema;
44
+		$this->_defaultSchema = $schema;
45 45
 	}
46 46
 
47 47
 	/**
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	protected function getSchemaTableName($table)
60 60
 	{
61
-		if(count($parts= explode('.', str_replace('"','',$table))) > 1)
61
+		if (count($parts = explode('.', str_replace('"', '', $table))) > 1)
62 62
 			return array($parts[0], $parts[1]);
63 63
 		else
64
-			return array($this->getDefaultSchema(),$parts[0]);
64
+			return array($this->getDefaultSchema(), $parts[0]);
65 65
 	}
66 66
 
67 67
 	/**
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 */
72 72
 	protected function createTableInfo($table)
73 73
 	{
74
-		list($schemaName,$tableName) = $this->getSchemaTableName($table);
74
+		list($schemaName, $tableName) = $this->getSchemaTableName($table);
75 75
 
76 76
 		// This query is made much more complex by the addition of the 'attisserial' field.
77 77
 		// The subquery to get that field checks to see if there is an internally dependent
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
 		//$command->bindValue(':table', $tableName);
101 101
 		//$command->bindValue(':schema', $schemaName);
102 102
 		$tableInfo = $this->createNewTableInfo($schemaName, $tableName);
103
-		$index=0;
104
-		foreach($command->query() as $col)
103
+		$index = 0;
104
+		foreach ($command->query() as $col)
105 105
 		{
106 106
 			$col['index'] = $index++;
107 107
 			$this->processColumn($tableInfo, $col);
108 108
 		}
109
-		if($index===0)
109
+		if ($index === 0)
110 110
 			throw new TDbException('dbmetadata_invalid_table_view', $table);
111 111
 		return $tableInfo;
112 112
 	}
@@ -116,15 +116,15 @@  discard block
 block discarded – undo
116 116
 	 * @param string table name.
117 117
 	 * @return TOracleTableInfo
118 118
 	 */
119
-	protected function createNewTableInfo($schemaName,$tableName)
119
+	protected function createNewTableInfo($schemaName, $tableName)
120 120
 	{
121 121
 		$info['SchemaName'] = $this->assertIdentifier($schemaName);
122
-		$info['TableName']	= $this->assertIdentifier($tableName);
123
-		$info['IsView'] 	= false;
124
-		if($this->getIsView($schemaName,$tableName)) $info['IsView'] = true;
122
+		$info['TableName'] = $this->assertIdentifier($tableName);
123
+		$info['IsView'] = false;
124
+		if ($this->getIsView($schemaName, $tableName)) $info['IsView'] = true;
125 125
 		list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
126 126
 		$class = $this->getTableInfoClass();
127
-		return new $class($info,$primary,$foreign);
127
+		return new $class($info, $primary, $foreign);
128 128
 	}
129 129
 
130 130
 	/**
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 */
135 135
 	protected function assertIdentifier($name)
136 136
 	{
137
-		if(strpos($name, '"')!==false)
137
+		if (strpos($name, '"') !== false)
138 138
 		{
139 139
 			$ref = 'http://www.oracle.com';
140 140
 			throw new TDbException('dbcommon_invalid_identifier_name', $name, $ref);
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 * @param string table name.
148 148
 	 * @return boolean true if the table is a view.
149 149
 	 */
150
-	protected function getIsView($schemaName,$tableName)
150
+	protected function getIsView($schemaName, $tableName)
151 151
 	{
152 152
 		$this->getDbConnection()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
153 153
 		$sql =
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
 		$columnId = strtolower($col['attname']); //use column name as column Id
174 174
 
175 175
 		//$info['ColumnName'] 	= '"'.$columnId.'"'; //quote the column names!
176
-		$info['ColumnName'] 	= $columnId; //NOT quote the column names!
177
-		$info['ColumnId'] 		= $columnId;
178
-		$info['ColumnIndex'] 	= $col['index'];
179
-		if(! (bool)$col['attnotnull'] ) $info['AllowNull'] = true;
180
-		if(in_array($columnId, $tableInfo->getPrimaryKeys())) $info['IsPrimaryKey'] = true;
181
-		if($this->isForeignKeyColumn($columnId, $tableInfo)) $info['IsForeignKey'] = true;
182
-		if( (int)$col['atttypmod'] > 0 ) $info['ColumnSize'] =  $col['atttypmod']; // - 4;
183
-		if( (bool)$col['atthasdef'] ) $info['DefaultValue'] = $col['adsrc'];
176
+		$info['ColumnName'] = $columnId; //NOT quote the column names!
177
+		$info['ColumnId'] = $columnId;
178
+		$info['ColumnIndex'] = $col['index'];
179
+		if (!(bool) $col['attnotnull']) $info['AllowNull'] = true;
180
+		if (in_array($columnId, $tableInfo->getPrimaryKeys())) $info['IsPrimaryKey'] = true;
181
+		if ($this->isForeignKeyColumn($columnId, $tableInfo)) $info['IsForeignKey'] = true;
182
+		if ((int) $col['atttypmod'] > 0) $info['ColumnSize'] = $col['atttypmod']; // - 4;
183
+		if ((bool) $col['atthasdef']) $info['DefaultValue'] = $col['adsrc'];
184 184
 		//
185 185
 		// For a while Oracle Tables has no  associated AutoIncrement Triggers
186 186
 		//
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
 		}
196 196
 		*/
197 197
 		$matches = array();
198
-		if(preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches))
198
+		if (preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches))
199 199
 		{
200
-			$info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/','',$col['type']);
201
-			if($this->isPrecisionType($info['DbType']))
200
+			$info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/', '', $col['type']);
201
+			if ($this->isPrecisionType($info['DbType']))
202 202
 			{
203 203
 				$info['NumericPrecision'] = intval($matches[1]);
204
-				if(count($matches) > 2)
204
+				if (count($matches) > 2)
205 205
 					$info['NumericScale'] = intval($matches[2]);
206 206
 			}
207 207
 			else
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
 	/**
216 216
 	 * @return string serial name if found, null otherwise.
217 217
 	 */
218
-	protected function getSequenceName($tableInfo,$src)
218
+	protected function getSequenceName($tableInfo, $src)
219 219
 	{
220 220
 		$matches = array();
221
-		if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches))
221
+		if (preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i', $src, $matches))
222 222
 		{
223
-			if(is_int(strpos($matches[1], '.')))
223
+			if (is_int(strpos($matches[1], '.')))
224 224
 				return $matches[1];
225 225
 			else
226
-				return $tableInfo->getSchemaName().'.'.$matches[1];
226
+				return $tableInfo->getSchemaName() . '.' . $matches[1];
227 227
 		}
228 228
 	}
229 229
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	protected function isPrecisionType($type)
234 234
 	{
235 235
 		$type = strtolower(trim($type));
236
-		return $type==='number'; // || $type==='interval' || strpos($type, 'time')===0;
236
+		return $type === 'number'; // || $type==='interval' || strpos($type, 'time')===0;
237 237
 	}
238 238
 
239 239
 	/**
@@ -262,19 +262,19 @@  discard block
 block discarded – undo
262 262
 		//$command->bindValue(':schema', $schemaName);
263 263
 		$primary = array();
264 264
 		$foreign = array();
265
-		foreach($command->query() as $row)
265
+		foreach ($command->query() as $row)
266 266
 		{
267
-			switch( strtolower( $row['contype'] ) )
267
+			switch (strtolower($row['contype']))
268 268
 			{
269 269
 				case 'p':
270
-					$primary = array_merge( $primary, array(strtolower( $row['consrc'] )) );
270
+					$primary = array_merge($primary, array(strtolower($row['consrc'])));
271 271
 					/*
272 272
 					$arr = $this->getPrimaryKeys($row['consrc']);
273 273
 					$primary = array_merge( $primary, array(strtolower( $arr[0] )) );
274 274
 					*/
275 275
 					break;
276 276
 				case 'r':
277
-					$foreign = array_merge( $foreign, array(strtolower( $row['consrc'] )) );
277
+					$foreign = array_merge($foreign, array(strtolower($row['consrc'])));
278 278
 					/*
279 279
 					// if(($fkey = $this->getForeignKeys($row['consrc']))!==null)
280 280
 					$fkey = $this->getForeignKeys( $row['consrc'] );
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 					break;
284 284
 			}
285 285
 		}
286
-		return array($primary,$foreign);
286
+		return array($primary, $foreign);
287 287
 	}
288 288
 
289 289
 	/**
@@ -294,8 +294,8 @@  discard block
 block discarded – undo
294 294
 	protected function getPrimaryKeys($src)
295 295
 	{
296 296
 		$matches = array();
297
-		if(preg_match('/PRIMARY\s+KEY\s+\(([^\)]+)\)/i', $src, $matches))
298
-			return preg_split('/,\s+/',$matches[1]);
297
+		if (preg_match('/PRIMARY\s+KEY\s+\(([^\)]+)\)/i', $src, $matches))
298
+			return preg_split('/,\s+/', $matches[1]);
299 299
 		return array();
300 300
 	}
301 301
 
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
 		$matches = array();
310 310
 		$brackets = '\(([^\)]+)\)';
311 311
 		$find = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i";
312
-		if(preg_match($find, $src, $matches))
312
+		if (preg_match($find, $src, $matches))
313 313
 		{
314 314
 			$keys = preg_split('/,\s+/', $matches[1]);
315 315
 			$fkeys = array();
316
-			foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey)
316
+			foreach (preg_split('/,\s+/', $matches[3]) as $i => $fkey)
317 317
 				$fkeys[$keys[$i]] = $fkey;
318
-			return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys);
318
+			return array('table' => str_replace('"', '', $matches[2]), 'keys' => $fkeys);
319 319
 		}
320 320
 	}
321 321
 
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
 	 */
327 327
 	protected function isForeignKeyColumn($columnId, $tableInfo)
328 328
 	{
329
-		foreach($tableInfo->getForeignKeys() as $fk)
329
+		foreach ($tableInfo->getForeignKeys() as $fk)
330 330
 		{
331
-			if( $fk==$columnId )
331
+			if ($fk == $columnId)
332 332
 			//if(in_array($columnId, array_keys($fk['keys'])))
333 333
 				return true;
334 334
 		}
@@ -341,33 +341,33 @@  discard block
 block discarded – undo
341 341
 	 * If not empty, the returned table names will be prefixed with the schema name.
342 342
 	 * @return array all table names in the database.
343 343
 	 */
344
-	public function findTableNames($schema='')
344
+	public function findTableNames($schema = '')
345 345
 	{
346
-		if($schema==='')
346
+		if ($schema === '')
347 347
 		{
348
-			$sql=<<<EOD
348
+			$sql = <<<EOD
349 349
 SELECT table_name, '{$schema}' as table_schema FROM user_tables
350 350
 EOD;
351
-			$command=$this->getDbConnection()->createCommand($sql);
351
+			$command = $this->getDbConnection()->createCommand($sql);
352 352
 		}
353 353
 		else
354 354
 		{
355
-			$sql=<<<EOD
355
+			$sql = <<<EOD
356 356
 SELECT object_name as table_name, owner as table_schema FROM all_objects
357 357
 WHERE object_type = 'TABLE' AND owner=:schema
358 358
 EOD;
359
-			$command=$this->getDbConnection()->createCommand($sql);
360
-			$command->bindParam(':schema',$schema);
359
+			$command = $this->getDbConnection()->createCommand($sql);
360
+			$command->bindParam(':schema', $schema);
361 361
 		}
362 362
 
363
-		$rows=$command->queryAll();
364
-		$names=array();
365
-		foreach($rows as $row)
363
+		$rows = $command->queryAll();
364
+		$names = array();
365
+		foreach ($rows as $row)
366 366
 		{
367
-			if($schema===$this->getDefaultSchema() || $schema==='')
368
-				$names[]=$row['TABLE_NAME'];
367
+			if ($schema === $this->getDefaultSchema() || $schema === '')
368
+				$names[] = $row['TABLE_NAME'];
369 369
 			else
370
-				$names[]=$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME'];
370
+				$names[] = $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME'];
371 371
 		}
372 372
 		return $names;
373 373
 	}
Please login to merge, or discard this patch.
Braces   +54 added lines, -34 removed lines patch added patch discarded remove patch
@@ -58,10 +58,11 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	protected function getSchemaTableName($table)
60 60
 	{
61
-		if(count($parts= explode('.', str_replace('"','',$table))) > 1)
62
-			return array($parts[0], $parts[1]);
63
-		else
64
-			return array($this->getDefaultSchema(),$parts[0]);
61
+		if(count($parts= explode('.', str_replace('"','',$table))) > 1) {
62
+					return array($parts[0], $parts[1]);
63
+		} else {
64
+					return array($this->getDefaultSchema(),$parts[0]);
65
+		}
65 66
 	}
66 67
 
67 68
 	/**
@@ -106,8 +107,9 @@  discard block
 block discarded – undo
106 107
 			$col['index'] = $index++;
107 108
 			$this->processColumn($tableInfo, $col);
108 109
 		}
109
-		if($index===0)
110
-			throw new TDbException('dbmetadata_invalid_table_view', $table);
110
+		if($index===0) {
111
+					throw new TDbException('dbmetadata_invalid_table_view', $table);
112
+		}
111 113
 		return $tableInfo;
112 114
 	}
113 115
 
@@ -121,7 +123,9 @@  discard block
 block discarded – undo
121 123
 		$info['SchemaName'] = $this->assertIdentifier($schemaName);
122 124
 		$info['TableName']	= $this->assertIdentifier($tableName);
123 125
 		$info['IsView'] 	= false;
124
-		if($this->getIsView($schemaName,$tableName)) $info['IsView'] = true;
126
+		if($this->getIsView($schemaName,$tableName)) {
127
+			$info['IsView'] = true;
128
+		}
125 129
 		list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
126 130
 		$class = $this->getTableInfoClass();
127 131
 		return new $class($info,$primary,$foreign);
@@ -176,11 +180,22 @@  discard block
 block discarded – undo
176 180
 		$info['ColumnName'] 	= $columnId; //NOT quote the column names!
177 181
 		$info['ColumnId'] 		= $columnId;
178 182
 		$info['ColumnIndex'] 	= $col['index'];
179
-		if(! (bool)$col['attnotnull'] ) $info['AllowNull'] = true;
180
-		if(in_array($columnId, $tableInfo->getPrimaryKeys())) $info['IsPrimaryKey'] = true;
181
-		if($this->isForeignKeyColumn($columnId, $tableInfo)) $info['IsForeignKey'] = true;
182
-		if( (int)$col['atttypmod'] > 0 ) $info['ColumnSize'] =  $col['atttypmod']; // - 4;
183
-		if( (bool)$col['atthasdef'] ) $info['DefaultValue'] = $col['adsrc'];
183
+		if(! (bool)$col['attnotnull'] ) {
184
+			$info['AllowNull'] = true;
185
+		}
186
+		if(in_array($columnId, $tableInfo->getPrimaryKeys())) {
187
+			$info['IsPrimaryKey'] = true;
188
+		}
189
+		if($this->isForeignKeyColumn($columnId, $tableInfo)) {
190
+			$info['IsForeignKey'] = true;
191
+		}
192
+		if( (int)$col['atttypmod'] > 0 ) {
193
+			$info['ColumnSize'] =  $col['atttypmod'];
194
+		}
195
+		// - 4;
196
+		if( (bool)$col['atthasdef'] ) {
197
+			$info['DefaultValue'] = $col['adsrc'];
198
+		}
184 199
 		//
185 200
 		// For a while Oracle Tables has no  associated AutoIncrement Triggers
186 201
 		//
@@ -201,14 +216,15 @@  discard block
 block discarded – undo
201 216
 			if($this->isPrecisionType($info['DbType']))
202 217
 			{
203 218
 				$info['NumericPrecision'] = intval($matches[1]);
204
-				if(count($matches) > 2)
205
-					$info['NumericScale'] = intval($matches[2]);
219
+				if(count($matches) > 2) {
220
+									$info['NumericScale'] = intval($matches[2]);
221
+				}
222
+			} else {
223
+							$info['ColumnSize'] = intval($matches[1]);
206 224
 			}
207
-			else
208
-				$info['ColumnSize'] = intval($matches[1]);
225
+		} else {
226
+					$info['DbType'] = $col['type'];
209 227
 		}
210
-		else
211
-			$info['DbType'] = $col['type'];
212 228
 		$tableInfo->Columns[$columnId] = new TOracleTableColumn($info);
213 229
 	}
214 230
 
@@ -220,10 +236,11 @@  discard block
 block discarded – undo
220 236
 		$matches = array();
221 237
 		if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches))
222 238
 		{
223
-			if(is_int(strpos($matches[1], '.')))
224
-				return $matches[1];
225
-			else
226
-				return $tableInfo->getSchemaName().'.'.$matches[1];
239
+			if(is_int(strpos($matches[1], '.'))) {
240
+							return $matches[1];
241
+			} else {
242
+							return $tableInfo->getSchemaName().'.'.$matches[1];
243
+			}
227 244
 		}
228 245
 	}
229 246
 
@@ -294,8 +311,9 @@  discard block
 block discarded – undo
294 311
 	protected function getPrimaryKeys($src)
295 312
 	{
296 313
 		$matches = array();
297
-		if(preg_match('/PRIMARY\s+KEY\s+\(([^\)]+)\)/i', $src, $matches))
298
-			return preg_split('/,\s+/',$matches[1]);
314
+		if(preg_match('/PRIMARY\s+KEY\s+\(([^\)]+)\)/i', $src, $matches)) {
315
+					return preg_split('/,\s+/',$matches[1]);
316
+		}
299 317
 		return array();
300 318
 	}
301 319
 
@@ -313,8 +331,9 @@  discard block
 block discarded – undo
313 331
 		{
314 332
 			$keys = preg_split('/,\s+/', $matches[1]);
315 333
 			$fkeys = array();
316
-			foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey)
317
-				$fkeys[$keys[$i]] = $fkey;
334
+			foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) {
335
+							$fkeys[$keys[$i]] = $fkey;
336
+			}
318 337
 			return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys);
319 338
 		}
320 339
 	}
@@ -328,9 +347,10 @@  discard block
 block discarded – undo
328 347
 	{
329 348
 		foreach($tableInfo->getForeignKeys() as $fk)
330 349
 		{
331
-			if( $fk==$columnId )
332
-			//if(in_array($columnId, array_keys($fk['keys'])))
350
+			if( $fk==$columnId ) {
351
+						//if(in_array($columnId, array_keys($fk['keys'])))
333 352
 				return true;
353
+			}
334 354
 		}
335 355
 		return false;
336 356
 	}
@@ -349,8 +369,7 @@  discard block
 block discarded – undo
349 369
 SELECT table_name, '{$schema}' as table_schema FROM user_tables
350 370
 EOD;
351 371
 			$command=$this->getDbConnection()->createCommand($sql);
352
-		}
353
-		else
372
+		} else
354 373
 		{
355 374
 			$sql=<<<EOD
356 375
 SELECT object_name as table_name, owner as table_schema FROM all_objects
@@ -364,10 +383,11 @@  discard block
 block discarded – undo
364 383
 		$names=array();
365 384
 		foreach($rows as $row)
366 385
 		{
367
-			if($schema===$this->getDefaultSchema() || $schema==='')
368
-				$names[]=$row['TABLE_NAME'];
369
-			else
370
-				$names[]=$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME'];
386
+			if($schema===$this->getDefaultSchema() || $schema==='') {
387
+							$names[]=$row['TABLE_NAME'];
388
+			} else {
389
+							$names[]=$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME'];
390
+			}
371 391
 		}
372 392
 		return $names;
373 393
 	}
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -417,12 +417,12 @@
 block discarded – undo
417 417
 		return false;
418 418
 	}
419 419
 
420
-        /**
421
-	 * Returns all table names in the database.
422
-	 * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
423
-	 * If not empty, the returned table names will be prefixed with the schema name.
424
-	 * @return array all table names in the database.
425
-	 */
420
+		/**
421
+		 * Returns all table names in the database.
422
+		 * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
423
+		 * If not empty, the returned table names will be prefixed with the schema name.
424
+		 * @return array all table names in the database.
425
+		 */
426 426
 	public function findTableNames($schema='public')
427 427
 	{
428 428
 		if($schema==='')
Please login to merge, or discard this patch.
framework/Data/Common/Oracle/TOracleTableInfo.php 3 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -53,6 +53,8 @@
 block discarded – undo
53 53
 	/**
54 54
 	 * @param string information array key name
55 55
 	 * @param mixed default value if information array value is null
56
+	 * @param string $name
57
+	 * @param boolean $default
56 58
 	 * @return mixed information array value.
57 59
 	 */
58 60
 	public function getInfo($name,$default=null)
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class TOracleTableInfo extends TComponent
21 21
 {
22
-	private $_info=array();
22
+	private $_info = array();
23 23
 
24 24
 	private $_primaryKeys;
25 25
 	private $_foreignKeys;
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
 	 * Sets the database table meta data information.
33 33
 	 * @param array table column information.
34 34
 	 */
35
-	public function __construct($tableInfo=array(),$primary=array(),$foreign=array())
35
+	public function __construct($tableInfo = array(), $primary = array(), $foreign = array())
36 36
 	{
37
-		$this->_info=$tableInfo;
38
-		$this->_primaryKeys=$primary;
39
-		$this->_foreignKeys=$foreign;
40
-		$this->_columns=new TMap;
37
+		$this->_info = $tableInfo;
38
+		$this->_primaryKeys = $primary;
39
+		$this->_foreignKeys = $foreign;
40
+		$this->_columns = new TMap;
41 41
 	}
42 42
 
43 43
 	/**
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	public function createCommandBuilder($connection)
48 48
 	{
49 49
 		Prado::using('System.Data.Common.Oracle.TOracleCommandBuilder');
50
-		return new TOracleCommandBuilder($connection,$this);
50
+		return new TOracleCommandBuilder($connection, $this);
51 51
 	}
52 52
 
53 53
 	/**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 * @param mixed default value if information array value is null
56 56
 	 * @return mixed information array value.
57 57
 	 */
58
-	public function getInfo($name,$default=null)
58
+	public function getInfo($name, $default = null)
59 59
 	{
60 60
 		return isset($this->_info[$name]) ? $this->_info[$name] : $default;
61 61
 	}
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 * @param string information array key name
65 65
 	 * @param mixed new information array value.
66 66
 	 */
67
-	protected function setInfo($name,$value)
67
+	protected function setInfo($name, $value)
68 68
 	{
69
-		$this->_info[$name]=$value;
69
+		$this->_info[$name] = $value;
70 70
 	}
71 71
 
72 72
 	/**
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	public function getTableFullName()
84 84
 	{
85
-		return $this->_info['SchemaName'].'.'.$this->getTableName();
85
+		return $this->_info['SchemaName'] . '.' . $this->getTableName();
86 86
 	}
87 87
 
88 88
 	/**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function getIsView()
92 92
 	{
93
-		return $this->getInfo('IsView',false);
93
+		return $this->getInfo('IsView', false);
94 94
 	}
95 95
 
96 96
 	/**
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	public function getColumn($name)
109 109
 	{
110
-		if(($column = $this->_columns->itemAt($name))!==null)
110
+		if (($column = $this->_columns->itemAt($name)) !== null)
111 111
 			return $column;
112 112
 		throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName());
113 113
 	}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function getColumnNames()
120 120
 	{
121
-		foreach($this->getColumns() as $column)
121
+		foreach ($this->getColumns() as $column)
122 122
 			$names[] = $column->getColumnName();
123 123
 		return $names;
124 124
 	}
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function getLowerCaseColumnNames()
146 146
 	{
147
-		if($this->_lowercase===null)
147
+		if ($this->_lowercase === null)
148 148
 		{
149
-			$this->_lowercase=array();
150
-			foreach($this->getColumns()->getKeys() as $key)
149
+			$this->_lowercase = array();
150
+			foreach ($this->getColumns()->getKeys() as $key)
151 151
 				$this->_lowercase[strtolower($key)] = $key;
152 152
 		}
153 153
 		return $this->_lowercase;
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -107,8 +107,9 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	public function getColumn($name)
109 109
 	{
110
-		if(($column = $this->_columns->itemAt($name))!==null)
111
-			return $column;
110
+		if(($column = $this->_columns->itemAt($name))!==null) {
111
+					return $column;
112
+		}
112 113
 		throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName());
113 114
 	}
114 115
 
@@ -118,8 +119,9 @@  discard block
 block discarded – undo
118 119
 	 */
119 120
 	public function getColumnNames()
120 121
 	{
121
-		foreach($this->getColumns() as $column)
122
-			$names[] = $column->getColumnName();
122
+		foreach($this->getColumns() as $column) {
123
+					$names[] = $column->getColumnName();
124
+		}
123 125
 		return $names;
124 126
 	}
125 127
 
@@ -147,8 +149,9 @@  discard block
 block discarded – undo
147 149
 		if($this->_lowercase===null)
148 150
 		{
149 151
 			$this->_lowercase=array();
150
-			foreach($this->getColumns()->getKeys() as $key)
151
-				$this->_lowercase[strtolower($key)] = $key;
152
+			foreach($this->getColumns()->getKeys() as $key) {
153
+							$this->_lowercase[strtolower($key)] = $key;
154
+			}
152 155
 		}
153 156
 		return $this->_lowercase;
154 157
 	}
Please login to merge, or discard this patch.