Passed
Push — master ( b771a6...8c8288 )
by Richard
02:06
created
Maphper/Maphper.php 1 patch
Braces   +25 added lines, -9 removed lines patch added patch discarded remove patch
@@ -61,7 +61,9 @@  discard block
 block discarded – undo
61 61
 
62 62
 		$siblings = new \ArrayObject();
63 63
 
64
-		foreach ($results as &$result) $result = $this->entity->create($result, $this->relations, $siblings);
64
+		foreach ($results as &$result) {
65
+			$result = $this->entity->create($result, $this->relations, $siblings);
66
+		}
65 67
 
66 68
 		return $results;
67 69
 	}
@@ -78,13 +80,17 @@  discard block
 block discarded – undo
78 80
 	private function processFilters($value) {
79 81
 		//When saving to a mapper with filters, write the filters back into the object being stored
80 82
 		foreach ($this->settings['filter'] as $key => $filterValue) {
81
-			if (empty($value->$key) && !is_array($filterValue)) $value->$key = $filterValue;
83
+			if (empty($value->$key) && !is_array($filterValue)) {
84
+				$value->$key = $filterValue;
85
+			}
82 86
 		}
83 87
 		return $value;
84 88
 	}
85 89
 
86 90
 	public function offsetSet($offset, $valueObj) {
87
-		if ($valueObj instanceof \Maphper\Relation) throw new \Exception();
91
+		if ($valueObj instanceof \Maphper\Relation) {
92
+			throw new \Exception();
93
+		}
88 94
 
89 95
 		//Extract private properties from the object
90 96
 		$visibilityOverride = new \Maphper\Lib\VisibilityOverride($valueObj);
@@ -92,7 +98,9 @@  discard block
 block discarded – undo
92 98
 
93 99
 		$value = $this->processFilters($value);
94 100
 		$pk = $this->dataSource->getPrimaryKey();
95
-		if ($offset !== null) $value->{$pk[0]} = $offset;
101
+		if ($offset !== null) {
102
+			$value->{$pk[0]} = $offset;
103
+		}
96 104
 		$valueCopy = clone $value;
97 105
 		$value = $this->entity->wrap($this->relations, $value);
98 106
 		$this->dataSource->save($value);
@@ -104,7 +112,9 @@  discard block
 block discarded – undo
104 112
 	}
105 113
 
106 114
 	public function offsetExists($offset) {
107
-		if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey());
115
+		if (count($this->dataSource->getPrimaryKey()) > 1) {
116
+			return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey());
117
+		}
108 118
         if (!empty($this->settings['filter'])) {
109 119
             $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset]));
110 120
             return isset($data[0]);
@@ -117,7 +127,9 @@  discard block
 block discarded – undo
117 127
 	}
118 128
 
119 129
 	public function offsetGet($offset) {
120
-		if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey());
130
+		if (count($this->dataSource->getPrimaryKey()) > 1) {
131
+			return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey());
132
+		}
121 133
         if (!empty($this->settings['filter'])) {
122 134
             $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset]));
123 135
             return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations);
@@ -128,11 +140,15 @@  discard block
 block discarded – undo
128 140
 	public function __call($method, $args) {
129 141
 		if (array_key_exists($method, $this->settings)) {
130 142
 			$maphper = new Maphper($this->dataSource, $this->settings, $this->relations);
131
-			if (is_array($maphper->settings[$method])) $maphper->settings[$method] = $args[0] + $maphper->settings[$method];
132
-			else $maphper->settings[$method] = $args[0];
143
+			if (is_array($maphper->settings[$method])) {
144
+				$maphper->settings[$method] = $args[0] + $maphper->settings[$method];
145
+			} else {
146
+				$maphper->settings[$method] = $args[0];
147
+			}
133 148
 			return $maphper;
149
+		} else {
150
+			throw new \Exception('Method Maphper::' . $method . ' does not exist');
134 151
 		}
135
-		else throw new \Exception('Method Maphper::' . $method . ' does not exist');
136 152
 	}
137 153
 
138 154
 	public function findAggregate($function, $field, $group = null) {
Please login to merge, or discard this patch.
Maphper/Iterator.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@
 block discarded – undo
20 20
 		if (count($this->pk) == 1) {
21 21
 			$pk = end($this->pk);
22 22
 			return $this->array[$this->iterator]->$pk;
23
-		}
24
-		else {
23
+		} else {
25 24
 			$current = $this->current();
26 25
 			return array_map(function($pkName) use ($current) {
27 26
 				return $current->$pkName;
Please login to merge, or discard this patch.
Maphper/Lib/SelectBuilder.php 1 patch
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,17 +7,23 @@
 block discarded – undo
7 7
 
8 8
 		if (isset($options['offset'])) {
9 9
 			$offset = ' OFFSET ' . $options['offset'];
10
-			if (!$limit) $limit = ' LIMIT  1000';
10
+			if (!$limit) {
11
+				$limit = ' LIMIT  1000';
12
+			}
13
+		} else {
14
+			$offset = '';
11 15
 		}
12
-		else $offset = '';
13 16
 
14 17
 		$order = isset($options['order']) ? ' ORDER BY ' . $options['order'] : '';
15 18
 		return new Query('SELECT * FROM ' . $table . ' ' . $where . $order . $limit . $offset, $args);
16 19
 	}
17 20
 
18 21
 	public function aggregate($table, $function, $field, $where, $args, $group) {
19
-		if ($group == true) $groupBy = ' GROUP BY ' . $field;
20
-		else $groupBy = '';
22
+		if ($group == true) {
23
+			$groupBy = ' GROUP BY ' . $field;
24
+		} else {
25
+			$groupBy = '';
26
+		}
21 27
 		return new Query('SELECT ' . $function . '(' . $field . ') as val, ' . $field . '   FROM ' . $table . ($where != null ? ' WHERE ' . $where : '') . ' ' . $groupBy, $args);
22 28
 	}
23 29
 }
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/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/In.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,8 +14,11 @@
 block discarded – undo
14 14
             $args[$key . $i] = $value[$i];
15 15
             $inSql[] = ':' . $key . $i;
16 16
         }
17
-        if (count($inSql) == 0) return [];
18
-        else $sql = [$key . ' IN ( ' .  implode(', ', $inSql) . ')'];
17
+        if (count($inSql) == 0) {
18
+        	return [];
19
+        } else {
20
+        	$sql = [$key . ' IN ( ' .  implode(', ', $inSql) . ')'];
21
+        }
19 22
 
20 23
         return ['args' => $args, 'sql' => $sql];
21 24
     }
Please login to merge, or discard this patch.