Passed
Push — master ( b771a6...8c8288 )
by Richard
02:06
created
Maphper/Lib/Sql/GeneralOperator.php 1 patch
Braces   +13 added lines, -5 removed lines patch added patch discarded remove patch
@@ -16,8 +16,11 @@  discard block
 block discarded – undo
16 16
     }
17 17
 
18 18
     private function getOperator($mode) {
19
-        if (\Maphper\Maphper::FIND_BIT & $mode) return '&';
20
-        else if (\Maphper\Maphper::FIND_NOT & $mode) return '!=';
19
+        if (\Maphper\Maphper::FIND_BIT & $mode) {
20
+        	return '&';
21
+        } else if (\Maphper\Maphper::FIND_NOT & $mode) {
22
+        	return '!=';
23
+        }
21 24
 
22 25
         return $this->getEqualsOperators($mode);
23 26
     }
@@ -25,10 +28,15 @@  discard block
 block discarded – undo
25 28
     private function getEqualsOperators($mode) {
26 29
         $operator = "";
27 30
 
28
-        if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
29
-        else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
31
+        if (\Maphper\Maphper::FIND_GREATER & $mode) {
32
+        	$operator = '>';
33
+        } else if (\Maphper\Maphper::FIND_LESS & $mode) {
34
+        	$operator = '<';
35
+        }
30 36
 
31
-        if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
37
+        if (\Maphper\Maphper::FIND_EXACT & $mode) {
38
+        	$operator .= '=';
39
+        }
32 40
 
33 41
         return $operator;
34 42
     }
Please login to merge, or discard this patch.
Maphper/Lib/Sql/WhereBuilder.php 1 patch
Braces   +28 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@  discard block
 block discarded – undo
13 13
             'Maphper\Lib\Sql\GeneralOperator'
14 14
         ];
15 15
 
16
-        foreach ($defaultConditionals as $conditional) $this->addConditional(new $conditional);
16
+        foreach ($defaultConditionals as $conditional) {
17
+        	$this->addConditional(new $conditional);
18
+        }
17 19
     }
18 20
 
