Passed
Pull Request — master (#70)
by Christian
01:42 queued 19s
created
Maphper/Lib/Entity.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 	private $parent;
9 9
 
10 10
 	public function __construct(\Maphper\Maphper $parent, $className = null) {
11
-        $this->parent = $parent;
11
+		$this->parent = $parent;
12 12
 		$this->className = $className;
13 13
 	}
14 14
 
@@ -25,12 +25,12 @@  discard block
 block discarded – undo
25 25
 		return $object;
26 26
 	}
27 27
 
28
-    private function addRelationData($object, $name, $relation, $siblings) {
29
-        if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation) ) {
30
-            //After overwriting the relation, does the parent object ($object) need overwriting as well?
31
-            if ($relation->overwrite($object, $object->$name)) $this->parent[] = $object;
32
-        }
28
+	private function addRelationData($object, $name, $relation, $siblings) {
29
+		if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation) ) {
30
+			//After overwriting the relation, does the parent object ($object) need overwriting as well?
31
+			if ($relation->overwrite($object, $object->$name)) $this->parent[] = $object;
32
+		}
33 33
 
34
-        $object->$name = $relation->getData($object, $siblings);
35
-    }
34
+		$object->$name = $relation->getData($object, $siblings);
35
+	}
36 36
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 	}
27 27
 
28 28
     private function addRelationData($object, $name, $relation, $siblings) {
29
-        if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation) ) {
29
+        if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation)) {
30 30
             //After overwriting the relation, does the parent object ($object) need overwriting as well?
31 31
             if ($relation->overwrite($object, $object->$name)) $this->parent[] = $object;
32 32
         }
Please login to merge, or discard this 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 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 	public function delete($table, $criteria, $args, $limit = null, $offset = null, $order = null) {
9 9
 		$limit = $limit ? ' LIMIT ' . $limit : '';
10 10
 		$offset = $offset ? ' OFFSET ' . $offset : '';
11
-        $order = $order ? ' ORDER BY ' . $order : '';
11
+		$order = $order ? ' ORDER BY ' . $order : '';
12 12
 		return new Query('DELETE FROM ' . $table . ' WHERE ' . ($criteria ?: '1 = 1 ') . $order . $limit . $offset, $args);
13 13
 	}
14 14
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
 			//For dates with times set, search on time, if the time is not set, search on date only.
21 21
 			//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
22 22
 			if ($value instanceof \DateTimeInterface) {
23
-				if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
23
+				if ($value->format('H:i:s') == '00:00:00') $value = $value->format('Y-m-d');
24 24
 				else $value = $value->format('Y-m-d H:i:s');
25 25
 			}
26 26
 			if (is_object($value)) continue;
