Passed
Pull Request — master (#70)
by Christian
01:42 queued 19s
created
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 1 patch
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.
Maphper/Lib/Sql/GeneralOperator.php 1 patch
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.
Maphper/Lib/Sql/WhereBuilder.php 1 patch
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.
Maphper/Relation/One.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 	private $siblings = [];
10 10
 
11 11
 	public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $criteria = []) {
12
-        if ($criteria) $mapper = $mapper->filter($this->criteira);
12
+		if ($criteria) $mapper = $mapper->filter($this->criteira);
13 13
 		$this->mapper = $mapper;
14 14
 		$this->parentField = $parentField;
15 15
 		$this->localField = $localField;
@@ -48,17 +48,17 @@  discard block
 block discarded – undo
48 48
 		//Fetch the results so they're in the cache for the corresponding maphper object
49 49
 		$results = $this->mapper->filter([$this->localField => $recordsToLoad]);
50 50
 
51
-        $this->loadDataIntoSiblings($results);
51
+		$this->loadDataIntoSiblings($results);
52 52
 	}
53 53
 
54
-    private function loadDataIntoSiblings($results) {
55
-        $cache = [];
54
+	private function loadDataIntoSiblings($results) {
55
+		$cache = [];
56 56
 		foreach ($results as $result) {
57 57
 			$cache[$result->{$this->localField}] = $result;
58 58
 		}
59 59
 
60 60
 		foreach ($this->siblings as $sibling) {
61
-            if (isset($cache[$sibling->parentObject->{$this->parentField}])) $sibling->data = $cache[$sibling->parentObject->{$this->parentField}];
61
+			if (isset($cache[$sibling->parentObject->{$this->parentField}])) $sibling->data = $cache[$sibling->parentObject->{$this->parentField}];
62 62
 		}
63 63
 		/*
64 64
 		foreach ($this->siblings as $sibling) {
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 			else $sibling->data = $sibling->mapper->filter([$sibling->localField => $sibling->parentObject->{$this->parentField}])->item(0);
67 67
 		}
68 68
 		*/
69
-    }
69
+	}
70 70
 
