Passed
Push — master ( e288dc...71d24f )
by Richard
01:40
created
maphper/lib/Sql/Like.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -3,18 +3,18 @@
 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 & $mode || Maphper::FIND_STARTS & $mode ||
8
-                Maphper::FIND_ENDS & $mode || Maphper::FIND_NOCASE & $mode;
9
-    }
6
+	public function matches($key, $value, $mode) {
7
+		return Maphper::FIND_LIKE & $mode || Maphper::FIND_STARTS & $mode ||
8
+				Maphper::FIND_ENDS & $mode || Maphper::FIND_NOCASE & $mode;
9
+	}
10 10
 
11
-    public function getSql($key, $value, $mode) {
12
-        if (Maphper::FIND_LIKE & $mode || Maphper::FIND_STARTS & $mode) $value = '%' . $value;
13
-        if (Maphper::FIND_LIKE & $mode || Maphper::FIND_ENDS & $mode) $value .= '%';
11
+	public function getSql($key, $value, $mode) {
12
+		if (Maphper::FIND_LIKE & $mode || Maphper::FIND_STARTS & $mode) $value = '%' . $value;
13
+		if (Maphper::FIND_LIKE & $mode || Maphper::FIND_ENDS & $mode) $value .= '%';
14 14
 
15
-        return [
16
-            'sql' => [$key . ' LIKE :' . $key],
17
-            'args' => [$key => $value]
18
-        ];
19
-    }
15
+		return [
16
+			'sql' => [$key . ' LIKE :' . $key],
17
+			'args' => [$key => $value]
18
+		];
19
+	}
20 20
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,8 +9,12 @@
 block discarded – undo
9 9
     }
10 10
 