19 21
     public function addConditional(WhereConditional $conditional) {
@@ -27,7 +29,9 @@  discard block
 block discarded – undo
27 29
         foreach ($fields as $key => $value) {
28 30
             $value = $this->convertDates($value);
29 31
 
30
-            if (is_object($value)) continue;
32
+            if (is_object($value)) {
33
+            	continue;
34
+            }
31 35
 			$result = $this->getResult($key, $value, $mode);
32 36
             $result = $this->fixDuplicateArgs($args, $result);
33 37
             $sql = array_merge($sql, (array)$result['sql']);
@@ -40,7 +44,9 @@  discard block
 block discarded – undo
40 44
     // Returns result with duplicate issues removed
41 45
     private function fixDuplicateArgs($origArgs, $result) {
42 46
         $duplicates = array_intersect_key($result['args'], $origArgs); // Holds all keys in results already in the args
43
-        if (count($duplicates) === 0) return $result;
47
+        if (count($duplicates) === 0) {
48
+        	return $result;
49
+        }
44 50
 
45 51
         foreach ($duplicates as $argKey => $argVal) {
46 52
             $valHash = substr(md5($argVal), 0, 5);
@@ -59,29 +65,40 @@  discard block
 block discarded – undo
59 65
      * Either get sql from a conditional or call createSql again because the mode needs to be changed
60 66
      */
61 67
     private function getResult($key, $value, $mode) {
62
-        if (is_numeric($key) && is_array($value)) return $this->createSql($value, $key);
68
+        if (is_numeric($key) && is_array($value)) {
69
+        	return $this->createSql($value, $key);
70
+        }
63 71
         return $this->getConditional($key, $value, $mode);
64 72
     }
65 73
 
66 74
     private function sqlArrayToString($sql, $mode) {
67
-        if (\Maphper\Maphper::FIND_OR & $mode) $query = implode(' OR  ', $sql);
68
-		else $query = implode(' AND ', $sql);
69
-		if (!empty($query)) $query = '(' . $query . ')';
75
+        if (\Maphper\Maphper::FIND_OR & $mode) {
76
+        	$query = implode(' OR  ', $sql);
77
+        } else {
78
+			$query = implode(' AND ', $sql);
79
+		}
80
+		if (!empty($query)) {
81
+			$query = '(' . $query . ')';
82
+		}
70 83
         return $query;
71 84
     }
72 85
 
73 86
     private function getConditional($key, $value, $mode) {
74 87
         foreach ($this->conditionals as $conditional) {
75
-            if ($conditional->matches($key, $value, $mode))
76
-                return $conditional->getSql($key, $value, $mode);
88
+            if ($conditional->matches($key, $value, $mode)) {
89
+                            return $conditional->getSql($key, $value, $mode);
90
+            }
77 91
         }
78 92
         throw new \Exception("Invalid WHERE query");
79 93
     }
80 94
 
81 95
     private function convertDates($value) {
82 96
         if ($value instanceof \DateTimeInterface) {
83
-            if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
84
-            else $value = $value->format('Y-m-d H:i:s');
97
+            if ($value->format('H:i:s')  == '00:00:00') {
98
+            	$value = $value->format('Y-m-d');
99
+            } else {
100
+            	$value = $value->format('Y-m-d H:i:s');
101
+            }
85 102
         }
86 103
         return $value;
87 104
     }
Please login to merge, or discard this patch.
Maphper/Lib/DateInjector.php 1 patch
Braces   +27 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,26 +11,35 @@  discard block
 block discarded – undo
11 11
 
12 12
 	public function replaceDates($obj, $reset = true) {
13 13
 		//prevent infinite recursion, only process each object once
14
-		if ($this->checkCache($obj, $reset)) return $obj;
14
+		if ($this->checkCache($obj, $reset)) {
15
+			return $obj;
16
+		}
15 17
 
16
-		if ($this->isIterable($obj)) foreach ($obj as &$o) $o = $this->replaceDates($o, false);
17
-		if ($this->isPossiblyDateString($obj)) $obj = $this->tryToGetDateObjFromString($obj);
18
+		if ($this->isIterable($obj)) {
19
+			foreach ($obj as &$o) $o = $this->replaceDates($o, false);
20
+		}
21
+		if ($this->isPossiblyDateString($obj)) {
22
+			$obj = $this->tryToGetDateObjFromString($obj);
23
+		}
18 24
 		return $obj;
19 25
 	}
20 26
 
21 27
     private function tryToGetDateObjFromString($obj) {
22 28
         try {
23 29
             $date = new \DateTime($obj);
24
-			if ($this->dateMatchesFormats($date, $obj)) $obj = $date;
25
-        }
26
-        catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date
30
+			if ($this->dateMatchesFormats($date, $obj)) {
31
+				$obj = $date;
32
+			}
33
+        } catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date
27 34
         }
28 35
         return $obj;
29 36
     }
30 37
 
31 38
 	private function dateMatchesFormats($date, $str) {
32 39
 		foreach ($this->dateFormats as list($format, $len)) {
33
-			if ($date->format($format) == substr($str, 0, $len)) return true;
40
+			if ($date->format($format) == substr($str, 0, $len)) {
41
+				return true;
42
+			}
34 43
 		}
35 44
 		return false;
36 45
 	}
@@ -44,11 +53,18 @@  discard block
 block discarded – undo
44 53
     }
45 54
 
46 55
 	private function checkCache($obj, $reset) {
47
-		if ($reset) $this->processCache = new \SplObjectStorage();
48
-        if (!is_object($obj)) return false;
56
+		if ($reset) {
57
+			$this->processCache = new \SplObjectStorage();
58
+		}
59
+        if (!is_object($obj)) {
60
+        	return false;
61
+        }
49 62
 
50
-		if ($this->processCache->contains($obj)) return $obj;
51
-		else $this->processCache->attach($obj, true);
63
+		if ($this->processCache->contains($obj)) {
64
+			return $obj;
65
+		} else {
66
+			$this->processCache->attach($obj, true);
67
+		}
52 68
 
53 69
 		return false;
54 70
 	}
Please login to merge, or discard this patch.
Maphper/Optimiser/MySql.php 1 patch
Braces   +13 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,16 +11,21 @@  discard block
 block discarded – undo
11 11
 		foreach ($columns as $column) {
12 12
 			$parts = explode('.', $column->Field_name);
13 13
 			$name = $this->quote(end($parts));
14
-			if ($column->Min_value === null && $column->Max_value === null) $this->pdo->query('ALTER TABLE ' . $this->quote($table) . ' DROP COLUMN ' . $name);
15
-			else {
14
+			if ($column->Min_value === null && $column->Max_value === null) {
15
+				$this->pdo->query('ALTER TABLE ' . $this->quote($table) . ' DROP COLUMN ' . $name);
16
+			} else {
16 17
 				$type = $column->Optimal_fieldtype;
17 18
 				if ($column->Max_length < 11) {
18 19
 					//Check for dates
19 20
 					$count = $this->pdo->query('SELECT count(*) as `count` FROM ' . $this->quote($table) . ' WHERE STR_TO_DATE(' . $name . ',\'%Y-%m-%d %H:%i:s\') IS NULL OR STR_TO_DATE(' . $name . ',\'%Y-%m-%d %H:%i:s\') != ' . $name . ' LIMIT 1')->fetch(\PDO::FETCH_OBJ)->count;
20
-					if ($count == 0) $type = 'DATETIME';
21
+					if ($count == 0) {
22
+						$type = 'DATETIME';
23
+					}
21 24
 
22 25
 					$count = $this->pdo->query('SELECT count(*) as `count` FROM ' . $this->quote($table) . ' WHERE STR_TO_DATE(' . $name . ',\'%Y-%m-%d\') IS NULL OR STR_TO_DATE(' . $name . ',\'%Y-%m-%d\') != ' . $name . ' LIMIT 1')->fetch(\PDO::FETCH_OBJ)->count;
23
-					if ($count == 0) $type = 'DATE';
26
+					if ($count == 0) {
27
+						$type = 'DATE';
28
+					}
24 29
 				}
25 30
 
26 31
 				//If it's text, work out if it would be better to be something else
@@ -30,8 +35,7 @@  discard block
 block discarded – undo
30 35
 					if ($count == 0) {
31 36
 						$type = 'INT(11)';
32 37
 						$runAgain = true;
33
-					}
34
-					else {
38
+					} else {
35 39
 						//See if it's decimal
36 40
 						$count = $this->pdo->query('SELECT count(*) FROM ' . $table . ' WHERE concat(\'\', ' . $name . ' * 1) != ' . $name . ')')->fetch(\PDO::FETCH_OBJ)->count;
37 41
 						if ($count == 0) {
@@ -45,6 +49,8 @@  discard block
 block discarded – undo
45 49
 			}
46 50
 		}
47 51
 		//Sometimes a second pass is needed, if a column has gone from varchar -> int(11) a better int type may be needed
48
-		if ($runAgain) $this->optimiseColumns($table);
52
+		if ($runAgain) {
53
+			$this->optimiseColumns($table);
54
+		}
49 55
 	}
50 56
 }
51 57
\ No newline at end of file
Please login to merge, or discard this patch.
Maphper/Relation/One.php 1 patch
Braces   +17 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,7 +9,9 @@  discard block
 block discarded – undo
9 9
 	private $siblings = [];
10 10
 
11 11
 	public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $criteria = []) {
12
-        if ($criteria) $mapper = $mapper->filter($this->criteira);
12
+        if ($criteria) {
13
+        	$mapper = $mapper->filter($this->criteira);
14
+        }
13 15
 		$this->mapper = $mapper;
14 16
 		$this->parentField = $parentField;
15 17
 		$this->localField = $localField;
@@ -29,7 +31,9 @@  discard block
 block discarded – undo
29 31
 	private function lazyLoad() {
30 32
 		if (!isset($this->data)) {
31 33
 
32
-			if ($this->parentObject == null) throw new \Exception('Error, no object set');
34
+			if ($this->parentObject == null) {
35
+				throw new \Exception('Error, no object set');
36
+			}
33 37
 
34 38
 			$this->eagerLoad();
35 39
 
@@ -58,7 +62,9 @@  discard block
 block discarded – undo
58 62
 		}
59 63
 
60 64
 		foreach ($this->siblings as $sibling) {
61
-            if (isset($cache[$sibling->parentObject->{$this->parentField}])) $sibling->data = $cache[$sibling->parentObject->{$this->parentField}];
65
+            if (isset($cache[$sibling->parentObject->{$this->parentField}])) {
66
+            	$sibling->data = $cache[$sibling->parentObject->{$this->parentField}];
67
+            }
62 68
 		}
63 69
 		/*
64 70
 		foreach ($this->siblings as $sibling) {
@@ -69,13 +75,18 @@  discard block
 block discarded – undo
69 75
     }
70 76
 
71 77
 	public function __call($func, array $args = []) {
72
-		if ($this->lazyLoad() == null) return '';
78
+		if ($this->lazyLoad() == null) {
79
+			return '';
80
+		}
73 81
 		return call_user_func_array([$this->lazyLoad(), $func], $args);
74 82
 	}
75 83
 
76 84
 	public function __get($name) {
77
-		if ($this->lazyLoad()) return $this->lazyLoad()->$name;
78
-        else return null;
85
+		if ($this->lazyLoad()) {
86
+			return $this->lazyLoad()->$name;
87
+		} else {
88
+        	return null;
89
+        }
79 90
 	}
80 91
 
81 92
 	public function __isset($name) {
Please login to merge, or discard this patch.
Maphper/Relation/Many.php 1 patch
Braces   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,7 +6,9 @@  discard block
 block discarded – undo
6 6
 	private $localField;
7 7
 	
8 8
 	public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $critiera = []) {
9
-		if ($critiera) $mapper->filter($critiera);
9
+		if ($critiera) {
10
+			$mapper->filter($critiera);
11
+		}
10 12
 		$this->mapper = $mapper;
11 13
 		$this->parentField = $parentField;
12 14
 		$this->localField = $localField;		
@@ -14,17 +16,24 @@  discard block
 block discarded – undo
14 16
 	
15 17
 	
16 18
 	public function getData($parentObject) {
17
-		if (!isset($parentObject->{$this->parentField})) $mapper = $this->mapper;
18
-		else $mapper = $this->mapper->filter([$this->localField => $parentObject->{$this->parentField}]);
19
+		if (!isset($parentObject->{$this->parentField})) {
20
+			$mapper = $this->mapper;
21
+		} else {
22
+			$mapper = $this->mapper->filter([$this->localField => $parentObject->{$this->parentField}]);
23
+		}
19 24
 		
20 25
 		return $mapper;
21 26
 	}
22 27
 
23 28
 	
24 29
 	public function overwrite($key, &$mapper) {
25
-		if (!isset($key->{$this->parentField})) return false;
30
+		if (!isset($key->{$this->parentField})) {
31
+			return false;
32
+		}
26 33
 		foreach ($mapper as $k => $val) {
27
-			if (!empty($val->{$this->localField}) && $val->{$this->localField} == $key->{$this->parentField}) continue;
34
+			if (!empty($val->{$this->localField}) && $val->{$this->localField} == $key->{$this->parentField}) {
35
+				continue;
36
+			}
28 37
 			$val->{$this->localField} = $key->{$this->parentField};
29 38
 			$this->mapper[] = $val;
30 39
 		}
Please login to merge, or discard this patch.
Maphper/Relation/ManyManyIterator.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,9 @@
 block discarded – undo
12 12
   }
13 13
 
14 14
   public function current() {
15
-    if ($this->intermediateName) return $this->iterator->current()->{$this->intermediateName};
15
+    if ($this->intermediateName) {
16
+    	return $this->iterator->current()->{$this->intermediateName};
17
+    }
16 18
 		return $this->iterator->current();
17 19
 	}
18 20
 
Please login to merge, or discard this patch.
Maphper/Relation/ManyMany.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@  discard block
 block discarded – undo
31 31
 	public function overwrite($parentObject, &$data) {
32 32
 		$this->results = $data;
33 33
 		$this->object = $parentObject;
34
-		foreach ($data as $dt) $this[] = $dt;
34
+		foreach ($data as $dt) {
35
+			$this[] = $dt;
36
+		}
35 37
 	}
36 38
 
37 39
 	//bit hacky, breaking encapsulation, but simplest way to work out the info for the other side of the many:many relationship.
@@ -86,8 +88,9 @@  discard block
 block discarded – undo
86 88
 
87 89
 	public function offsetSet($name, $value) {
88 90
 		list($relatedField, $valueField, $mapper) = $this->getOtherFieldNameInfo();
89
-		if ($this->autoTraverse) $this->offsetSetAutotraverse($value, $relatedField, $valueField);
90
-		else if ($this->doUpdateInterMapper($value, $relatedField, $valueField)) {
91
+		if ($this->autoTraverse) {
92
+			$this->offsetSetAutotraverse($value, $relatedField, $valueField);
93
+		} else if ($this->doUpdateInterMapper($value, $relatedField, $valueField)) {
91 94
             $record = $value;
92 95
 			$record->{$this->parentField} = $value->{$this->intermediateName}->{$this->localField};
93 96
 			$record->$valueField = $this->object->{$relatedField};
Please login to merge, or discard this patch.