Passed
Push — master ( 8885c8...8f5295 )
by Tom
01:55
created
Maphper/Lib/VisibilityOverride.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,8 +9,7 @@
 block discarded – undo
9 9
 		if ($object instanceof \stdclass) {
10 10
 			$this->readClosure = function() use ($object) { return $object;	};
11 11
 			$this->writeClosure = function ($field, $value) use ($object) { $object->$field = $value; };
12
-		}
13
-		else {
12
+		} else {
14 13
             $visOverride = $this;
15 14
 			$this->readClosure = function() use ($visOverride) {
16 15
                 return (object) array_filter(get_object_vars($this), [$visOverride, 'isReturnableDataType']);
Please login to merge, or discard this patch.
Maphper/Lib/Entity.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,14 +21,18 @@
 block discarded – undo
21 21
 
22 22
 	public function wrap($relations, $object, $siblings = []) {
23 23
 		//see if any relations need overwriting
24
-		foreach ($relations as $name => $relation) $this->addRelationData($object, $name, $relation, $siblings);
24
+		foreach ($relations as $name => $relation) {
25
+			$this->addRelationData($object, $name, $relation, $siblings);
26
+		}
25 27
 		return $object;
26 28
 	}
27 29
 
28 30
     private function addRelationData($object, $name, $relation, $siblings) {
29 31
         if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation) ) {
30 32
             //After overwriting the relation, does the parent object ($object) need overwriting as well?
31
-            if ($relation->overwrite($object, $object->$name)) $this->parent[] = $object;
33
+            if ($relation->overwrite($object, $object->$name)) {
34
+            	$this->parent[] = $object;
35
+            }
32 36
         }
33 37
 
34 38
         $object->$name = $relation->getData($object, $siblings);
Please login to merge, or discard this patch.
Maphper/Lib/CrudBuilder.php 1 patch
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,10 +19,15 @@  discard block
 block discarded – undo
19 19
 			//For dates with times set, search on time, if the time is not set, search on date only.
20 20
 			//E.g. searching for all records posted on '2015-11-14' should return all records that day, not just the ones posted at 00:00:00 on that day
21 21
 			if ($value instanceof \DateTime) {
22
-				if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
23
-				else $value = $value->format('Y-m-d H:i:s');
22
+				if ($value->format('H:i:s')  == '00:00:00') {
23
+					$value = $value->format('Y-m-d');
24
+				} else {
25
+					$value = $value->format('Y-m-d H:i:s');
26
+				}
27
+			}
28
+			if (is_object($value)) {
29
+				continue;
24 30
 			}
25
-			if (is_object($value)) continue;
26 31
 			if ($prependField){
27 32
 				$sql[] = $this->quote($field) . ' = :' . $field;
28 33
 			} else {
@@ -41,7 +46,9 @@  discard block
 block discarded – undo
41 46
 	public function update($table, array $primaryKey, $data) {
42 47
 		$query = $this->buildSaveQuery($data, true);
43 48
 		$where = [];
44
-		foreach($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field;
49
+		foreach($primaryKey as $field) {
50
+			$where[] = $this->quote($field) . ' = :' . $field;
51
+		}
45 52
 		return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']). ' WHERE '. implode(' AND ', $where), $query['args']);
46 53
 	}
47 54
 }
Please login to merge, or discard this patch.
Maphper/Lib/ArrayFilter.php 1 patch
Braces   +26 added lines, -14 removed lines patch added patch discarded remove patch
@@ -21,8 +21,11 @@  discard block
 block discarded – undo
21 21
             foreach ($fields as $key => $val) {
22 22
                 $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode);
23 23
 
24
-                if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true;
25
-                else if (Maphper::FIND_OR ^ $mode && $currentFieldResult === false) return false;
24
+                if (Maphper::FIND_OR & $mode && $currentFieldResult === true) {
25
+                	return true;
26
+                } else if (Maphper::FIND_OR ^ $mode && $currentFieldResult === false) {
27
+                	return false;
28
+                }
26 29
             }
27 30
             return (bool)(Maphper::FIND_OR ^ $mode);
28 31
         };
@@ -31,12 +34,13 @@  discard block
 block discarded – undo