27
-			if ($prependField){
27
+			if ($prependField) {
28 28
 				$sql[] = $this->quote($field) . ' = :' . $field;
29 29
 			} else {
30 30
 				$sql[] = ':' . $field;
@@ -36,13 +36,13 @@  discard block
 block discarded – undo
36 36
 
37 37
 	public function insert($table, $data) {
38 38
 		$query = $this->buildSaveQuery($data);
39
-		return new Query('INSERT INTO ' . $this->quote($table) . ' (' .implode(', ', array_keys($query['args'])).') VALUES ( ' . implode(', ', $query['sql']). ' )', $query['args']);
39
+		return new Query('INSERT INTO ' . $this->quote($table) . ' (' . implode(', ', array_keys($query['args'])) . ') VALUES ( ' . implode(', ', $query['sql']) . ' )', $query['args']);
40 40
 	}
41 41
 
42 42
 	public function update($table, array $primaryKey, $data) {
43 43
 		$query = $this->buildSaveQuery($data, true);
44 44
 		$where = [];
45
-		foreach($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field;
46
-		return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']). ' WHERE '. implode(' AND ', $where), $query['args']);
45
+		foreach ($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field;
46
+		return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']) . ' WHERE ' . implode(' AND ', $where), $query['args']);
47 47
 	}
48 48
 }
Please login to merge, or discard this patch.
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,10 +20,15 @@  discard block
 block discarded – undo
20 20
 			//For dates with times set, search on time, if the time is not set, search on date only.
21 21
 			//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
22 22
 			if ($value instanceof \DateTimeInterface) {
23
-				if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
24
-				else $value = $value->format('Y-m-d H:i:s');
23
+				if ($value->format('H:i:s')  == '00:00:00') {
24
+					$value = $value->format('Y-m-d');
25
+				} else {
26
+					$value = $value->format('Y-m-d H:i:s');
27
+				}
28
+			}
29
+			if (is_object($value)) {
30
+				continue;
25 31
 			}
26
-			if (is_object($value)) continue;
27 32
 			if ($prependField){
28 33
 				$sql[] = $this->quote($field) . ' = :' . $field;
29 34
 			} else {
@@ -42,7 +47,9 @@  discard block
 block discarded – undo
42 47
 	public function update($table, array $primaryKey, $data) {
43 48
 		$query = $this->buildSaveQuery($data, true);
44 49
 		$where = [];
45
-		foreach($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field;
50
+		foreach($primaryKey as $field) {
51
+			$where[] = $this->quote($field) . ' = :' . $field;
52
+		}
46 53
 		return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']). ' WHERE '. implode(' AND ', $where), $query['args']);
47 54
 	}
48 55
 }
Please login to merge, or discard this patch.
Maphper/Lib/ArrayFilter.php 3 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -3,58 +3,58 @@
 block discarded – undo
3 3
 use Maphper\Maphper;
4 4
 
5 5
 class ArrayFilter {
6
-    private $array;
7
-
8
-    public function __construct(array $array) {
9
-        $this->array = $array;
10
-    }
11
-
12
-    public function filter($fields) {
13
-        $filteredArray = array_filter($this->array, $this->getSearchFieldFunction($fields, \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND));
14
-        // Need to reset indexes
15
-        $filteredArray = array_values($filteredArray);
16
-        return $filteredArray;
17
-    }
18
-
19
-    private function getSearchFieldFunction($fields, $mode) {
20
-        return function ($data) use ($fields, $mode) {
21
-            foreach ($fields as $key => $val) {
22
-                $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode);
23
-
24
-                if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true;
25
-                else if (Maphper::FIND_OR ^ $mode && $currentFieldResult === false) return false;
26
-            }
27
-            return (bool)(Maphper::FIND_OR ^ $mode);
28
-        };
29
-    }
30
-
31
-    private function getIfFieldMatches($key, $val, $data, $mode) {
32
-        if ($this->shouldRunDeepSearch($key, $val)) {
33
-            return $this->getSearchFieldFunction($val, $key)($data);
34
-        }
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
-    }
41
-
42
-    private function shouldRunDeepSearch($key, $val) {
43
-        return is_numeric($key) && is_array($val);
44
-    }
45
-
46
-    private function isInArraySearch($mode, $key, $val) {
47
-        return !(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val);
48
-    }
49
-
50
-    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);
58
-        return $expected == $actual;
59
-    }
6
+	private $array;
7
+
8
+	public function __construct(array $array) {
9
+		$this->array = $array;
10
+	}
11
+
12
+	public function filter($fields) {
13
+		$filteredArray = array_filter($this->array, $this->getSearchFieldFunction($fields, \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND));
14
+		// Need to reset indexes
15
+		$filteredArray = array_values($filteredArray);
16
+		return $filteredArray;
17
+	}
18
+
19
+	private function getSearchFieldFunction($fields, $mode) {
20
+		return function ($data) use ($fields, $mode) {
21
+			foreach ($fields as $key => $val) {
22
+				$currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode);
23
+
24
+				if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true;
25
+				else if (Maphper::FIND_OR ^ $mode && $currentFieldResult === false) return false;
26
+			}
27
+			return (bool)(Maphper::FIND_OR ^ $mode);
28
+		};
29
+	}
30
+
31
+	private function getIfFieldMatches($key, $val, $data, $mode) {
32
+		if ($this->shouldRunDeepSearch($key, $val)) {
33
+			return $this->getSearchFieldFunction($val, $key)($data);
34
+		}
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
+	}
41
+
42
+	private function shouldRunDeepSearch($key, $val) {
43
+		return is_numeric($key) && is_array($val);
44
+	}
45
+
46
+	private function isInArraySearch($mode, $key, $val) {
47
+		return !(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val);
48
+	}
49
+
50
+	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);
58
+		return $expected == $actual;
59
+	}
60 60
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
     }
34 34
 