71 71
 	public function __call($func, array $args = []) {
72 72
 		if ($this->lazyLoad() == null) return '';
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 
76 76
 	public function __get($name) {
77 77
 		if ($this->lazyLoad()) return $this->lazyLoad()->$name;
78
-        else return null;
78
+		else return null;
79 79
 	}
80 80
 
81 81
 	public function __isset($name) {
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 	}
84 84
 
85 85
 	public function overwrite($parentObject, &$data) {
86
-        $this->mapper[] = $data;
86
+		$this->mapper[] = $data;
87 87
 
88
-        if (!isset($parentObject->{$this->parentField}) || $parentObject->{$this->parentField} != $data->{$this->localField}) {
88
+		if (!isset($parentObject->{$this->parentField}) || $parentObject->{$this->parentField} != $data->{$this->localField}) {
89 89
 			$parentObject->{$this->parentField} = $data->{$this->localField};
90 90
 			//Trigger an update of the parent object
91 91
 			return true;
Please login to merge, or discard this patch.
Maphper/Relation/ManyManyIterator.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,17 +7,17 @@
 block discarded – undo
7 7
   private $intermediateName;
8 8
 
9 9
   public function __construct(\Maphper\Iterator $iterator, $intermediateName = null) {
10
-    $this->iterator = $iterator;
11
-    $this->intermediateName = $intermediateName;
10
+	$this->iterator = $iterator;
11
+	$this->intermediateName = $intermediateName;
12 12
   }
13 13
 
14 14
   public function current() {
15
-    if ($this->intermediateName) return $this->iterator->current()->{$this->intermediateName};
15
+	if ($this->intermediateName) return $this->iterator->current()->{$this->intermediateName};
16 16
 		return $this->iterator->current();
17 17
 	}
18 18
 
19 19
 	public function key() {
20
-    return $this->iterator->key();
20
+	return $this->iterator->key();
21 21
 	}
22 22
 
23 23
 	public function next() {
Please login to merge, or discard this patch.
Maphper/Relation/ManyMany.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -90,26 +90,26 @@
 block discarded – undo
90 90
 		list($relatedField, $valueField, $mapper) = $this->getOtherFieldNameInfo();
91 91
 		if ($this->autoTraverse) $this->offsetSetAutotraverse($value, $relatedField, $valueField);
92 92
 		else if ($this->doUpdateInterMapper($value, $relatedField, $valueField)) {
93
-            $record = $value;
93
+			$record = $value;
94 94
 			$record->{$this->parentField} = $value->{$this->intermediateName}->{$this->localField};
95 95
 			$record->$valueField = $this->object->{$relatedField};
96 96
 			$this->intermediateMapper[] = $record;
97 97
 		}
98 98
 	}
99 99
 
100
-    private function doUpdateInterMapper($record, $relatedField, $valueField) {
101
-        return !(isset($record->{$this->parentField}) && isset($record->{$this->intermediateName}) &&
102
-            isset($record->$valueField) && isset($this->object->{$relatedField}) &&
103
-            $record->{$this->parentField} == $record->{$this->intermediateName}->{$this->localField} &&
104
-            $record->$valueField == $this->object->{$relatedField});
105
-    }
106
-
107
-    private function offsetSetAutotraverse($value, $relatedField, $valueField) {
108
-        $record = new \stdClass;
109
-        $record->{$this->parentField} =  $value->{$this->localField};
110
-        $record->$valueField = $this->object->{$relatedField};
111
-        $this->intermediateMapper[] = $record;
112
-    }
100
+	private function doUpdateInterMapper($record, $relatedField, $valueField) {
101
+		return !(isset($record->{$this->parentField}) && isset($record->{$this->intermediateName}) &&
102
+			isset($record->$valueField) && isset($this->object->{$relatedField}) &&
103
+			$record->{$this->parentField} == $record->{$this->intermediateName}->{$this->localField} &&
104
+			$record->$valueField == $this->object->{$relatedField});
105
+	}
106
+
107
+	private function offsetSetAutotraverse($value, $relatedField, $valueField) {
108
+		$record = new \stdClass;
109
+		$record->{$this->parentField} =  $value->{$this->localField};
110
+		$record->$valueField = $this->object->{$relatedField};
111
+		$this->intermediateMapper[] = $record;
112
+	}
113 113
 
114 114
 	public function offsetUnset($id) {
115 115
 		//$this->relation->mapper->filter([$relatedField => $this->object->$valueField, $this->relation->parentField => $id])->delete();
Please login to merge, or discard this patch.
Maphper/Lib/Sql/In.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -2,28 +2,28 @@
 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
-        $value = array_values($value); // fix numeric index being different than $i
14
-        for ($i = 0; $i < $count; $i++) {
15
-            $args[$key . $i] = $value[$i];
16
-            $inSql[] = ':' . $key . $i;
17
-        }
9
+	public function getSql($key, $value, $mode) {
10
+		$args = [];
11
+		$inSql = [];
12
+		$count = count($value);
13
+		$value = array_values($value); // fix numeric index being different than $i
14
+		for ($i = 0; $i < $count; $i++) {
15
+			$args[$key . $i] = $value[$i];
16
+			$inSql[] = ':' . $key . $i;
17
+		}
18 18
 
19
-        $notText = '';
20
-        if (\Maphper\Maphper::FIND_NOT & $mode) {
21
-            $notText = ' NOT';
22
-        }
19
+		$notText = '';
20
+		if (\Maphper\Maphper::FIND_NOT & $mode) {
21
+			$notText = ' NOT';
22
+		}
23 23
 
24
-        if (count($inSql) == 0) return ['args' => [], 'sql' => ''];
25
-        else $sql = [$key . $notText . ' IN ( ' .  implode(', ', $inSql) . ')'];
24
+		if (count($inSql) == 0) return ['args' => [], 'sql' => ''];
25
+		else $sql = [$key . $notText . ' IN ( ' .  implode(', ', $inSql) . ')'];
26 26
 
27
-        return ['args' => $args, 'sql' => $sql];
28
-    }
27
+		return ['args' => $args, 'sql' => $sql];
28
+	}
29 29
 }
Please login to merge, or discard this patch.