11 11
     public function getSql($key, $value, $mode) {
12
-        if (Maphper::FIND_LIKE & $mode || Maphper::FIND_STARTS & $mode) $value = '%' . $value;
13
-        if (Maphper::FIND_LIKE & $mode || Maphper::FIND_ENDS & $mode) $value .= '%';
12
+        if (Maphper::FIND_LIKE & $mode || Maphper::FIND_STARTS & $mode) {
13
+        	$value = '%' . $value;
14
+        }
15
+        if (Maphper::FIND_LIKE & $mode || Maphper::FIND_ENDS & $mode) {
16
+        	$value .= '%';
17
+        }
14 18
 
15 19
         return [
16 20
             'sql' => [$key . ' LIKE :' . $key],
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/WhereBuilder.php 3 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -2,62 +2,62 @@
 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
-    //Needs to be broken up into better methods
23
+	//Needs to be broken up into better methods
24 24
 	public function createSql($fields, $mode = \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND){
25 25
 		$args = [];
26 26
 		$sql = [];
27 27
 
28
-        foreach ($fields as $key => $value) {
29
-            $value = $this->convertDates($value);
28
+		foreach ($fields as $key => $value) {
29
+			$value = $this->convertDates($value);
30 30
 
31
-            if (is_object($value)) continue;
31
+			if (is_object($value)) continue;
32 32
 			if (is_numeric($key) && is_array($value)) {
33 33
 				$result = $this->createSql($value, $key);
34 34
 			}
35
-            else {
36
-                $result = $this->getConditional($key, $value, $mode);
37
-            }
38
-            $sql = array_merge($sql, $result['sql']);
39
-            $args = array_merge($args, $result['args']);
40
-        }
41
-
42
-        if (\Maphper\Maphper::FIND_OR & $mode) $query = implode(' OR  ', $sql);
35
+			else {
36
+				$result = $this->getConditional($key, $value, $mode);
37
+			}
38
+			$sql = array_merge($sql, $result['sql']);
39
+			$args = array_merge($args, $result['args']);
40
+		}
41
+
42
+		if (\Maphper\Maphper::FIND_OR & $mode) $query = implode(' OR  ', $sql);
43 43
 		else $query = implode(' AND ', $sql);
44 44
 		if (!empty($query)) $query = '(' . $query . ')';
45 45
 		return ['args' => $args, 'sql' => $query];
46 46
 	}
47 47
 
48
-    private function getConditional($key, $value, $mode) {
49
-        foreach ($this->conditionals as $conditional) {
50
-            if ($conditional->matches($key, $value, $mode))
51
-                return $conditional->getSql($key, $value, $mode);
52
-        }
53
-        throw new \Exception("Invalid WHERE query");
54
-    }
55
-
56
-    private function convertDates($value) {
57
-        if ($value instanceof \DateTime) {
58
-            if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
59
-            else $value = $value->format('Y-m-d H:i:s');
60
-        }
61
-        return $value;
62
-    }
48
+	private function getConditional($key, $value, $mode) {
49
+		foreach ($this->conditionals as $conditional) {
50
+			if ($conditional->matches($key, $value, $mode))
51
+				return $conditional->getSql($key, $value, $mode);
52
+		}
53
+		throw new \Exception("Invalid WHERE query");
54
+	}
55
+
56
+	private function convertDates($value) {
57
+		if ($value instanceof \DateTime) {
58
+			if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
59
+			else $value = $value->format('Y-m-d H:i:s');
60
+		}
61
+		return $value;
62
+	}
63 63
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     }
22 22
 
23 23
     //Needs to be broken up into better methods
24
-	public function createSql($fields, $mode = \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND){
24
+	public function createSql($fields, $mode = \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND) {
25 25
 		$args = [];
26 26
 		$sql = [];
27 27
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
     private function convertDates($value) {
57 57
         if ($value instanceof \DateTime) {
58
-            if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
58
+            if ($value->format('H:i:s') == '00:00:00') $value = $value->format('Y-m-d');
59 59
             else $value = $value->format('Y-m-d H:i:s');
60 60
         }
61 61
         return $value;
Please login to merge, or discard this patch.
Braces   +23 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) {
@@ -28,35 +30,45 @@  discard block
 block discarded – undo
28 30
         foreach ($fields as $key => $value) {
29 31
             $value = $this->convertDates($value);
30 32
 
31
-            if (is_object($value)) continue;
33
+            if (is_object($value)) {
34
+            	continue;
35
+            }
32 36
 			if (is_numeric($key) && is_array($value)) {
33 37
 				$result = $this->createSql($value, $key);
34
-			}
35
-            else {
38
+			} else {
36 39
                 $result = $this->getConditional($key, $value, $mode);
37 40
             }
38 41
             $sql = array_merge($sql, $result['sql']);
39 42
             $args = array_merge($args, $result['args']);
40 43
         }
41 44
 
42
-        if (\Maphper\Maphper::FIND_OR & $mode) $query = implode(' OR  ', $sql);
43
-		else $query = implode(' AND ', $sql);
44
-		if (!empty($query)) $query = '(' . $query . ')';
45
+        if (\Maphper\Maphper::FIND_OR & $mode) {
46
+        	$query = implode(' OR  ', $sql);
47
+        } else {
48
+			$query = implode(' AND ', $sql);
49
+		}
50
+		if (!empty($query)) {
51
+			$query = '(' . $query . ')';
52
+		}
45 53
 		return ['args' => $args, 'sql' => $query];
46 54
 	}
47 55
 
48 56
     private function getConditional($key, $value, $mode) {
49 57
         foreach ($this->conditionals as $conditional) {
50
-            if ($conditional->matches($key, $value, $mode))
51
-                return $conditional->getSql($key, $value, $mode);
58
+            if ($conditional->matches($key, $value, $mode)) {
59
+                            return $conditional->getSql($key, $value, $mode);
60
+            }
52 61
         }
53 62
         throw new \Exception("Invalid WHERE query");
54 63
     }
55 64
 
56 65
     private function convertDates($value) {
57 66
         if ($value instanceof \DateTime) {
58
-            if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
59
-            else $value = $value->format('Y-m-d H:i:s');
67
+            if ($value->format('H:i:s')  == '00:00:00') {
68
+            	$value = $value->format('Y-m-d');
69
+            } else {
70
+            	$value = $value->format('Y-m-d H:i:s');
71
+            }
60 72
         }
61 73
         return $value;
62 74
     }
Please login to merge, or discard this patch.
maphper/lib/Sql/In.php 3 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -2,21 +2,21 @@
 block discarded – undo
2 2
 namespace Maphper\Lib\Sql;
3 3
 
4 4
 class In implements WhereConditional {
5
-    public function matches($key, $value, $mode) {
6
-        return !is_numeric($key) && is_array($value);
7
-    }
5
+	public function matches($key, $value, $mode) {
6
+		return !is_numeric($key) && is_array($value);
7
+	}
8 8
 
9
-    public function getSql($key, $value, $mode) {
10
-        $args = [];
11
-        $inSql = [];
12
-        $count = count($value);
13
-        for ($i = 0; $i < $count; $i++) {
14
-            $args[$key . $i] = $value[$i];
15
-            $inSql[] = ':' . $key . $i;
16
-        }
17
-        if (count($inSql) == 0) return [];
18
-        else $sql = [$key . ' IN ( ' .  implode(', ', $inSql) . ')'];
9
+	public function getSql($key, $value, $mode) {
10
+		$args = [];
11
+		$inSql = [];
12
+		$count = count($value);
13
+		for ($i = 0; $i < $count; $i++) {
14
+			$args[$key . $i] = $value[$i];
15
+			$inSql[] = ':' . $key . $i;
16
+		}
17
+		if (count($inSql) == 0) return [];
18
+		else $sql = [$key . ' IN ( ' .  implode(', ', $inSql) . ')'];
19 19
 
20
-        return ['args' => $args, 'sql' => $sql];
21
-    }
20
+		return ['args' => $args, 'sql' => $sql];
21
+	}
22 22
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
             $inSql[] = ':' . $key . $i;
16 16
         }
17 17
         if (count($inSql) == 0) return [];
18
-        else $sql = [$key . ' IN ( ' .  implode(', ', $inSql) . ')'];
18
+        else $sql = [$key . ' IN ( ' . implode(', ', $inSql) . ')'];
19 19
 
20 20
         return ['args' => $args, 'sql' => $sql];
21 21
     }
Please login to merge, or discard this 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.
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/GeneralOperator.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -3,28 +3,28 @@
 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 & $mode || Maphper::FIND_GREATER & $mode ||
8
-                Maphper::FIND_LESS & $mode || Maphper::FIND_NOT & $mode || Maphper::FIND_EXACT & $mode;
9
-    }
6
+	public function matches($key, $value, $mode) {
7
+		return Maphper::FIND_BIT & $mode || Maphper::FIND_GREATER & $mode ||
8
+				Maphper::FIND_LESS & $mode || Maphper::FIND_NOT & $mode || 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
-        $operator = "";
18
+	private function getOperator($mode) {
19
+		$operator = "";
20 20
 
21
-        if (\Maphper\Maphper::FIND_BIT & $mode) $operator = '&';
22
-        else if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
23
-        else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
24
-        else if (\Maphper\Maphper::FIND_NOT & $mode) $operator = '!=';
21
+		if (\Maphper\Maphper::FIND_BIT & $mode) $operator = '&';
22
+		else if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
23
+		else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
24
+		else if (\Maphper\Maphper::FIND_NOT & $mode) $operator = '!=';
25 25
 
26
-        if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
26
+		if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
27 27
 
28
-        return $operator;
29
-    }
28
+		return $operator;
29
+	}
30 30
 }
Please login to merge, or discard this patch.
Braces   +12 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,12 +18,19 @@
 block discarded – undo
18 18
     private function getOperator($mode) {
19 19
         $operator = "";
20 20
 
21
-        if (\Maphper\Maphper::FIND_BIT & $mode) $operator = '&';
22
-        else if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
23
-        else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
24
-        else if (\Maphper\Maphper::FIND_NOT & $mode) $operator = '!=';
21
+        if (\Maphper\Maphper::FIND_BIT & $mode) {
22
+        	$operator = '&';
23
+        } else if (\Maphper\Maphper::FIND_GREATER & $mode) {
24
+        	$operator = '>';
25
+        } else if (\Maphper\Maphper::FIND_LESS & $mode) {
26
+        	$operator = '<';
27
+        } else if (\Maphper\Maphper::FIND_NOT & $mode) {
28
+        	$operator = '!=';
29
+        }
25 30
 
26
-        if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
31
+        if (\Maphper\Maphper::FIND_EXACT & $mode) {
32
+        	$operator .= '=';
33
+        }
27 34
 
28 35
         return $operator;
29 36
     }
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.