35 35
     private function getSearchFieldFunction($fields, $mode) {
36
-        return function ($data) use ($fields, $mode) {
36
+        return function($data) use ($fields, $mode) {
37 37
             foreach ($fields as $key => $val) {
38 38
                 $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode);
39 39
 
Please login to merge, or discard this 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 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -2,15 +2,15 @@
 block discarded – undo
2 2
 namespace Maphper\Lib\Sql;
3 3
 
4 4
 class NullConditional implements WhereConditional {
5
-    public function matches($key, $value, $mode) {
6
-        return $value === NULL;
7
-    }
5
+	public function matches($key, $value, $mode) {
6
+		return $value === NULL;
7
+	}
8 8
 
9
-    public function getSql($key, $value, $mode) {
10
-        $nullSql = $key . ' IS ';
11
-        if (\Maphper\Maphper::FIND_NOT & $mode) $nullSql .= 'NOT ';
12
-        $sql = [$nullSql . 'NULL'];
9
+	public function getSql($key, $value, $mode) {
10
+		$nullSql = $key . ' IS ';
11
+		if (\Maphper\Maphper::FIND_NOT & $mode) $nullSql .= 'NOT ';
12
+		$sql = [$nullSql . 'NULL'];
13 13
 
14
-        return ['args' => [], 'sql' => $sql];
15
-    }
14
+		return ['args' => [], 'sql' => $sql];
15
+	}
16 16
 }
Please login to merge, or discard this 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/WhereConditional.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,6 +2,6 @@
 block discarded – undo
2 2
 namespace Maphper\Lib\Sql;
3 3
 
4 4
 interface WhereConditional {
5
-    public function matches($key, $value, $mode);
6
-    public function getSql($key, $value, $mode);
5
+	public function matches($key, $value, $mode);
6
+	public function getSql($key, $value, $mode);
7 7
 }
Please login to merge, or discard this patch.
Maphper/Lib/Sql/Between.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -2,20 +2,20 @@
 block discarded – undo
2 2
 namespace Maphper\Lib\Sql;
3 3
 
4 4
 class Between implements WhereConditional {
5
-    public function matches($key, $value, $mode) {
6
-        return is_array($value) && \Maphper\Maphper::FIND_BETWEEN & $mode;
7
-    }
5
+	public function matches($key, $value, $mode) {
6
+		return is_array($value) && \Maphper\Maphper::FIND_BETWEEN & $mode;
7
+	}
8 8
 
9
-    public function getSql($key, $value, $mode) {
10
-        return [
11
-            'sql' => [
12
-                $key . '>= :' . $key . 'from',
13
-                $key . ' <= :' . $key . 'to'
14
-            ],
15
-            'args' => [
16
-                $key . 'from' => $value[0],
17
-                $key . 'to' => $value[1]
18
-            ]
19
-        ];
20
-    }
9
+	public function getSql($key, $value, $mode) {
10
+		return [
11
+			'sql' => [
12
+				$key . '>= :' . $key . 'from',
13
+				$key . ' <= :' . $key . 'to'
14
+			],
15
+			'args' => [
16
+				$key . 'from' => $value[0],
17
+				$key . 'to' => $value[1]
18
+			]
19
+		];
20
+	}
21 21
 }
Please login to merge, or discard this patch.
Maphper/Lib/Sql/Like.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -3,21 +3,21 @@
 block discarded – undo
3 3
 use Maphper\Maphper;
4 4
 
5 5
 class Like implements WhereConditional {
6
-    public function matches($key, $value, $mode) {
7
-        return (Maphper::FIND_LIKE | Maphper::FIND_STARTS |
8
-                Maphper::FIND_ENDS | Maphper::FIND_NOCASE) & $mode;
9
-    }
6
+	public function matches($key, $value, $mode) {
7
+		return (Maphper::FIND_LIKE | Maphper::FIND_STARTS |
8
+				Maphper::FIND_ENDS | Maphper::FIND_NOCASE) & $mode;
9
+	}
10 10
 
11
-    public function getSql($key, $value, $mode) {
12
-        return [
13
-            'sql' => [$key . ' LIKE :' . $key],
14
-            'args' => [$key => $this->getValue($value, $mode)]
15
-        ];
16
-    }
11
+	public function getSql($key, $value, $mode) {
12
+		return [
13
+			'sql' => [$key . ' LIKE :' . $key],
14
+			'args' => [$key => $this->getValue($value, $mode)]
15
+		];
16
+	}
17 17
 
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 .= '%';
21
-        return $value;
22
-    }
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 .= '%';
21
+		return $value;
22
+	}
23 23
 }
Please login to merge, or discard this 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 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -3,33 +3,33 @@
 block discarded – undo
3 3
 use Maphper\Maphper;
4 4
 
5 5
 class GeneralOperator implements WhereConditional {
6
-    public function matches($key, $value, $mode) {
7
-        return (Maphper::FIND_BIT ^ Maphper::FIND_GREATER ^ Maphper::FIND_LESS ^ Maphper::FIND_NOT & $mode)
8
-                || Maphper::FIND_EXACT & $mode;
9
-    }
6
+	public function matches($key, $value, $mode) {
7
+		return (Maphper::FIND_BIT ^ Maphper::FIND_GREATER ^ Maphper::FIND_LESS ^ Maphper::FIND_NOT & $mode)
8
+				|| Maphper::FIND_EXACT & $mode;
9
+	}
10 10
 
11
-    public function getSql($key, $value, $mode) {
12
-        return [
13
-            'sql' => [$key . ' ' . $this->getOperator($mode) . ' :' . $key],
14
-            'args' => [$key => $value]
15
-        ];
16
-    }
11
+	public function getSql($key, $value, $mode) {
12
+		return [
13
+			'sql' => [$key . ' ' . $this->getOperator($mode) . ' :' . $key],
14
+			'args' => [$key => $value]
15
+		];
16
+	}
17 17
 
18
-    private function getOperator($mode) {
19
-        if (\Maphper\Maphper::FIND_BIT & $mode) return '&';
20
-        else if (\Maphper\Maphper::FIND_NOT & $mode) return '!=';
18
+	private function getOperator($mode) {
19
+		if (\Maphper\Maphper::FIND_BIT & $mode) return '&';
20
+		else if (\Maphper\Maphper::FIND_NOT & $mode) return '!=';
21 21
 
22
-        return $this->getEqualsOperators($mode);
23
-    }
22
+		return $this->getEqualsOperators($mode);
23
+	}
24 24
 
25
-    private function getEqualsOperators($mode) {
26
-        $operator = "";
25
+	private function getEqualsOperators($mode) {
26
+		$operator = "";
27 27
 
28
-        if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
29
-        else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
28
+		if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
29
+		else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
30 30
 
31
-        if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
31
+		if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
32 32
 
33
-        return $operator;
34
-    }
33
+		return $operator;
34
+	}
35 35
 }
Please login to merge, or discard this 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 3 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -2,87 +2,87 @@
 block discarded – undo
2 2
 namespace Maphper\Lib\Sql;
3 3
 
4 4
 class WhereBuilder {
5
-    private $conditionals = [];
6
-
7
-    public function __construct() {
8
-        $defaultConditionals = [
9
-            'Maphper\Lib\Sql\Between',
10
-            'Maphper\Lib\Sql\In',
11
-            'Maphper\Lib\Sql\NullConditional',
12
-            'Maphper\Lib\Sql\Like',
13
-            'Maphper\Lib\Sql\GeneralOperator'
14
-        ];
15
-
16
-        foreach ($defaultConditionals as $conditional) $this->addConditional(new $conditional);
17
-    }
5
+	private $conditionals = [];
6
+
7
+	public function __construct() {
8
+		$defaultConditionals = [
9
+			'Maphper\Lib\Sql\Between',
10
+			'Maphper\Lib\Sql\In',
11
+			'Maphper\Lib\Sql\NullConditional',
12
+			'Maphper\Lib\Sql\Like',
13
+			'Maphper\Lib\Sql\GeneralOperator'
14
+		];
15
+
16
+		foreach ($defaultConditionals as $conditional) $this->addConditional(new $conditional);
17
+	}
18 18
 
19
-    public function addConditional(WhereConditional $conditional) {
20
-        $this->conditionals[] = $conditional;
21
-    }
19
+	public function addConditional(WhereConditional $conditional) {
20
+		$this->conditionals[] = $conditional;
21
+	}
22 22
 
23 23
 	public function createSql($fields, $mode = \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND) {
24 24
 		$args = [];
25 25
 		$sql = [];
26 26
 
27
-        foreach ($fields as $key => $value) {
28
-            $value = $this->convertDates($value);
27
+		foreach ($fields as $key => $value) {
28
+			$value = $this->convertDates($value);
29 29
 
30
-            if (is_object($value)) continue;
30
+			if (is_object($value)) continue;
31 31
 			$result = $this->getResult($key, $value, $mode);
32
-            $result = $this->fixDuplicateArgs($args, $result);
33
-            $sql = array_merge($sql, (array)$result['sql']);
34
-            $args = array_merge($args, $result['args']);
35
-        }
32
+			$result = $this->fixDuplicateArgs($args, $result);
33
+			$sql = array_merge($sql, (array)$result['sql']);
34
+			$args = array_merge($args, $result['args']);
35
+		}
36 36
 
37 37
 		return ['args' => $args, 'sql' => $this->sqlArrayToString($sql, $mode)];
38 38
 	}
39 39
 
40
-    // Returns result with duplicate issues removed
41
-    private function fixDuplicateArgs($origArgs, $result) {
42
-        $duplicates = array_intersect_key($result['args'], $origArgs); // Holds all keys in results already in the args
43
-        if (count($duplicates) === 0) return $result;
40
+	// Returns result with duplicate issues removed
41
+	private function fixDuplicateArgs($origArgs, $result) {
42
+		$duplicates = array_intersect_key($result['args'], $origArgs); // Holds all keys in results already in the args
43
+		if (count($duplicates) === 0) return $result;
44 44
 
45
-        foreach ($duplicates as $argKey => $argVal) {
46
-            $valHash = substr(md5($argVal), 0, 5);
47
-            $newKey = $argKey . $valHash;
45
+		foreach ($duplicates as $argKey => $argVal) {
46
+			$valHash = substr(md5($argVal), 0, 5);
47
+			$newKey = $argKey . $valHash;
48 48
 
49
-            // Replace occurences of duplicate key with key + hash as arg
50
-            $result['sql'] = str_replace(':' . $argKey, ':' . $newKey, $result['sql']);
51
-            unset($result['args'][$argKey]);
52
-            $result['args'][$newKey] = $argVal;
53
-        }
49
+			// Replace occurences of duplicate key with key + hash as arg
50
+			$result['sql'] = str_replace(':' . $argKey, ':' . $newKey, $result['sql']);
51
+			unset($result['args'][$argKey]);
52
+			$result['args'][$newKey] = $argVal;
53
+		}
54 54
 
55
-        return $result;
56
-    }
55
+		return $result;
56
+	}
57 57
 
58
-    /*
58
+	/*
59 59
      * Either get sql from a conditional or call createSql again because the mode needs to be changed
60 60
      */
61
-    private function getResult($key, $value, $mode) {
62
-        if (is_numeric($key) && is_array($value)) return $this->createSql($value, $key);
63
-        return $this->getConditional($key, $value, $mode);
64
-    }
61
+	private function getResult($key, $value, $mode) {
62
+		if (is_numeric($key) && is_array($value)) return $this->createSql($value, $key);
63
+		return $this->getConditional($key, $value, $mode);
64
+	}
65 65
 
66
-    private function sqlArrayToString($sql, $mode) {
67
-        if (\Maphper\Maphper::FIND_OR & $mode) $query = implode(' OR  ', $sql);
66
+	private function sqlArrayToString($sql, $mode) {
67
+		if (\Maphper\Maphper::FIND_OR & $mode) $query = implode(' OR  ', $sql);
68 68
 		else $query = implode(' AND ', $sql);
69 69
 		if (!empty($query)) $query = '(' . $query . ')';
70
-        return $query;
71
-    }
72
-
73
-    private function getConditional($key, $value, $mode) {
74
-        foreach ($this->conditionals as $conditional) {
75
-            if ($conditional->matches($key, $value, $mode))
76
-                return $conditional->getSql($key, $value, $mode);
77
-        }
78
-        throw new \Exception("Invalid WHERE query");
79
-    }
80
-
81
-    private function convertDates($value) {
82
-        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');
85
-        }
86
-        return $value;
87
-    }
70
+		return $query;
71
+	}
72
+
73
+	private function getConditional($key, $value, $mode) {
74
+		foreach ($this->conditionals as $conditional) {
75
+			if ($conditional->matches($key, $value, $mode))
76
+				return $conditional->getSql($key, $value, $mode);
77
+		}
78
+		throw new \Exception("Invalid WHERE query");
79
+	}
80
+
81
+	private function convertDates($value) {
82
+		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');
85
+		}
86
+		return $value;
87
+	}
88 88
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@
 block discarded – undo
80 80
 
81 81
     private function convertDates($value) {
82 82
         if ($value instanceof \DateTimeInterface) {
83
-            if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
83
+            if ($value->format('H:i:s') == '00:00:00') $value = $value->format('Y-m-d');
84 84
             else $value = $value->format('Y-m-d H:i:s');
85 85
         }
86 86
         return $value;
Please login to merge, or discard this 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.