31 34
     private function getIfFieldMatches($key, $val, $data, $mode) {
32 35
         if ($this->shouldRunDeepSearch($key, $val)) {
33 36
             return $this->getSearchFieldFunction($val, $key)($data);
37
+        } else if (!isset($data->$key)) {
38
+        	return false;
39
+        } else if ($this->isInArraySearch($mode, $key, $val)) {
40
+                    return in_array($data->$key, $val);
41
+        } else {
42
+                    return $this->processFilter($mode, $val, $data->$key);
34 43
         }
35
-        else if (!isset($data->$key)) return false;
36
-        else if ($this->isInArraySearch($mode, $key, $val))
37
-            return in_array($data->$key, $val);
38
-        else
39
-            return $this->processFilter($mode, $val, $data->$key);
40 44
     }
41 45
 
42 46
     private function shouldRunDeepSearch($key, $val) {
@@ -48,13 +52,21 @@  discard block
 block discarded – undo
48 52
     }
49 53
 
50 54
     private function processFilter($mode, $expected, $actual) {
51
-        if (Maphper::FIND_NOT & $mode) return $expected != $actual;
52
-        else if ((Maphper::FIND_GREATER | Maphper::FIND_EXACT) === $mode) return $expected <= $actual;
53
-        else if ((Maphper::FIND_LESS | Maphper::FIND_EXACT) === $mode) return $expected >= $actual;
54
-        else if (Maphper::FIND_GREATER & $mode) return $expected < $actual;
55
-        else if (Maphper::FIND_LESS & $mode) return $expected > $actual;
56
-        else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1];
57
-        else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual);
55
+        if (Maphper::FIND_NOT & $mode) {
56
+        	return $expected != $actual;
57
+        } else if ((Maphper::FIND_GREATER | Maphper::FIND_EXACT) === $mode) {
58
+        	return $expected <= $actual;
59
+        } else if ((Maphper::FIND_LESS | Maphper::FIND_EXACT) === $mode) {
60
+        	return $expected >= $actual;
61
+        } else if (Maphper::FIND_GREATER & $mode) {
62
+        	return $expected < $actual;
63
+        } else if (Maphper::FIND_LESS & $mode) {
64
+        	return $expected > $actual;
65
+        } else if (Maphper::FIND_BETWEEN & $mode) {
66
+        	return $expected[0] <= $actual && $actual <= $expected[1];
67
+        } else if (Maphper::FIND_NOCASE & $mode) {
68
+        	return strtolower($expected) == strtolower($actual);
69
+        }
58 70
         return $expected == $actual;
59 71
     }
60 72
 }
Please login to merge, or discard this patch.
Maphper/Lib/Sql/NullConditional.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,9 @@
 block discarded – undo
8 8
 
9 9
     public function getSql($key, $value, $mode) {
10 10
         $nullSql = $key . ' IS ';
11
-        if (\Maphper\Maphper::FIND_NOT & $mode) $nullSql .= 'NOT ';
11
+        if (\Maphper\Maphper::FIND_NOT & $mode) {
12
+        	$nullSql .= 'NOT ';
13
+        }
12 14
         $sql = [$nullSql . 'NULL'];
13 15
 
14 16
         return ['args' => [], 'sql' => $sql];
Please login to merge, or discard this patch.
Maphper/Lib/Sql/Like.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,12 @@
 block discarded – undo
16 16
     }
17 17
 
18 18
     private function getValue($value, $mode) {
19
-        if ((Maphper::FIND_LIKE | Maphper::FIND_ENDS) & $mode) $value = '%' . $value;
20
-        if ((Maphper::FIND_LIKE | Maphper::FIND_STARTS) & $mode) $value .= '%';
19
+        if ((Maphper::FIND_LIKE | Maphper::FIND_ENDS) & $mode) {
20
+        	$value = '%' . $value;
21
+        }
22
+        if ((Maphper::FIND_LIKE | Maphper::FIND_STARTS) & $mode) {
23
+        	$value .= '%';
24
+        }
21 25
         return $value;
22 26
     }
23 27
 }
Please login to merge, or discard this patch.
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.