Passed
Push — master ( 562277...03179d )
by Richard
01:52
created
maphper/lib/dateinjector.php 1 patch
Braces   +25 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,19 +6,26 @@  discard block
 block discarded – undo
6 6
 
7 7
 	public function replaceDates($obj, $reset = true) {
8 8
 		//prevent infinite recursion, only process each object once
9
-		if ($this->checkCache($obj, $reset)) return $obj;
10
-
11
-		if ($this->isIterable($obj)) foreach ($obj as &$o) $o = $this->replaceDates($o, false);
12
-		if ($this->isPossiblyDateString($obj)) $obj = $this->tryToGetDateObjFromString($obj);
9
+		if ($this->checkCache($obj, $reset)) {
10
+			return $obj;
11
+		}
12
+
13
+		if ($this->isIterable($obj)) {
14
+			foreach ($obj as &$o) $o = $this->replaceDates($o, false);
15
+		}
16
+		if ($this->isPossiblyDateString($obj)) {
17
+			$obj = $this->tryToGetDateObjFromString($obj);
18
+		}
13 19
 		return $obj;
14 20
 	}
15 21
 
16 22
     private function tryToGetDateObjFromString($obj) {
17 23
         try {
18 24
             $date = new \DateTime($obj);
19
-            if ($date->format('Y-m-d H:i:s') == substr($obj, 0, 20) || $date->format('Y-m-d') == substr($obj, 0, 10)) $obj = $date;
20
-        }
21
-        catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date
25
+            if ($date->format('Y-m-d H:i:s') == substr($obj, 0, 20) || $date->format('Y-m-d') == substr($obj, 0, 10)) {
26
+            	$obj = $date;
27
+            }
28
+        } catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date
22 29
         }
23 30
         return $obj;
24 31
     }
@@ -32,11 +39,18 @@  discard block
 block discarded – undo
32 39
     }
33 40
 
34 41
 	private function checkCache($obj, $reset) {
35
-		if ($reset) $this->processCache = new \SplObjectStorage();
36
-        if (!is_object($obj)) return false;
42
+		if ($reset) {
43
+			$this->processCache = new \SplObjectStorage();
44
+		}
45
+        if (!is_object($obj)) {
46
+        	return false;
47
+        }
37 48
 
38
-		if ($this->processCache->contains($obj)) return $obj;
39
-		else $this->processCache->attach($obj, true);
49
+		if ($this->processCache->contains($obj)) {
50
+			return $obj;
51
+		} else {
52
+			$this->processCache->attach($obj, true);
53
+		}
40 54
 
41 55
 		return false;
42 56
 	}
Please login to merge, or discard this patch.
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/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 !(Maphper::FIND_OR & $mode);
28 31
         };
@@ -31,22 +34,31 @@  discard block
 block discarded – undo
31 34
     private function getIfFieldMatches($key, $val, $data, $mode) {
32 35
         if (is_numeric($key) && is_array($val)) {
33 36
             return $this->getSearchFieldFunction($val, $key)($data);
37
+        } else if (!isset($data->$key)) {
38
+        	return false;
39
+        } else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($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 (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($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 processFilter($mode, $expected, $actual) {
43
-        if (Maphper::FIND_NOT & $mode) return $expected != $actual;
44
-        else if ((Maphper::FIND_GREATER | Maphper::FIND_EXACT) === $mode) return $expected <= $actual;
45
-        else if ((Maphper::FIND_LESS | Maphper::FIND_EXACT) === $mode) return $expected >= $actual;
46
-        else if (Maphper::FIND_GREATER & $mode) return $expected < $actual;
47
-        else if (Maphper::FIND_LESS & $mode) return $expected > $actual;
48
-        else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1];
49
-        else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual);
47
+        if (Maphper::FIND_NOT & $mode) {
48
+        	return $expected != $actual;
49
+        } else if ((Maphper::FIND_GREATER | Maphper::FIND_EXACT) === $mode) {
50
+        	return $expected <= $actual;
51
+        } else if ((Maphper::FIND_LESS | Maphper::FIND_EXACT) === $mode) {
52
+        	return $expected >= $actual;
53
+        } else if (Maphper::FIND_GREATER & $mode) {
54
+        	return $expected < $actual;
55
+        } else if (Maphper::FIND_LESS & $mode) {
56
+        	return $expected > $actual;
57
+        } else if (Maphper::FIND_BETWEEN & $mode) {
58
+        	return $expected[0] <= $actual && $actual <= $expected[1];
59
+        } else if (Maphper::FIND_NOCASE & $mode) {
60
+        	return strtolower($expected) == strtolower($actual);
61
+        }
50 62
         return $expected == $actual;
51 63
     }
52 64
 }
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/Sql/WhereBuilder.php 1 patch
Braces   +25 added lines, -10 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
             $sql = array_merge($sql, (array)$result['sql']);
33 37
             $args = array_merge($args, $result['args']);
@@ -40,29 +44,40 @@  discard block
 block discarded – undo
40 44
      * Either get sql from a conditional or call createSql again because the mode needs to be changed
41 45
      */
42 46
     private function getResult($key, $value, $mode) {
43
-        if (is_numeric($key) && is_array($value)) return $this->createSql($value, $key);
47
+        if (is_numeric($key) && is_array($value)) {
48
+        	return $this->createSql($value, $key);
49
+        }
44 50
         return $this->getConditional($key, $value, $mode);
45 51
     }
46 52
 
47 53
     private function sqlArrayToString($sql, $mode) {
48
-        if (\Maphper\Maphper::FIND_OR & $mode) $query = implode(' OR  ', $sql);
49
-		else $query = implode(' AND ', $sql);
50
-		if (!empty($query)) $query = '(' . $query . ')';
54
+        if (\Maphper\Maphper::FIND_OR & $mode) {
55
+        	$query = implode(' OR  ', $sql);
56
+        } else {
57
+			$query = implode(' AND ', $sql);
58
+		}
59
+		if (!empty($query)) {
60
+			$query = '(' . $query . ')';
61
+		}
51 62
         return $query;
52 63
     }
53 64
 
54 65
     private function getConditional($key, $value, $mode) {
55 66
         foreach ($this->conditionals as $conditional) {
56
-            if ($conditional->matches($key, $value, $mode))
57
-                return $conditional->getSql($key, $value, $mode);
67
+            if ($conditional->matches($key, $value, $mode)) {
68
+                            return $conditional->getSql($key, $value, $mode);
69
+            }
58 70
         }
59 71
         throw new \Exception("Invalid WHERE query");
60 72
     }
61 73
 
62 74
     private function convertDates($value) {
63 75
         if ($value instanceof \DateTime) {
64
-            if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
65
-            else $value = $value->format('Y-m-d H:i:s');
76
+            if ($value->format('H:i:s')  == '00:00:00') {
77
+            	$value = $value->format('Y-m-d');
78
+            } else {
79
+            	$value = $value->format('Y-m-d H:i:s');
80
+            }
66 81
         }
67 82
         return $value;
68 83
     }
Please login to merge, or discard this patch.