Completed
Push — 3.2 ( 7b06ed...40a0aa )
by David
09:20
created
src/Mouf/Database/TDBM/Filters/GreaterFilter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@
 block discarded – undo
85 85
 	 * @param string $columnName
86 86
 	 * @param string $value
87 87
 	 */
88
-	public function __construct($tableName=null, $columnName=null, $value=null) {
88
+	public function __construct($tableName = null, $columnName = null, $value = null) {
89 89
 		$this->tableName = $tableName;
90 90
 		$this->columnName = $columnName;
91 91
 		$this->value = $value;
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Filters/GreaterOrEqualFilter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@
 block discarded – undo
85 85
 	 * @param string $columnName
86 86
 	 * @param string $value
87 87
 	 */
88
-	public function __construct($tableName=null, $columnName=null, $value=null) {
88
+	public function __construct($tableName = null, $columnName = null, $value = null) {
89 89
 		$this->tableName = $tableName;
90 90
 		$this->columnName = $columnName;
91 91
 		$this->value = $value;
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Filters/LessFilter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@
 block discarded – undo
85 85
 	 * @param string $columnName
86 86
 	 * @param string $value
87 87
 	 */
88
-	public function __construct($tableName=null, $columnName=null, $value=null) {
88
+	public function __construct($tableName = null, $columnName = null, $value = null) {
89 89
 		$this->tableName = $tableName;
90 90
 		$this->columnName = $columnName;
91 91
 		$this->value = $value;
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Filters/LessOrEqualFilter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@
 block discarded – undo
85 85
 	 * @param string $columnName
86 86
 	 * @param string $value
87 87
 	 */
88
-	public function __construct($tableName=null, $columnName=null, $value=null) {
88
+	public function __construct($tableName = null, $columnName = null, $value = null) {
89 89
 		$this->tableName = $tableName;
90 90
 		$this->columnName = $columnName;
91 91
 		$this->value = $value;
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Filters/LikeFilter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@
 block discarded – undo
85 85
 	 * @param string $columnName
86 86
 	 * @param string $value
87 87
 	 */
88
-	public function __construct($tableName=null, $columnName=null, $value=null) {
88
+	public function __construct($tableName = null, $columnName = null, $value = null) {
89 89
 		$this->tableName = $tableName;
90 90
 		$this->columnName = $columnName;
91 91
 		$this->value = $value;
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Filters/OrderBySQLString.php 3 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,8 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Mouf\Database\TDBM\Filters;
3 3
 
4
-use Mouf\Database\DBConnection\ConnectionInterface;
5
-
6 4
 /*
7 5
  Copyright (C) 2006-2011 David Négrier - THE CODING MACHINE
8 6
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * 
61 61
 	 * @param string $sqlString
62 62
 	 */
63
-	public function __construct($sqlString=null) {
63
+	public function __construct($sqlString = null) {
64 64
 		$this->sqlString = $sqlString;
65 65
 	}
66 66
 	
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 			$result = -1;
89 89
 			while (true) {
90 90
 				$result = strrpos($phrase, "'", $result+1);
91
-				if ($result===false) {
92
-					if ($sentence!='')
91
+				if ($result === false) {
92
+					if ($sentence != '')
93 93
 					$sentence .= ',';
94 94
 					$sentence .= $phrase;
95 95
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 				{
106 106
 					$valid_result = true;
107 107
 					//echo '-'.$phrase{$result-1}.'-';
108
-					if ($result>0 && $phrase{$result-1}=='\\') {
108
+					if ($result>0 && $phrase{$result-1} == '\\') {
109 109
 						$valid_result = false;
110 110
 					}
111 111
 					if ($valid_result)
@@ -133,33 +133,33 @@  discard block
 block discarded – undo
133 133
 		// First, let's remove all the stuff in quotes:
134 134
 
135 135
 		// Let's remove all the \' found
136
-		$work_str = str_replace("\\'",'',$this->sqlString);
136
+		$work_str = str_replace("\\'", '', $this->sqlString);
137 137
 		// Now, let's split the string using '
138 138
 		$work_table = explode("'", $work_str);
139 139
 
140
-		if (count($work_table)==0)
140
+		if (count($work_table) == 0)
141 141
 		return '';
142 142
 
143 143
 		// if we start with a ', let's remove the first text
144
-		if (strstr($work_str,"'")===0)
144
+		if (strstr($work_str, "'") === 0)
145 145
 		array_shift($work_table);
146 146
 			
147
-		if (count($work_table)==0)
147
+		if (count($work_table) == 0)
148 148
 		return '';
149 149
 
150 150
 		// Now, let's take only the stuff outside the quotes.
151 151
 		$work_str2 = '';
152 152
 
153
-		$i=0;
153
+		$i = 0;
154 154
 		foreach ($work_table as $str_fragment) {
155
-			if (($i % 2) == 0)
155
+			if (($i%2) == 0)
156 156
 			$work_str2 .= $str_fragment.' ';
157 157
 			$i++;
158 158
 		}
159 159
 
160 160
 		// Now, let's run a regexp to find all the strings matching the pattern xxx.yyy
161 161
 		//preg_match_all('/(\w+)\.(?:\w+)/', $work_str2,$capture_result);
162
-		preg_match_all('/([a-zA-Z_](?:[a-zA-Z0-9_]*))\.(?:[a-zA-Z_](?:[a-zA-Z0-9_]*))/', $work_str2,$capture_result);
162
+		preg_match_all('/([a-zA-Z_](?:[a-zA-Z0-9_]*))\.(?:[a-zA-Z_](?:[a-zA-Z0-9_]*))/', $work_str2, $capture_result);
163 163
 
164 164
 		$tables_used = $capture_result[1];
165 165
 		// remove doubles:
Please login to merge, or discard this patch.
Braces   +19 added lines, -14 removed lines patch added patch discarded remove patch
@@ -89,8 +89,9 @@  discard block
 block discarded – undo
89 89
 			while (true) {
90 90
 				$result = strrpos($phrase, "'", $result+1);
91 91
 				if ($result===false) {
92
-					if ($sentence!='')
93
-					$sentence .= ',';
92
+					if ($sentence!='') {
93
+										$sentence .= ',';
94
+					}
94 95
 					$sentence .= $phrase;
95 96
 
96 97
 					if ($is_inside_quotes) {
@@ -100,16 +101,16 @@  discard block
 block discarded – undo
100 101
 						$sentence = '';
101 102
 						break;
102 103
 					}
103
-				}
104
-				else
104
+				} else
105 105
 				{
106 106
 					$valid_result = true;
107 107
 					//echo '-'.$phrase{$result-1}.'-';
108 108
 					if ($result>0 && $phrase{$result-1}=='\\') {
109 109
 						$valid_result = false;
110 110
 					}
111
-					if ($valid_result)
112
-					$is_inside_quotes = !$is_inside_quotes;
111
+					if ($valid_result) {
112
+										$is_inside_quotes = !$is_inside_quotes;
113
+					}
113 114
 				}
114 115
 			}
115 116
 
@@ -137,23 +138,27 @@  discard block
 block discarded – undo
137 138
 		// Now, let's split the string using '
138 139
 		$work_table = explode("'", $work_str);
139 140
 
140
-		if (count($work_table)==0)
141
-		return '';
141
+		if (count($work_table)==0) {
142
+				return '';
143
+		}
142 144
 
143 145
 		// if we start with a ', let's remove the first text
144
-		if (strstr($work_str,"'")===0)
145
-		array_shift($work_table);
146
+		if (strstr($work_str,"'")===0) {
147
+				array_shift($work_table);
148
+		}
146 149
 			
147
-		if (count($work_table)==0)
148
-		return '';
150
+		if (count($work_table)==0) {
151
+				return '';
152
+		}
149 153
 
150 154
 		// Now, let's take only the stuff outside the quotes.
151 155
 		$work_str2 = '';
152 156
 
153 157
 		$i=0;
154 158
 		foreach ($work_table as $str_fragment) {
155
-			if (($i % 2) == 0)
156
-			$work_str2 .= $str_fragment.' ';
159
+			if (($i % 2) == 0) {
160
+						$work_str2 .= $str_fragment.' ';
161
+			}
157 162
 			$i++;
158 163
 		}
159 164
 
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/DisplayNode.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 	public static $box_height = 30;
34 34
 	public static $interspace_width = 10;
35 35
 	public static $interspace_height = 50;
36
-	public static $text_height=13;
37
-	public static $border =2;
36
+	public static $text_height = 13;
37
+	public static $border = 2;
38 38
 
39 39
 
40 40
 	private $parent_node;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
 	public $width;
48 48
 
49
-	public function __construct($table_name, $parent_node=null, $link_type=null, $keyParent=null, $keyNode=null) {
49
+	public function __construct($table_name, $parent_node = null, $link_type = null, $keyParent = null, $keyNode = null) {
50 50
 		$this->table_name = $table_name;
51 51
 		if ($parent_node !== null) {
52 52
 			$this->parent_node = $parent_node;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	}
84 84
 
85 85
 	public function computeWidth() {
86
-		if (!is_array($this->children) || count($this->children)==0) {
86
+		if (!is_array($this->children) || count($this->children) == 0) {
87 87
 			$this->width = 1;
88 88
 			return 1;
89 89
 		} else {
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 
99 99
 	public function computeDepth($my_depth) {
100
-		if (!is_array($this->children) || count($this->children)==0) {
100
+		if (!is_array($this->children) || count($this->children) == 0) {
101 101
 			return $my_depth+1;
102 102
 		} else {
103 103
 			$max = 0;
104 104
 			foreach ($this->children as $child) {
105
-				$depth = $my_depth + $child->computeDepth($my_depth);
106
-				if ($depth > $max) {
105
+				$depth = $my_depth+$child->computeDepth($my_depth);
106
+				if ($depth>$max) {
107 107
 					$max = $depth;
108 108
 				}
109 109
 			}
@@ -113,23 +113,23 @@  discard block
 block discarded – undo
113 113
 
114 114
 	public function draw($x, $y, $left_px, $top_px) {
115 115
 
116
-		$mybox_width_px = $this->width*DisplayNode::$box_width + ($this->width-1)*DisplayNode::$interspace_width;
117
-		$my_x_px = $left_px + DisplayNode::$left_start + $x*(DisplayNode::$box_width + DisplayNode::$interspace_width);
118
-		$my_y_px = $top_px + DisplayNode::$top_start + $y*(DisplayNode::$box_height + DisplayNode::$interspace_height);
116
+		$mybox_width_px = $this->width*DisplayNode::$box_width+($this->width-1)*DisplayNode::$interspace_width;
117
+		$my_x_px = $left_px+DisplayNode::$left_start+$x*(DisplayNode::$box_width+DisplayNode::$interspace_width);
118
+		$my_y_px = $top_px+DisplayNode::$top_start+$y*(DisplayNode::$box_height+DisplayNode::$interspace_height);
119 119
 
120 120
 		// White background first
121 121
 		$str = "<div style='position:absolute; left:".$my_x_px."px; top:".$my_y_px."px; width:".$mybox_width_px."px; height:".DisplayNode::$box_height."; background-color:gray; color: white; text-align:center; border:".DisplayNode::$border."px solid black'>\n<b>".$this->table_name."</b></div>";
122 122
 
123 123
 		if ($this->keyParent != null) {
124
-			$my_x_px_line = $my_x_px + DisplayNode::$box_width/2;
125
-			$my_y_px_line = $my_y_px - DisplayNode::$interspace_height;
124
+			$my_x_px_line = $my_x_px+DisplayNode::$box_width/2;
125
+			$my_y_px_line = $my_y_px-DisplayNode::$interspace_height;
126 126
 			$str .= "<div style='position:absolute; left:".$my_x_px_line."px; top:".($my_y_px_line+DisplayNode::$border)."px; width:2px; height:".(DisplayNode::$interspace_height-DisplayNode::$border)."; background-color:black; '></div>\n";
127 127
 
128
-			$top_key = ($this->link_type=='1*')?'* fk:':'1 pk:';
128
+			$top_key = ($this->link_type == '1*') ? '* fk:' : '1 pk:';
129 129
 			$top_key .= '<i>'.$this->keyParent.'</i>';
130 130
 
131 131
 
132
-			$bottom_key = ($this->link_type=='*1')?'* fk:':'1 pk:';
132
+			$bottom_key = ($this->link_type == '*1') ? '* fk:' : '1 pk:';
133 133
 			$bottom_key .= '<i>'.$this->keyParent.'</i>';
134 134
 
135 135
 			$str .= "<div style='position:absolute; left:".($my_x_px_line+2)."px; top:".($my_y_px_line+DisplayNode::$border*2)."px; background-color:#EEEEEE; font-size: 10px'>$top_key</div>\n";
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,8 +67,7 @@
 block discarded – undo
67 67
 			if ($this->link_type == "*1")
68 68
 			{
69 69
 				echo "Table $this->table_name points to table ".$this->parent_node->table_name." through its foreign key on column $this->keyNode that points to column $this->keyParent<br />";
70
-			}
71
-			else if ($this->link_type == "1*")
70
+			} else if ($this->link_type == "1*")
72 71
 			{
73 72
 				echo "Table $this->table_name is pointed by table ".$this->parent_node->table_name." by its foreign key on column $this->keyParent that points to column $this->keyNode<br />";
74 73
 			}
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/TDBMObject.php 4 patches
Braces   +30 added lines, -23 removed lines patch added patch discarded remove patch
@@ -263,10 +263,11 @@  discard block
 block discarded – undo
263 263
 				// Let's try to be accurate in error reporting. The checkColumnExist returns an array of closest matches.
264 264
 				$result_array = $column_exist;
265 265
 				
266
-				if (count($result_array)==1)
267
-				$str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'";
268
-				else
269
-				$str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'";
266
+				if (count($result_array)==1) {
267
+								$str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'";
268
+				} else {
269
+								$str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'";
270
+				}
270 271
 	
271 272
 	
272 273
 				throw new TDBMException($str);
@@ -348,10 +349,11 @@  discard block
 block discarded – undo
348 349
 			if (count($pk_array)>1 && !$pk_set) {
349 350
 				$msg = "Error! You did not set the primary keys for the new object of type '$this->db_table_name'. TDBM usually assumes that the primary key is automatically set by the DB engine to the maximum value in the database. However, in this case, the '$this->db_table_name' table has a primary key on multiple columns. TDBM would be unable to find back this record after save. Please specify the primary keys for all new objects of kind '$this->db_table_name'.";
350 351
 
351
-				if (!$this->tdbmService->isProgramExiting())
352
-				throw new TDBMException($msg);
353
-				else
354
-				trigger_error($msg, E_USER_ERROR);
352
+				if (!$this->tdbmService->isProgramExiting()) {
353
+								throw new TDBMException($msg);
354
+				} else {
355
+								trigger_error($msg, E_USER_ERROR);
356
+				}
355 357
 			}
356 358
 			
357 359
 			$sql = 'INSERT INTO '.$this->db_connection->escapeDBItem($this->db_table_name).
@@ -360,8 +362,9 @@  discard block
 block discarded – undo
360 362
 
361 363
 			$first = true;
362 364
 			foreach ($this->db_row as $key=>$value) {
363
-				if (!$first)
364
-				$sql .= ',';
365
+				if (!$first) {
366
+								$sql .= ',';
367
+				}
365 368
 				$sql .= $this->db_connection->quoteSmart($value);
366 369
 				$first=false;
367 370
 			}
@@ -378,9 +381,9 @@  discard block
 block discarded – undo
378 381
 				//	trigger_error("program exiting");
379 382
 				trigger_error($e->getMessage(), E_USER_ERROR);
380 383
 
381
-				if (!$this->tdbmService->isProgramExiting())
382
-				throw $e;
383
-				else
384
+				if (!$this->tdbmService->isProgramExiting()) {
385
+								throw $e;
386
+				} else
384 387
 				{
385 388
 					trigger_error($e->getMessage(), E_USER_ERROR);
386 389
 				}
@@ -447,8 +450,9 @@  discard block
 block discarded – undo
447 450
 
448 451
 			$first = true;
449 452
 			foreach ($this->db_row as $key=>$value) {
450
-				if (!$first)
451
-				$sql .= ',';
453
+				if (!$first) {
454
+								$sql .= ',';
455
+				}
452 456
 				$sql .= $this->db_connection->escapeDBItem($key)." = ".$this->db_connection->quoteSmart($value);
453 457
 				$first=false;
454 458
 			}
@@ -456,10 +460,11 @@  discard block
 block discarded – undo
456 460
 			try {
457 461
 				$this->db_connection->exec($sql);
458 462
 			} catch (TDBMException $e) {
459
-				if (!$this->tdbmService->isProgramExiting())
460
-				throw $e;
461
-				else
462
-				trigger_error($e->getMessage(), E_USER_ERROR);
463
+				if (!$this->tdbmService->isProgramExiting()) {
464
+								throw $e;
465
+				} else {
466
+								trigger_error($e->getMessage(), E_USER_ERROR);
467
+				}
463 468
 			}
464 469
 
465 470
 			// Let's remove this object from the $new_objects static table.
@@ -490,11 +495,13 @@  discard block
 block discarded – undo
490 495
 	 *
491 496
 	 */
492 497
 	public function discardChanges() {
493
-		if ($this->TDBMObject_state == "new")
494
-		throw new TDBMException("You cannot call discardChanges() on an object that has been created with getNewObject and that has not yet been saved.");
498
+		if ($this->TDBMObject_state == "new") {
499
+				throw new TDBMException("You cannot call discardChanges() on an object that has been created with getNewObject and that has not yet been saved.");
500
+		}
495 501
 
496
-		if ($this->TDBMObject_state == "deleted")
497
-		throw new TDBMException("You cannot call discardChanges() on an object that has been deleted.");
502
+		if ($this->TDBMObject_state == "deleted") {
503
+				throw new TDBMException("You cannot call discardChanges() on an object that has been deleted.");
504
+		}
498 505
 			
499 506
 		$this->db_modified_state = false;
500 507
 		$this->TDBMObject_state = "not loaded";
Please login to merge, or discard this patch.
Doc Comments   +9 added lines, -2 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * false if an explicit call to save() is required.
146 146
 	 *
147 147
 	 * @param unknown_type $autoSave
148
-	 * @return boolean
148
+	 * @return boolean|null
149 149
 	 */
150 150
 	public function setAutoSaveMode($autoSave) {
151 151
 		$this->db_autosave = $autoSave;
@@ -255,6 +255,9 @@  discard block
 block discarded – undo
255 255
 		}
256 256
 	}
257 257
 
258
+	/**
259
+	 * @param string $var
260
+	 */
258 261
 	public function __get($var) {
259 262
 		$this->_dbLoadIfNotLoaded();
260 263
 
@@ -307,6 +310,10 @@  discard block
 block discarded – undo
307 310
 		return isset($this->db_row[$var]);
308 311
 	}
309 312
 	
313
+	/**
314
+	 * @param string $var
315
+	 * @param string|null $value
316
+	 */
310 317
 	public function __set($var, $value) {
311 318
 		$this->_dbLoadIfNotLoaded();
312 319
 
@@ -525,7 +532,7 @@  discard block
 block discarded – undo
525 532
 	 *
526 533
 	 * @param unknown_type $func_name
527 534
 	 * @param unknown_type $values
528
-	 * @return unknown
535
+	 * @return TDBMObjectArray
529 536
 	 */
530 537
 	public function __call($func_name, $values) {
531 538
 
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -563,46 +563,46 @@
 block discarded – undo
563 563
 	}
564 564
 	
565 565
 		/**
566
-	 * Implements array behaviour for our object.
567
-	 * 
568
-	 * @param string $offset
569
-	 * @param string $value
570
-	 */
566
+		 * Implements array behaviour for our object.
567
+		 * 
568
+		 * @param string $offset
569
+		 * @param string $value
570
+		 */
571 571
 	public function offsetSet($offset, $value) {
572 572
 		$this->__set($offset, $value);
573
-    }
573
+	}
574 574
 	/**
575 575
 	 * Implements array behaviour for our object.
576 576
 	 * 
577 577
 	 * @param string $offset
578 578
 	 */
579
-    public function offsetExists($offset) {
580
-    	$this->_dbLoadIfNotLoaded();
581
-        return isset($this->db_row[$offset]);
582
-    }
579
+	public function offsetExists($offset) {
580
+		$this->_dbLoadIfNotLoaded();
581
+		return isset($this->db_row[$offset]);
582
+	}
583 583
 	/**
584 584
 	 * Implements array behaviour for our object.
585 585
 	 * 
586 586
 	 * @param string $offset
587 587
 	 */
588
-    public function offsetUnset($offset) {
588
+	public function offsetUnset($offset) {
589 589
 		$this->__set($offset, null);
590
-    }
590
+	}
591 591
 	/**
592 592
 	 * Implements array behaviour for our object.
593 593
 	 * 
594 594
 	 * @param string $offset
595 595
 	 */
596
-    public function offsetGet($offset) {
597
-        return $this->__get($offset);
598
-    }
596
+	public function offsetGet($offset) {
597
+		return $this->__get($offset);
598
+	}
599 599
 	
600 600
 	private $_validIterator = false;
601 601
 	/**
602 602
 	 * Implements iterator behaviour for our object (so we can each column).
603 603
 	 */
604 604
 	public function rewind() {
605
-    	$this->_dbLoadIfNotLoaded();
605
+		$this->_dbLoadIfNotLoaded();
606 606
 		if (count($this->db_row)>0) {
607 607
 			$this->_validIterator = true;
608 608
 		} else {
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 * @param string $table_name
114 114
 	 * @param mixed $id
115 115
 	 */
116
-	public function __construct(TDBMService $tdbmService, $table_name, $id=false) {
116
+	public function __construct(TDBMService $tdbmService, $table_name, $id = false) {
117 117
 		$this->tdbmService = $tdbmService;
118 118
 		$this->db_connection = $this->tdbmService->getConnection();
119 119
 		$this->db_table_name = $table_name;
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * $TDBMObject_state = "loaded" when the object is cached in memory.
160 160
 	 * @return string
161 161
 	 */
162
-	public function getTDBMObjectState(){
162
+	public function getTDBMObjectState() {
163 163
 		return $this->TDBMObject_state;
164 164
 	}
165 165
 	
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	 * $TDBMObject_state = "loaded" when the object is cached in memory.
172 172
 	 * @param string $state
173 173
 	 */
174
-	public function setTDBMObjectState($state){
174
+	public function setTDBMObjectState($state) {
175 175
 		$this->TDBMObject_state = $state;	
176 176
 	}
177 177
 	
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 */
185 185
 	public function loadFromRow($row) {
186 186
 		foreach ($row as $key=>$value) {
187
-			if (strpos($key, 'tdbm_reserved_col_')!==0) {
188
-				$this->db_row[$key]=$value;
187
+			if (strpos($key, 'tdbm_reserved_col_') !== 0) {
188
+				$this->db_row[$key] = $value;
189 189
 			}
190 190
 		}
191 191
 
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
 			// Now for the object_id
220 220
 			$object_id = $this->TDBMObject_id;
221 221
 			// If there is only one primary key:
222
-			if (count($pk_table)==1) {
222
+			if (count($pk_table) == 1) {
223 223
 				$sql_where = $this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id);
224 224
 			} else {
225 225
 				$ids = unserialize($object_id);
226
-				$i=0;
226
+				$i = 0;
227 227
 				$sql_where_array = array();
228 228
 				foreach ($pk_table as $pk) {
229 229
 					$sql_where_array[] = $this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]);
230 230
 					$i++;
231 231
 				}
232
-				$sql_where = implode(" AND ",$sql_where_array);
232
+				$sql_where = implode(" AND ", $sql_where_array);
233 233
 			}
234 234
 
235 235
 			$sql = "SELECT * FROM ".$this->db_connection->escapeDBItem($this->db_table_name)." WHERE ".$sql_where;
236 236
 			$result = $this->db_connection->query($sql);
237 237
 
238 238
 
239
-			if ($result->rowCount()==0)
239
+			if ($result->rowCount() == 0)
240 240
 			{
241 241
 				throw new TDBMException("Could not retrieve object from table \"$this->db_table_name\" with ID \"".$this->TDBMObject_id."\".");
242 242
 			}
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
 			$result = null;
248 248
 				
249 249
 			$this->db_row = array();
250
-			foreach ($fullCaseRow[0] as $key=>$value)  {
251
-				$this->db_row[$this->db_connection->toStandardCaseColumn($key)]=$value;
250
+			foreach ($fullCaseRow[0] as $key=>$value) {
251
+				$this->db_row[$this->db_connection->toStandardCaseColumn($key)] = $value;
252 252
 			}
253 253
 			
254 254
 			$this->TDBMObject_state = "loaded";
@@ -280,10 +280,10 @@  discard block
 block discarded – undo
280 280
 				// Let's try to be accurate in error reporting. The checkColumnExist returns an array of closest matches.
281 281
 				$result_array = $column_exist;
282 282
 				
283
-				if (count($result_array)==1)
283
+				if (count($result_array) == 1)
284 284
 				$str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant this column: '".$result_array[0]."'";
285 285
 				else
286
-				$str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '",$result_array)."'";
286
+				$str = "Could not find column \"$var\" in table \"$this->db_table_name\". Maybe you meant one of those columns: '".implode("', '", $result_array)."'";
287 287
 	
288 288
 	
289 289
 				throw new TDBMException($str);
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
 			$pk_array = $this->getPrimaryKey();
357 357
 			
358 358
 			foreach ($pk_array as $pk) {
359
-				if (isset($this->db_row[$pk]) && $this->db_row[$pk]!==null) {
360
-					$pk_set=true;
359
+				if (isset($this->db_row[$pk]) && $this->db_row[$pk] !== null) {
360
+					$pk_set = true;
361 361
 				}
362 362
 			}
363 363
 			// if there are many columns for the PK, and none is set, we have no way to find the object back!
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 				if (!$first)
381 381
 				$sql .= ',';
382 382
 				$sql .= $this->db_connection->quoteSmart($value);
383
-				$first=false;
383
+				$first = false;
384 384
 			}
385 385
 			$sql .= ')';
386 386
 
@@ -408,12 +408,12 @@  discard block
 block discarded – undo
408 408
 
409 409
 			// If there is only one column for the primary key, and if it has not been filled, let's find it.
410 410
 			// We assume this is the biggest ID in the database
411
-			if (count($pk_array)==1 && !$pk_set) {
411
+			if (count($pk_array) == 1 && !$pk_set) {
412 412
 				// FIXME: for PostgreSQL or MSSQL, the getInsertId call is not thread safe
413 413
 				// We should start a transaction before the insert
414
-				$this->TDBMObject_id = $this->db_connection->getInsertId($this->db_table_name,$pk_array[0]);
414
+				$this->TDBMObject_id = $this->db_connection->getInsertId($this->db_table_name, $pk_array[0]);
415 415
 				$this->db_row[$pk_array[0]] = $this->TDBMObject_id;
416
-			} elseif (count($pk_array)==1 && $pk_set) {
416
+			} elseif (count($pk_array) == 1 && $pk_set) {
417 417
 				$this->TDBMObject_id = $this->db_row[$pk_array[0]];
418 418
 			}
419 419
 
@@ -440,24 +440,24 @@  discard block
 block discarded – undo
440 440
 			
441 441
 			// Let's add this object to the list of objects in cache.
442 442
 			$this->tdbmService->_addToCache($this);
443
-		} else if ($this->TDBMObject_state == "loaded" && $this->db_modified_state==true) {
443
+		} else if ($this->TDBMObject_state == "loaded" && $this->db_modified_state == true) {
444 444
 			//$primary_key = $this->getPrimaryKey();
445 445
 			// Let's first get the primary keys
446 446
 			$pk_table = $this->getPrimaryKey();
447 447
 			// Now for the object_id
448 448
 			$object_id = $this->TDBMObject_id;
449 449
 			// If there is only one primary key:
450
-			if (count($pk_table)==1) {
450
+			if (count($pk_table) == 1) {
451 451
 				$sql_where = $this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id);
452 452
 			} else {
453 453
 				$ids = unserialize($object_id);
454
-				$i=0;
454
+				$i = 0;
455 455
 				$sql_where_array = array();
456 456
 				foreach ($pk_table as $pk) {
457 457
 					$sql_where_array[] = $this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]);
458 458
 					$i++;
459 459
 				}
460
-				$sql_where = implode(" AND ",$sql_where_array);
460
+				$sql_where = implode(" AND ", $sql_where_array);
461 461
 			}
462 462
 
463 463
 			$sql = 'UPDATE '.$this->db_connection->escapeDBItem($this->db_table_name).' SET ';
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 				if (!$first)
468 468
 				$sql .= ',';
469 469
 				$sql .= $this->db_connection->escapeDBItem($key)." = ".$this->db_connection->quoteSmart($value);
470
-				$first=false;
470
+				$first = false;
471 471
 			}
472 472
 			$sql .= ' WHERE '.$sql_where/*$primary_key."='".$this->db_row[$primary_key]."'"*/;
473 473
 			try {
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 	 */
530 530
 	public function __call($func_name, $values) {
531 531
 
532
-		if (strpos($func_name,"get_") === 0) {
533
-			$table = substr($func_name,4);
532
+		if (strpos($func_name, "get_") === 0) {
533
+			$table = substr($func_name, 4);
534 534
 		} else {
535 535
 			throw new TDBMException("Method ".$func_name." not found");
536 536
 		}
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 	 * Implement the unique JsonSerializable method
641 641
 	 * @return array
642 642
 	 */
643
-	public function jsonSerialize(){
643
+	public function jsonSerialize() {
644 644
 		$this->_dbLoadIfNotLoaded();
645 645
 		return $this->db_row;
646 646
 	}
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Utils/TDBMDaoGenerator.php 4 patches
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 				$defaultSort = $data['column_name'];
427 427
 				if (count($matches == 3)){
428 428
 					$defaultSortDirection = $matches[2];
429
-				}else{
429
+				} else{
430 430
 					$defaultSortDirection = 'ASC';
431 431
 				}
432 432
 			}
@@ -836,8 +836,9 @@  discard block
 block discarded – undo
836 836
 	public static function toCamelCase($str) {
837 837
 		$str = strtoupper(substr($str,0,1)).substr($str,1);
838 838
 		while (true) {
839
-			if (strpos($str, "_") === false && strpos($str, " ") === false)
840
-				break;
839
+			if (strpos($str, "_") === false && strpos($str, " ") === false) {
840
+							break;
841
+			}
841 842
 				
842 843
 			$pos = strpos($str, "_");
843 844
 			if ($pos === false) {
Please login to merge, or discard this patch.
Doc Comments   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	/**
125 125
 	 * Generates in one method call the daos and the beans for one table.
126 126
 	 * 
127
-	 * @param $tableName
127
+	 * @param string $tableName
128 128
 	 */
129 129
 	public function generateDaoAndBean($tableName) {
130 130
 		//$baseClassName = TDBMDaoGenerator::toSingular(TDBMDaoGenerator::toCamelCase($tableName));
@@ -427,6 +427,10 @@  discard block
 block discarded – undo
427 427
 	 * @param string $fileName The file that will be written (without the directory)
428 428
 	 * @param string $className The name of the class
429 429
 	 * @param string $tableName The name of the table
430
+	 * @param string $baseFileName
431
+	 * @param string $beanFileName
432
+	 * @param string $baseClassName
433
+	 * @param string $beanClassName
430 434
 	 */
431 435
 	public function generateDao($fileName, $baseFileName, $beanFileName, $className, $baseClassName, $beanClassName, $tableName) {
432 436
 		$info = $this->dbConnection->getTableInfo($tableName);
@@ -697,7 +701,7 @@  discard block
 block discarded – undo
697 701
 	/**
698 702
 	 * Generates the factory bean.
699 703
 	 * 
700
-	 * @param $tableList
704
+	 * @param string[] $tableList
701 705
 	 */
702 706
 	private function generateFactory($tableList) {
703 707
 		// For each table, let's write a property.
@@ -763,7 +767,6 @@  discard block
 block discarded – undo
763 767
 	 * Transforms the property name in a setter name.
764 768
 	 * For instance, phone => getPhone or name => getName
765 769
 	 *
766
-	 * @param string $methodName
767 770
 	 * @return string
768 771
 	 */
769 772
 	public static function getSetterNameForPropertyName($propertyName) {
@@ -843,7 +846,7 @@  discard block
 block discarded – undo
843 846
 	 * Tries to put string to the singular form (if it is plural).
844 847
 	 * Obviously, this can't be perfect, be we do the best we can.
845 848
 	 * 
846
-	 * @param $str string
849
+	 * @param string $str string
847 850
 	 * @return string
848 851
 	 */
849 852
 	public static function toSingular($str) {
@@ -864,7 +867,7 @@  discard block
 block discarded – undo
864 867
 	 * Put the first letter of the string in lower case.
865 868
 	 * Very useful to transform a class name into a variable name.
866 869
 	 * 
867
-	 * @param $str string
870
+	 * @param string $str string
868 871
 	 * @return string
869 872
 	 */
870 873
 	public static function toVariableName($str) {
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 		// Ok, let's return the list of all tables.
115 115
 		// These will be used by the calling script to create Mouf instances.
116 116
 		$root = simplexml_load_string("<tdbm></tdbm>");
117
-    	foreach ($tableList as $table) {
118
-    		$root->addChild("table", $table);
119
-    	}
117
+		foreach ($tableList as $table) {
118
+			$root->addChild("table", $table);
119
+		}
120 120
 		
121 121
 		return $root;
122 122
 	}
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
 		$beanName = $this->getBeanNameFromTableName($tableName);
133 133
 		$baseBeanName = $this->getBaseBeanNameFromTableName($tableName);
134 134
 
135
-        $connection = $this->dbConnection;
136
-        if ($connection instanceof CachedConnection){
137
-            $connection->cacheService->purgeAll();
138
-        }
135
+		$connection = $this->dbConnection;
136
+		if ($connection instanceof CachedConnection){
137
+			$connection->cacheService->purgeAll();
138
+		}
139 139
 		
140 140
 		$this->generateBean($beanName.".php", $beanName, $baseBeanName.".php", $baseBeanName, $tableName);
141 141
 		$this->generateDao($daoName.".php", $daoName."Base.php", $beanName.".php", $daoName, $daoName."Base", $beanName, $tableName);
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		$baseBeanName = $this->getBaseBeanNameFromTableName($tableName);
134 134
 
135 135
         $connection = $this->dbConnection;
136
-        if ($connection instanceof CachedConnection){
136
+        if ($connection instanceof CachedConnection) {
137 137
             $connection->cacheService->purgeAll();
138 138
         }
139 139
 		
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 		if($date === null)
232 232
 			return null;
233 233
 		else
234
-			return strtotime($date'.($this->storeInUtc?'.\' UTC\'':'').');
234
+			return strtotime($date'.($this->storeInUtc ? '.\' UTC\'' : '').');
235 235
 	}
236 236
 	
237 237
 	/**
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 		if ($this->'.$array["col1"].' == null) {
322 322
 			return null;
323 323
 		}
324
-		return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\","\\\\",$this->beanNamespace).'\\\\'.$referencedBeanName.'", true);
324
+		return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\", "\\\\", $this->beanNamespace).'\\\\'.$referencedBeanName.'", true);
325 325
 	}
326 326
 	
327 327
 	/**
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 		
341 341
 		// Now, let's implement the shortcuts to the getter of objects.
342 342
 		// Shortcuts are used to save typing. They are available only if a referenced table is referenced only once by our tables.
343
-		foreach($referencedTablesList as $referrencedTable=>$number) {
343
+		foreach ($referencedTablesList as $referrencedTable=>$number) {
344 344
 			if ($number == 1) {
345 345
 				foreach ($constraints as $array) {
346
-					if ($array['table2'] ==$referrencedTable) {
346
+					if ($array['table2'] == $referrencedTable) {
347 347
 						$columnName = $array['col1'];
348 348
 						$targetColumnName = $array['col2'];
349 349
 						break;
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 		if ($this->'.$array["col1"].' == null) {
375 375
 			return null;
376 376
 		}
377
-		return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\","\\\\",$this->beanNamespace).'\\\\'.$referencedBeanName.'");
377
+		return $this->tdbmService->getObject("'.$array["table2"].'", $this->'.$array["col1"].', "'.str_replace("\\", "\\\\", $this->beanNamespace).'\\\\'.$referencedBeanName.'");
378 378
 	}
379 379
 	
380 380
 	/**
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 {
417 417
 
418 418
 }";
419
-			file_put_contents($this->beanDirectory.$fileName ,$str);
419
+			file_put_contents($this->beanDirectory.$fileName, $str);
420 420
 			@chmod($this->beanDirectory.$fileName, 0664);
421 421
 		}
422 422
 	}
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
 		foreach ($info as $index => $data) {
435 435
 			$comments = $data['column_comment'];
436 436
 			$matches = array();
437
-			if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0){
437
+			if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) {
438 438
 				$defaultSort = $data['column_name'];
439
-				if (count($matches == 3)){
439
+				if (count($matches == 3)) {
440 440
 					$defaultSortDirection = $matches[2];
441
-				}else{
441
+				} else {
442 442
 					$defaultSortDirection = 'ASC';
443 443
 				}
444 444
 			}
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 
668 668
 		
669 669
 
670
-		file_put_contents($this->daoDirectory.$baseFileName ,$str);
670
+		file_put_contents($this->daoDirectory.$baseFileName, $str);
671 671
 		@chmod($this->daoDirectory.$baseFileName, 0664);
672 672
 		
673 673
 		// Now, let's generate the "editable" class
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 {
690 690
 
691 691
 }";
692
-			file_put_contents($this->daoDirectory.$fileName ,$str);
692
+			file_put_contents($this->daoDirectory.$fileName, $str);
693 693
 			@chmod($this->daoDirectory.$fileName, 0664);
694 694
 		}
695 695
 	}
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 ?>';
757 757
 		
758 758
 		//$daoDirectory = dirname(__FILE__)."/../../../../../dao/";
759
-		file_put_contents($this->daoDirectory.$this->daoFactoryClassName.'.php' ,$str);
759
+		file_put_contents($this->daoDirectory.$this->daoFactoryClassName.'.php', $str);
760 760
 	}
761 761
 	
762 762
 	/**
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 	 * @return string
824 824
 	 */
825 825
 	public static function toCamelCase($str) {
826
-		$str = strtoupper(substr($str,0,1)).substr($str,1);
826
+		$str = strtoupper(substr($str, 0, 1)).substr($str, 1);
827 827
 		while (true) {
828 828
 			if (strpos($str, "_") === false && strpos($str, " ") === false)
829 829
 				break;
@@ -832,9 +832,9 @@  discard block
 block discarded – undo
832 832
 			if ($pos === false) {
833 833
 				$pos = strpos($str, " ");
834 834
 			}
835
-			$before = substr($str,0,$pos);
836
-			$after = substr($str,$pos+1);
837
-			$str = $before.strtoupper(substr($after,0,1)).substr($after,1);
835
+			$before = substr($str, 0, $pos);
836
+			$after = substr($str, $pos+1);
837
+			$str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1);
838 838
 		}
839 839
 		return $str;
840 840
 	}
Please login to merge, or discard this patch.