Passed
Push — master ( 8a2369...384d23 )
by Tom
02:08
created
maphper/datasource/mock.php 3 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -2,113 +2,113 @@
 block discarded – undo
2 2
 namespace Maphper\DataSource;
3 3
 use Maphper\Maphper;
4 4
 class Mock implements \Maphper\DataSource {
5
-    private $data;
6
-    private $id;
5
+	private $data;
6
+	private $id;
7 7
 
8
-    public function __construct(\ArrayObject $data, $id) {
9
-        $this->data = $data;
10
-        $this->id = is_array($id) ? $id : [$id];
11
-    }
8
+	public function __construct(\ArrayObject $data, $id) {
9
+		$this->data = $data;
10
+		$this->id = is_array($id) ? $id : [$id];
11
+	}
12 12
 
13
-    public function getPrimaryKey() {
14
-        return $this->id;
15
-    }
13
+	public function getPrimaryKey() {
14
+		return $this->id;
15
+	}
16 16
 
17
-    public function findById($id) {
18
-        return isset($this->data[$id]) ? (array)$this->data[$id] : [];
19
-    }
17
+	public function findById($id) {
18
+		return isset($this->data[$id]) ? (array)$this->data[$id] : [];
19
+	}
20 20
 
21
-    public function findByField(array $fields, $options = []) {
22
-        $array = iterator_to_array($this->data->getIterator());
23
-        $filteredArray = array_filter($array, $this->getSearchFieldFunction($fields, \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND));
24
-        // Need to reset indexes
25
-        $filteredArray = array_values($filteredArray);
26
-        if (isset($options['order'])) {
27
-            list($columns, $order) = explode(' ', $options['order']);
28
-            usort($filteredArray, $this->getOrderFunction($order, $columns));
29
-        }
30
-        if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']);
31
-        if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']);
32
-        return $filteredArray;
33
-    }
21
+	public function findByField(array $fields, $options = []) {
22
+		$array = iterator_to_array($this->data->getIterator());
23
+		$filteredArray = array_filter($array, $this->getSearchFieldFunction($fields, \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND));
24
+		// Need to reset indexes
25
+		$filteredArray = array_values($filteredArray);
26
+		if (isset($options['order'])) {
27
+			list($columns, $order) = explode(' ', $options['order']);
28
+			usort($filteredArray, $this->getOrderFunction($order, $columns));
29
+		}
30
+		if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']);
31
+		if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']);
32
+		return $filteredArray;
33
+	}
34 34
 
35
-    private function getSearchFieldFunction($fields, $mode) {
36
-        return function ($data) use ($fields, $mode) {
37
-            foreach ($fields as $key => $val) {
38
-                $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode);
35
+	private function getSearchFieldFunction($fields, $mode) {
36
+		return function ($data) use ($fields, $mode) {
37
+			foreach ($fields as $key => $val) {
38
+				$currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode);
39 39
 
40
-                if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true;
41
-                else if (!(Maphper::FIND_OR & $mode) && $currentFieldResult === false) return false;
42
-            }
43
-            return !(Maphper::FIND_OR & $mode);
44
-        };
45
-    }
40
+				if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true;
41
+				else if (!(Maphper::FIND_OR & $mode) && $currentFieldResult === false) return false;
42
+			}
43
+			return !(Maphper::FIND_OR & $mode);
44
+		};
45
+	}
46 46
 
47
-    private function getIfFieldMatches($key, $val, $data, $mode) {
48
-        if (is_numeric($key) && is_array($val)) {
49
-            return $this->getSearchFieldFunction($val, $key)($data);
50
-        }
51
-        else if (!isset($data->$key)) return false;
52
-        else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val))
53
-            return in_array($data->$key, $val);
54
-        else
55
-            return $this->processFilter($mode, $val, $data->$key);
56
-    }
47
+	private function getIfFieldMatches($key, $val, $data, $mode) {
48
+		if (is_numeric($key) && is_array($val)) {
49
+			return $this->getSearchFieldFunction($val, $key)($data);
50
+		}
51
+		else if (!isset($data->$key)) return false;
52
+		else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val))
53
+			return in_array($data->$key, $val);
54
+		else
55
+			return $this->processFilter($mode, $val, $data->$key);
56
+	}
57 57
 
58 58
   	public function findAggregate($function, $field, $group = null, array $criteria = [], array $options = []) {
59
-        $array = iterator_to_array($this->data);
60
-        return $function($this->findByField($criteria));
61
-    }
59
+		$array = iterator_to_array($this->data);
60
+		return $function($this->findByField($criteria));
61
+	}
62 62
 
63 63
   	public function deleteById($id) {
64
-        unset($this->data[$id]);
65
-    }
64
+		unset($this->data[$id]);
65
+	}
66 66
 
67 67
   	public function deleteByField(array $fields) {
68
-        foreach ($this->findByField($fields) as $val) unset($this->data[$val->{$this->id[0]}]);
69
-    }
68
+		foreach ($this->findByField($fields) as $val) unset($this->data[$val->{$this->id[0]}]);
69
+	}
70 70
 
71
-    public function save($data) {
72
-        if (isset($data->{$this->id[0]})) {
73
-            $id = $data->{$this->id[0]};
74
-        }
75
-        else {
76
-            $id = count($this->data);
77
-            $data->{$this->id[0]} = $id;
78
-        }
71
+	public function save($data) {
72
+		if (isset($data->{$this->id[0]})) {
73
+			$id = $data->{$this->id[0]};
74
+		}
75
+		else {
76
+			$id = count($this->data);
77
+			$data->{$this->id[0]} = $id;
78
+		}
79 79
 
80
-        $this->data[$id] = (object)array_merge($this->findById($id), (array)$data);
81
-    }
80
+		$this->data[$id] = (object)array_merge($this->findById($id), (array)$data);
81
+	}
82 82
 
83
-    public function getErrors() {
84
-        return [];
85
-    }
83
+	public function getErrors() {
84
+		return [];
85
+	}
86 86
 
87
-    private function getOrderFunction($order, $columns) {
88
-        return function($a, $b) use ($order, $columns) {
89
-          foreach (explode(',', $columns) as $column) {
90
-            $aColumn = $a->$column;
91
-            $bColumn = $b->$column;
92
-            if ($aColumn === $bColumn) {
93
-              $sortVal = 0;
94
-              continue;
95
-            }
96
-            else $sortVal = ($aColumn < $bColumn) ? -1 : 1;
97
-            break;
98
-          }
99
-          if ($order === 'desc') return -$sortVal;
100
-          else return $sortVal;
101
-        };
102
-    }
87
+	private function getOrderFunction($order, $columns) {
88
+		return function($a, $b) use ($order, $columns) {
89
+		  foreach (explode(',', $columns) as $column) {
90
+			$aColumn = $a->$column;
91
+			$bColumn = $b->$column;
92
+			if ($aColumn === $bColumn) {
93
+			  $sortVal = 0;
94
+			  continue;
95
+			}
96
+			else $sortVal = ($aColumn < $bColumn) ? -1 : 1;
97
+			break;
98
+		  }
99
+		  if ($order === 'desc') return -$sortVal;
100
+		  else return $sortVal;
101
+		};
102
+	}
103 103
 
104
-    private function processFilter($mode, $expected, $actual) {
105
-        if (Maphper::FIND_NOT & $mode) return $expected != $actual;
106
-        else if (Maphper::FIND_GREATER & $mode && Maphper::FIND_EXACT & $mode) return $expected <= $actual;
107
-        else if (Maphper::FIND_LESS & $mode && Maphper::FIND_EXACT & $mode) return $expected >= $actual;
108
-        else if (Maphper::FIND_GREATER & $mode) return $expected < $actual;
109
-        else if (Maphper::FIND_LESS & $mode) return $expected > $actual;
110
-        else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1];
111
-        else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual);
112
-        return $expected == $actual;
113
-    }
104
+	private function processFilter($mode, $expected, $actual) {
105
+		if (Maphper::FIND_NOT & $mode) return $expected != $actual;
106
+		else if (Maphper::FIND_GREATER & $mode && Maphper::FIND_EXACT & $mode) return $expected <= $actual;
107
+		else if (Maphper::FIND_LESS & $mode && Maphper::FIND_EXACT & $mode) return $expected >= $actual;
108
+		else if (Maphper::FIND_GREATER & $mode) return $expected < $actual;
109
+		else if (Maphper::FIND_LESS & $mode) return $expected > $actual;
110
+		else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1];
111
+		else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual);
112
+		return $expected == $actual;
113
+	}
114 114
 }
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   +43 added lines, -22 removed lines patch added patch discarded remove patch
@@ -27,8 +27,12 @@  discard block
 block discarded – undo
27 27
             list($columns, $order) = explode(' ', $options['order']);
28 28
             usort($filteredArray, $this->getOrderFunction($order, $columns));
29 29
         }
30
-        if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']);
31
-        if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']);
30
+        if (isset($options['offset'])) {
31
+        	$filteredArray = array_slice($filteredArray, $options['offset']);
32
+        }
33
+        if (isset($options['limit'])) {
34
+        	$filteredArray = array_slice($filteredArray, 0, $options['limit']);
35
+        }
32 36
         return $filteredArray;
33 37
     }
34 38
 
@@ -37,8 +41,11 @@  discard block
 block discarded – undo
37 41
             foreach ($fields as $key => $val) {
38 42
                 $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode);
39 43
 
40
-                if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true;
41
-                else if (!(Maphper::FIND_OR & $mode) && $currentFieldResult === false) return false;
44
+                if (Maphper::FIND_OR & $mode && $currentFieldResult === true) {
45
+                	return true;
46
+                } else if (!(Maphper::FIND_OR & $mode) && $currentFieldResult === false) {
47
+                	return false;
48
+                }
42 49
             }
43 50
             return !(Maphper::FIND_OR & $mode);
44 51
         };
@@ -47,12 +54,13 @@  discard block
 block discarded – undo
47 54
     private function getIfFieldMatches($key, $val, $data, $mode) {
48 55
         if (is_numeric($key) && is_array($val)) {
49 56
             return $this->getSearchFieldFunction($val, $key)($data);
57
+        } else if (!isset($data->$key)) {
58
+        	return false;
59
+        } else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val)) {
60
+                    return in_array($data->$key, $val);
61
+        } else {
62
+                    return $this->processFilter($mode, $val, $data->$key);
50 63
         }
51
-        else if (!isset($data->$key)) return false;
52
-        else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val))
53
-            return in_array($data->$key, $val);
54
-        else
55
-            return $this->processFilter($mode, $val, $data->$key);
56 64
     }
57 65
 
58 66
   	public function findAggregate($function, $field, $group = null, array $criteria = [], array $options = []) {
@@ -65,14 +73,15 @@  discard block
 block discarded – undo
65 73
     }
66 74
 
67 75
   	public function deleteByField(array $fields) {
68
-        foreach ($this->findByField($fields) as $val) unset($this->data[$val->{$this->id[0]}]);
76
+        foreach ($this->findByField($fields) as $val) {
77
+        	unset($this->data[$val->{$this->id[0]}]);
78
+        }
69 79
     }
70 80
 
71 81
     public function save($data) {
72 82
         if (isset($data->{$this->id[0]})) {
73 83
             $id = $data->{$this->id[0]};
74
-        }
75
-        else {
84
+        } else {
76 85
             $id = count($this->data);
77 86
             $data->{$this->id[0]} = $id;
78 87
         }
@@ -92,23 +101,35 @@  discard block
 block discarded – undo
92 101
             if ($aColumn === $bColumn) {
93 102
               $sortVal = 0;
94 103
               continue;
104
+            } else {
105
+            	$sortVal = ($aColumn < $bColumn) ? -1 : 1;
95 106
             }
96
-            else $sortVal = ($aColumn < $bColumn) ? -1 : 1;
97 107
             break;
98 108
           }
99
-          if ($order === 'desc') return -$sortVal;
100
-          else return $sortVal;
109
+          if ($order === 'desc') {
110
+          	return -$sortVal;
111
+          } else {
112
+          	return $sortVal;
113
+          }
101 114
         };
102 115
     }
103 116
 
104 117
     private function processFilter($mode, $expected, $actual) {
105
-        if (Maphper::FIND_NOT & $mode) return $expected != $actual;
106
-        else if (Maphper::FIND_GREATER & $mode && Maphper::FIND_EXACT & $mode) return $expected <= $actual;
107
-        else if (Maphper::FIND_LESS & $mode && Maphper::FIND_EXACT & $mode) return $expected >= $actual;
108
-        else if (Maphper::FIND_GREATER & $mode) return $expected < $actual;
109
-        else if (Maphper::FIND_LESS & $mode) return $expected > $actual;
110
-        else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1];
111
-        else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual);
118
+        if (Maphper::FIND_NOT & $mode) {
119
+        	return $expected != $actual;
120
+        } else if (Maphper::FIND_GREATER & $mode && Maphper::FIND_EXACT & $mode) {
121
+        	return $expected <= $actual;
122
+        } else if (Maphper::FIND_LESS & $mode && Maphper::FIND_EXACT & $mode) {
123
+        	return $expected >= $actual;
124
+        } else if (Maphper::FIND_GREATER & $mode) {
125
+        	return $expected < $actual;
126
+        } else if (Maphper::FIND_LESS & $mode) {
127
+        	return $expected > $actual;
128
+        } else if (Maphper::FIND_BETWEEN & $mode) {
129
+        	return $expected[0] <= $actual && $actual <= $expected[1];
130
+        } else if (Maphper::FIND_NOCASE & $mode) {
131
+        	return strtolower($expected) == strtolower($actual);
132
+        }
112 133
         return $expected == $actual;
113 134
     }
114 135
 }
Please login to merge, or discard this patch.
maphper/datasource/sqliteadapter.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 		
24 24
 		$args = $query->getArgs();
25 25
 		foreach ($args as &$arg) if ($arg instanceof \DateTime) {
26
-			if ($arg->format('H:i:s')  == '00:00:00') $arg = $arg->format('Y-m-d');
26
+			if ($arg->format('H:i:s') == '00:00:00') $arg = $arg->format('Y-m-d');
27 27
 			else $arg = $arg->format('Y-m-d H:i:s');
28 28
 		}
29 29
 				
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	}
64 64
 
65 65
 	private function tableExists($name) {
66
-		$result = $this->pdo->query('SELECT name FROM sqlite_master WHERE type="table" and name="'. $name.'"');
66
+		$result = $this->pdo->query('SELECT name FROM sqlite_master WHERE type="table" and name="' . $name . '"');
67 67
 		return count($result->fetchAll()) == 1;
68 68
 	}
69 69
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		// SQLSTATE[HY000]: General error: 17 database schema has changed
83 83
 		$this->queryCache = [];
84 84
 
85
-		$affix = '_'.substr(md5($table), 0, 6);
85
+		$affix = '_' . substr(md5($table), 0, 6);
86 86
 		$this->createTable($table . $affix, $primaryKey, $data);
87 87
 		$fields = [];
88 88
 		foreach ($data as $key => $value) { $fields[] = $key; }
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 				$columns = implode(', ', $this->getColumns($table));			
92 92
 
93 93
 				$this->pdo->query('INSERT INTO ' . $this->quote($table . $affix) . '(' . $columns . ') SELECT ' . $columns . ' FROM ' . $this->quote($table));
94
-				$this->pdo->query('DROP TABLE IF EXISTS ' . $table );
94
+				$this->pdo->query('DROP TABLE IF EXISTS ' . $table);
95 95
 			}
96 96
 		}
97 97
 		catch (\PDOException $e) {
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 			echo $e->getMessage();
100 100
 		}
101 101
 
102
-		$this->pdo->query('DROP TABLE IF EXISTS ' . $table );
103
-		$this->pdo->query('ALTER TABLE ' . $table . $affix. ' RENAME TO '. $table );
102
+		$this->pdo->query('DROP TABLE IF EXISTS ' . $table);
103
+		$this->pdo->query('ALTER TABLE ' . $table . $affix . ' RENAME TO ' . $table);
104 104
 
105 105
 	}
106 106
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 		
115 115
 		$pkField = implode(', ', $parts) . ', PRIMARY KEY(' . implode(', ', $primaryKey) . ')';
116 116
 				
117
-		$this->pdo->query('DROP TABLE IF EXISTS ' . $table );
117
+		$this->pdo->query('DROP TABLE IF EXISTS ' . $table);
118 118
 		$this->pdo->query('CREATE TABLE ' . $table . ' (' . $pkField . ')');
119 119
 					
120 120
 		foreach ($data as $key => $value) {
Please login to merge, or discard this patch.
Braces   +57 added lines, -28 removed lines patch added patch discarded remove patch
@@ -15,32 +15,45 @@  discard block
 block discarded – undo
15 15
 		
16 16
 	public function query(\Maphper\Lib\Query $query) {
17 17
 		$queryId = md5($query->getSql());
18
-		if (isset($this->queryCache[$queryId])) $stmt = $this->queryCache[$queryId];
19
-		else {
18
+		if (isset($this->queryCache[$queryId])) {
19
+			$stmt = $this->queryCache[$queryId];
20
+		} else {
20 21
 			$stmt = $this->pdo->prepare($query->getSql(), [\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY]);
21
-			if ($stmt) $this->queryCache[$queryId] = $stmt;
22
+			if ($stmt) {
23
+				$this->queryCache[$queryId] = $stmt;
24
+			}
22 25
 		}
23 26
 		
24 27
 		$args = $query->getArgs();
25
-		foreach ($args as &$arg) if ($arg instanceof \DateTime) {
28
+		foreach ($args as &$arg) {
29
+			if ($arg instanceof \DateTime) {
26 30
 			if ($arg->format('H:i:s')  == '00:00:00') $arg = $arg->format('Y-m-d');
27
-			else $arg = $arg->format('Y-m-d H:i:s');
31
+		}
32
+			else {
33
+				$arg = $arg->format('Y-m-d H:i:s');
34
+			}
28 35
 		}
29 36
 				
30 37
 		if ($stmt !== false) {
31 38
 			try {
32
-				if (count($args) > 0) $res = $stmt->execute($args);
33
-				else $res = $stmt->execute();
34
-				if (substr($query->getSql(), 0, 6) === 'SELECT') return $stmt->fetchAll(\PDO::FETCH_OBJ);
35
-				else return $stmt;
36
-			}
37
-			catch (\Exception $e) {
39
+				if (count($args) > 0) {
40
+					$res = $stmt->execute($args);
41
+				} else {
42
+					$res = $stmt->execute();
43
+				}
44
+				if (substr($query->getSql(), 0, 6) === 'SELECT') {
45
+					return $stmt->fetchAll(\PDO::FETCH_OBJ);
46
+				} else {
47
+					return $stmt;
48
+				}
49
+			} catch (\Exception $e) {
38 50
 				//SQLite causes an error if when the DB schema changes, rebuild $stmt and try again.
39 51
 				if ($e->getMessage() == 'SQLSTATE[HY000]: General error: 17 database schema has changed') {
40 52
 					unset($this->queryCache[$queryId]);
41 53
 					return $this->query($query);	
54
+				} else {
55
+					return $stmt;
42 56
 				}
43
-				else return $stmt;				
44 57
 			}
45 58
 		}
46 59
 		//Handle SQLite when PDO_ERRMODE is set to SILENT
@@ -54,12 +67,19 @@  discard block
 block discarded – undo
54 67
 	}
55 68
 	
56 69
 	private function getType($val) {
57
-		if ($val instanceof \DateTime) return 'DATETIME';
58
-		else if (is_int($val)) return  'INTEGER';
59
-		else if (is_double($val)) return 'DECIMAL(9,' . strlen($val) - strrpos($val, '.') - 1 . ')';
60
-		else if (is_string($val) && strlen($val) < 256) return 'VARCHAR(255)';
61
-		else if (is_string($val) && strlen($val) > 256) return 'LONGBLOG';
62
-		else return 'VARCHAR(255)';		
70
+		if ($val instanceof \DateTime) {
71
+			return 'DATETIME';
72
+		} else if (is_int($val)) {
73
+			return  'INTEGER';
74
+		} else if (is_double($val)) {
75
+			return 'DECIMAL(9,' . strlen($val) - strrpos($val, '.') - 1 . ')';
76
+		} else if (is_string($val) && strlen($val) < 256) {
77
+			return 'VARCHAR(255)';
78
+		} else if (is_string($val) && strlen($val) > 256) {
79
+			return 'LONGBLOG';
80
+		} else {
81
+			return 'VARCHAR(255)';
82
+		}
63 83
 	}
64 84
 
65 85
 	private function tableExists($name) {
@@ -93,8 +113,7 @@  discard block
 block discarded – undo
93 113
 				$this->pdo->query('INSERT INTO ' . $this->quote($table . $affix) . '(' . $columns . ') SELECT ' . $columns . ' FROM ' . $this->quote($table));
94 114
 				$this->pdo->query('DROP TABLE IF EXISTS ' . $table );
95 115
 			}
96
-		}
97
-		catch (\PDOException $e) {
116
+		} catch (\PDOException $e) {
98 117
 			// No data to copy
99 118
 			echo $e->getMessage();
100 119
 		}
@@ -108,8 +127,11 @@  discard block
 block discarded – undo
108 127
 		$parts = [];
109 128
 		foreach ($primaryKey as $key) {
110 129
 			$pk = $data->$key;
111
-			if ($pk == null) $parts[] = $key . ' INTEGER'; 
112
-			else $parts[] = $key . ' ' . $this->getType($pk) . ' NOT NULL';					
130
+			if ($pk == null) {
131
+				$parts[] = $key . ' INTEGER';
132
+			} else {
133
+				$parts[] = $key . ' ' . $this->getType($pk) . ' NOT NULL';
134
+			}
113 135
 		}
114 136
 		
115 137
 		$pkField = implode(', ', $parts) . ', PRIMARY KEY(' . implode(', ', $primaryKey) . ')';
@@ -118,8 +140,12 @@  discard block
 block discarded – undo
118 140
 		$this->pdo->query('CREATE TABLE ' . $table . ' (' . $pkField . ')');
119 141
 					
120 142
 		foreach ($data as $key => $value) {
121
-			if (is_array($value) || (is_object($value) && !($value instanceof \DateTime))) continue;
122
-			if (in_array($key, $primaryKey)) continue;
143
+			if (is_array($value) || (is_object($value) && !($value instanceof \DateTime))) {
144
+				continue;
145
+			}
146
+			if (in_array($key, $primaryKey)) {
147
+				continue;
148
+			}
123 149
 
124 150
 			$type = $this->getType($value);
125 151
 		
@@ -129,10 +155,14 @@  discard block
 block discarded – undo
129 155
 	
130 156
 
131 157
 	public function addIndex($table, array $fields) {
132
-		if (empty($fields)) return false;
158
+		if (empty($fields)) {
159
+			return false;
160
+		}
133 161
 		
134 162
 		//SQLite doesn't support ASC/DESC indexes, remove the keywords
135
-		foreach ($fields as &$field) $field = str_ireplace([' desc', ' asc'], '', $field);
163
+		foreach ($fields as &$field) {
164
+			$field = str_ireplace([' desc', ' asc'], '', $field);
165
+		}
136 166
 		sort($fields);
137 167
 		$fields = array_map('strtolower', $fields);
138 168
 		$fields = array_map('trim', $fields);
@@ -141,8 +171,7 @@  discard block
 block discarded – undo
141 171
 		
142 172
 		try {
143 173
 			$this->pdo->query('CREATE INDEX IF NOT EXISTS  ' . $keyName . ' ON ' . $table . ' (' . implode(', ', $fields) . ')');
144
-		}
145
-		catch (\Exception $e) {
174
+		} catch (\Exception $e) {
146 175
 			
147 176
 		}
148 177
 	}
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 3 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -80,17 +80,17 @@
 block discarded – undo
80 80
 		return ['args' => $args, 'sql' => [$query]];
81 81
 	}
82 82
 
83
-    private function getOperator($mode) {
84
-        $operator = "";
83
+	private function getOperator($mode) {
84
+		$operator = "";
85 85
 
86
-        if (\Maphper\Maphper::FIND_NOCASE & $mode) $operator = 'LIKE';
87
-        else if (\Maphper\Maphper::FIND_BIT & $mode) $operator = '&';
88
-        else if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
89
-        else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
90
-        else if (\Maphper\Maphper::FIND_NOT & $mode) $operator = '!=';
86
+		if (\Maphper\Maphper::FIND_NOCASE & $mode) $operator = 'LIKE';
87
+		else if (\Maphper\Maphper::FIND_BIT & $mode) $operator = '&';
88
+		else if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
89
+		else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
90
+		else if (\Maphper\Maphper::FIND_NOT & $mode) $operator = '!=';
91 91
 
92
-        if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
92
+		if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
93 93
 
94
-        return $operator;
95
-    }
94
+		return $operator;
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 
27 27
 	//Needs to be broken up into better methods
28
-	public function createSql($fields, $mode){
28
+	public function createSql($fields, $mode) {
29 29
 		$args = [];
30 30
 		$sql = [];
31 31
 
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 					$inSql[] = ':' . $key . $i;
51 51
 				}
52 52
 				if (count($inSql) == 0) return [];
53
-				else $sql[] = $key . ' IN ( ' .  implode(', ', $inSql) . ')';
53
+				else $sql[] = $key . ' IN ( ' . implode(', ', $inSql) . ')';
54 54
 			}
55 55
 			else if ($value === NULL) {
56 56
 				$nullSql = $key . ' IS ';
Please login to merge, or discard this patch.
Braces   +53 added lines, -29 removed lines patch added patch discarded remove patch
@@ -9,17 +9,23 @@  discard block
 block discarded – undo
9 9
 
10 10
 		if (isset($options['offset'])) {
11 11
 			$offset = ' OFFSET ' . $options['offset'];
12
-			if (!$limit) $limit = ' LIMIT  1000';
12
+			if (!$limit) {
13
+				$limit = ' LIMIT  1000';
14
+			}
15
+		} else {
16
+			$offset = '';
13 17
 		}
14
-		else $offset = '';
15 18
 
16 19
 		$order = isset($options['order']) ? ' ORDER BY ' . $options['order'] : '';
17 20
 		return new Query('SELECT * FROM ' . $table . ' ' . $where . $order . $limit . $offset, $args);
18 21
 	}
19 22
 
20 23
 	public function aggregate($table, $function, $field, $where, $args, $group) {
21
-		if ($group == true) $groupBy = ' GROUP BY ' . $field;
22
-		else $groupBy = '';
24
+		if ($group == true) {
25
+			$groupBy = ' GROUP BY ' . $field;
26
+		} else {
27
+			$groupBy = '';
28
+		}
23 29
 		return new Query('SELECT ' . $function . '(' . $field . ') as val, ' . $field . '   FROM ' . $table . ($where[0] != null ? ' WHERE ' : '') . implode(' AND ', $where) . ' ' . $groupBy, $args);
24 30
 	}
25 31
 
@@ -32,64 +38,82 @@  discard block
 block discarded – undo
32 38
 		foreach ($fields as $key => $value) {
33 39
 			if (is_numeric($key) && is_array($value)) {
34 40
 				$result = $this->createSql($value, $key);
35
-				foreach ($result['args'] as $arg_key => $arg) $args[$arg_key] = $arg;
36
-				foreach ($result['sql'] as $arg) $sql[] = $arg;
37
-			}
38
-			else if (\Maphper\Maphper::FIND_BETWEEN & $mode) {
41
+				foreach ($result['args'] as $arg_key => $arg) {
42
+					$args[$arg_key] = $arg;
43
+				}
44
+				foreach ($result['sql'] as $arg) {
45
+					$sql[] = $arg;
46
+				}
47
+			} else if (\Maphper\Maphper::FIND_BETWEEN & $mode) {
39 48
 				$sql[] = $key . '>= :' . $key . 'from';
40 49
 				$sql[] = $key . ' <= :' . $key . 'to';
41 50
 
42 51
 				$args[$key . 'from'] = $value[0];
43 52
 				$args[$key . 'to'] = $value[1];
44
-			}
45
-			else if (!is_numeric($key) && is_array($value)) {
53
+			} else if (!is_numeric($key) && is_array($value)) {
46 54
 				$inSql = [];
47 55
 				$count = count($value);
48 56
 				for ($i = 0; $i < $count; $i++) {
49 57
 					$args[$key . $i] = $value[$i];
50 58
 					$inSql[] = ':' . $key . $i;
51 59
 				}
52
-				if (count($inSql) == 0) return [];
53
-				else $sql[] = $key . ' IN ( ' .  implode(', ', $inSql) . ')';
54
-			}
55
-			else if ($value === NULL) {
60
+				if (count($inSql) == 0) {
61
+					return [];
62
+				} else {
63
+					$sql[] = $key . ' IN ( ' .  implode(', ', $inSql) . ')';
64
+				}
65
+			} else if ($value === NULL) {
56 66
 				$nullSql = $key . ' IS ';
57
-				if (\Maphper\Maphper::FIND_NOT & $mode) $nullSql .= 'NOT ';
67
+				if (\Maphper\Maphper::FIND_NOT & $mode) {
68
+					$nullSql .= 'NOT ';
69
+				}
58 70
 				$sql[] = $nullSql . 'NULL';
59
-			}
60
-			else {
71
+			} else {
61 72
 
62 73
 				if (\Maphper\Maphper::FIND_LIKE & $mode) {
63 74
 					$operator = 'LIKE';
64 75
 					$value = '%' . $value . '%';
65
-				}
66
-				else if (\Maphper\Maphper::FIND_STARTS & $mode) {
76
+				} else if (\Maphper\Maphper::FIND_STARTS & $mode) {
67 77
 					$operator = 'LIKE';
68 78
 					$value = $value . '%';
79
+				} else {
80
+					$operator = $this->getOperator($mode);
69 81
 				}
70
-				else $operator = $this->getOperator($mode);
71 82
 
72 83
 				$args[$key] = $value;
73 84
 				$sql[] = $key . ' ' . $operator . ' :' . $key;
74 85
 			}
75 86
 		}
76 87
 
77
-		if (\Maphper\Maphper::FIND_OR & $mode) $query = implode(' OR  ', $sql);
78
-		else $query = implode(' AND ', $sql);
79
-		if (!empty($query)) $query = '(' . $query . ')';
88
+		if (\Maphper\Maphper::FIND_OR & $mode) {
89
+			$query = implode(' OR  ', $sql);
90
+		} else {
91
+			$query = implode(' AND ', $sql);
92
+		}
93
+		if (!empty($query)) {
94
+			$query = '(' . $query . ')';
95
+		}
80 96
 		return ['args' => $args, 'sql' => [$query]];
81 97
 	}
82 98
 
83 99
     private function getOperator($mode) {
84 100
         $operator = "";
85 101
 
86
-        if (\Maphper\Maphper::FIND_NOCASE & $mode) $operator = 'LIKE';
87
-        else if (\Maphper\Maphper::FIND_BIT & $mode) $operator = '&';
88
-        else if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>';
89
-        else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<';
90
-        else if (\Maphper\Maphper::FIND_NOT & $mode) $operator = '!=';
102
+        if (\Maphper\Maphper::FIND_NOCASE & $mode) {
103
+        	$operator = 'LIKE';
104
+        } else if (\Maphper\Maphper::FIND_BIT & $mode) {
105
+        	$operator = '&';
106
+        } else if (\Maphper\Maphper::FIND_GREATER & $mode) {
107
+        	$operator = '>';
108
+        } else if (\Maphper\Maphper::FIND_LESS & $mode) {
109
+        	$operator = '<';
110
+        } else if (\Maphper\Maphper::FIND_NOT & $mode) {
111
+        	$operator = '!=';
112
+        }
91 113
 
92
-        if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '=';
114
+        if (\Maphper\Maphper::FIND_EXACT & $mode) {
115
+        	$operator .= '=';
116
+        }
93 117
 
94 118
         return $operator;
95 119
     }
Please login to merge, or discard this patch.
maphper/lib/crudbuilder.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  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');
22
+				if ($value->format('H:i:s') == '00:00:00') $value = $value->format('Y-m-d');
23 23
 				else $value = $value->format('Y-m-d H:i:s');
24 24
 			}
25 25
 			if (is_object($value)) continue;
26
-			if ($prependField){
26
+			if ($prependField) {
27 27
 				$sql[] = $this->quote($field) . ' = :' . $field;
28 28
 			} else {
29 29
 				$sql[] = ':' . $field;
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 
36 36
 	public function insert($table, $data) {
37 37
 		$query = $this->buildSaveQuery($data);
38
-		return new Query('INSERT INTO ' . $this->quote($table) . ' (' .implode(', ', array_keys($query['args'])).') VALUES ( ' . implode(', ', $query['sql']). ' )', $query['args']);
38
+		return new Query('INSERT INTO ' . $this->quote($table) . ' (' . implode(', ', array_keys($query['args'])) . ') VALUES ( ' . implode(', ', $query['sql']) . ' )', $query['args']);
39 39
 	}
40 40
 
41 41
 	public function update($table, array $primaryKey, $data) {
42 42
 		$query = $this->buildSaveQuery($data, true);
43 43
 		$where = [];
44
-		foreach($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field;
45
-		return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']). ' WHERE '. implode(' AND ', $where), $query['args']);
44
+		foreach ($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field;
45
+		return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']) . ' WHERE ' . implode(' AND ', $where), $query['args']);
46 46
 	}
47 47
 }
Please login to merge, or discard this 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/multipk.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,8 +24,8 @@  discard block
 block discarded – undo
24 24
 	}
25 25
 
26 26
 	public function offsetGet($key) {
27
-		$depth = $this->getDepth()+1;
28
-		if (count($this->primaryKey)-1 == $depth) return $this->mapper->filter([$this->primaryKey[$depth] => $key])->item(0);
27
+		$depth = $this->getDepth() + 1;
28
+		if (count($this->primaryKey) - 1 == $depth) return $this->mapper->filter([$this->primaryKey[$depth] => $key])->item(0);
29 29
 		else return new MultiPk($this->mapper, $key, $this->primaryKey, $this);
30 30
 	}
31 31
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 
45 45
 	public function offsetUnset($key) {
46 46
 		$keys = $this->primaryKey;
47
-		$this->mapper->filter([ array_pop($keys) => $key])->delete();
47
+		$this->mapper->filter([array_pop($keys) => $key])->delete();
48 48
 	}
49 49
 
50 50
 	public function offsetExists($key) {
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,8 +25,11 @@
 block discarded – undo
25 25
 
26 26
 	public function offsetGet($key) {
27 27
 		$depth = $this->getDepth()+1;
28
-		if (count($this->primaryKey)-1 == $depth) return $this->mapper->filter([$this->primaryKey[$depth] => $key])->item(0);
29
-		else return new MultiPk($this->mapper, $key, $this->primaryKey, $this);
28
+		if (count($this->primaryKey)-1 == $depth) {
29
+			return $this->mapper->filter([$this->primaryKey[$depth] => $key])->item(0);
30
+		} else {
31
+			return new MultiPk($this->mapper, $key, $this->primaryKey, $this);
32
+		}
30 33
 	}
31 34
 
32 35
 	public function offsetSet($key, $value) {
Please login to merge, or discard this patch.
maphper/relation/many.php 1 patch
Braces   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,7 +6,9 @@  discard block
 block discarded – undo
6 6
 	private $localField;
7 7
 	
8 8
 	public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $critiera = []) {
9
-		if ($critiera) $mapper->filter($critiera);
9
+		if ($critiera) {
10
+			$mapper->filter($critiera);
11
+		}
10 12
 		$this->mapper = $mapper;
11 13
 		$this->parentField = $parentField;
12 14
 		$this->localField = $localField;		
@@ -14,17 +16,24 @@  discard block
 block discarded – undo
14 16
 	
15 17
 	
16 18
 	public function getData($parentObject) {
17
-		if (!isset($parentObject->{$this->parentField})) $mapper = $this->mapper;
18
-		else $mapper = $this->mapper->filter([$this->localField => $parentObject->{$this->parentField}]);
19
+		if (!isset($parentObject->{$this->parentField})) {
20
+			$mapper = $this->mapper;
21
+		} else {
22
+			$mapper = $this->mapper->filter([$this->localField => $parentObject->{$this->parentField}]);
23
+		}
19 24
 		
20 25
 		return $mapper;
21 26
 	}
22 27
 
23 28
 	
24 29
 	public function overwrite($key, &$mapper) {
25
-		if (!isset($key->{$this->parentField})) return false;
30
+		if (!isset($key->{$this->parentField})) {
31
+			return false;
32
+		}
26 33
 		foreach ($mapper as $k => $val) {
27
-			if (!empty($val->{$this->localField}) && $val->{$this->localField} == $key->{$this->parentField}) continue;
34
+			if (!empty($val->{$this->localField}) && $val->{$this->localField} == $key->{$this->parentField}) {
35
+				continue;
36
+			}
28 37
 			$val->{$this->localField} = $key->{$this->parentField};
29 38
 			$this->mapper[] = $val;
30 39
 		}
Please login to merge, or discard this patch.
maphper/relation/manymany.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	//bit hacky, breaking encapsulation, but simplest way to work out the info for the other side of the many:many relationship.
38 38
 	private function getOtherFieldNameInfo() {
39 39
 		if ($this->otherInfo == null) {
40
-			$propertyReader = function($name) {return $this->$name;	};
40
+			$propertyReader = function($name) {return $this->$name; };
41 41
 
42 42
 			$reader = $propertyReader->bindTo($this->intermediateMapper, $this->intermediateMapper);
43 43
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 				$propertyReader = $propertyReader->bindTo($relation, $relation);
46 46
 				if ($propertyReader('parentField') != $this->parentField) {
47 47
 					$relation = $relation->getData($this->object);
48
-					$this->otherInfo = [$propertyReader('localField'),  $propertyReader('parentField'), $propertyReader('mapper')];
48
+					$this->otherInfo = [$propertyReader('localField'), $propertyReader('parentField'), $propertyReader('mapper')];
49 49
 				}
50 50
 			}
51 51
 		}
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 		list($relatedField, $valueField, $mapper) = $this->getOtherFieldNameInfo();
89 89
 		if ($this->autoTraverse) {
90 90
 			$record = new \stdClass;
91
-			$record->{$this->parentField} =  $value->{$this->localField};
91
+			$record->{$this->parentField} = $value->{$this->localField};
92 92
 			$record->$valueField = $this->object->{$relatedField};
93 93
 			$this->intermediateMapper[] = $record;
94 94
 
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@  discard block
 block discarded – undo
31 31
 	public function overwrite($parentObject, &$data) {
32 32
 		$this->results = $data;
33 33
 		$this->object = $parentObject;
34
-		foreach ($data as $dt) $this[] = $dt;
34
+		foreach ($data as $dt) {
35
+			$this[] = $dt;
36
+		}
35 37
 	}
36 38
 
37 39
 	//bit hacky, breaking encapsulation, but simplest way to work out the info for the other side of the many:many relationship.
@@ -92,15 +94,13 @@  discard block
 block discarded – undo
92 94
 			$record->$valueField = $this->object->{$relatedField};
93 95
 			$this->intermediateMapper[] = $record;
94 96
 
95
-		}
96
-		else {
97
+		} else {
97 98
 			$record = $value;
98 99
 			if (isset($record->{$this->parentField}) && isset($value->{$this->intermediateName}) &&
99 100
 					$record->{$this->parentField} == $value->{$this->intermediateName}->{$this->localField} &&
100 101
 					$record->$valueField == $this->object->{$relatedField}) {
101 102
 				return;
102
-			}
103
-			else {
103
+			} else {
104 104
 				$record->{$this->parentField} = $value->{$this->intermediateName}->{$this->localField};
105 105
 				$record->$valueField = $this->object->{$relatedField};
106 106
 				$this->intermediateMapper[] = $record;
Please login to merge, or discard this patch.
maphper/relation/one.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
74 74
 
75 75
 	public function __get($name) {
76 76
 		if ($this->lazyLoad()) return $this->lazyLoad()->$name;
77
-        else return null;
77
+		else return null;
78 78
 	}
79 79
 
80 80
 	public function __isset($name) {
Please login to merge, or discard this patch.
Braces   +16 added lines, -6 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@  discard block
 block discarded – undo
30 30
 	private function lazyLoad() {
31 31
 		if (!isset($this->data)) {
32 32
 
33
-			if ($this->parentObject == null) throw new \Exception('Error, no object set');
33
+			if ($this->parentObject == null) {
34
+				throw new \Exception('Error, no object set');
35
+			}
34 36
 
35 37
 			$this->eagerLoad();
36 38
 			
@@ -47,8 +49,11 @@  discard block
 block discarded – undo
47 49
 
48 50
 		$recordsToLoad = array_unique($recordsToLoad);
49 51
 		//Fetch the results so they're in the cache for the corresponding maphper object
50
-		if ($this->criteria) $results = $this->mapper->filter($this->criteira)->filter([$this->localField => $recordsToLoad]);
51
-		else $results = $this->mapper->filter([$this->localField => $recordsToLoad]);
52
+		if ($this->criteria) {
53
+			$results = $this->mapper->filter($this->criteira)->filter([$this->localField => $recordsToLoad]);
54
+		} else {
55
+			$results = $this->mapper->filter([$this->localField => $recordsToLoad]);
56
+		}
52 57
 			
53 58
 		$cache = [];
54 59
 		foreach ($results as $result) {
@@ -68,13 +73,18 @@  discard block
 block discarded – undo
68 73
 	}
69 74
 
70 75
 	public function __call($func, array $args = []) {
71
-		if ($this->lazyLoad() == null) return '';
76
+		if ($this->lazyLoad() == null) {
77
+			return '';
78
+		}
72 79
 		return call_user_func_array([$this->lazyLoad(), $func], $args);
73 80
 	}
74 81
 
75 82
 	public function __get($name) {
76
-		if ($this->lazyLoad()) return $this->lazyLoad()->$name;
77
-        else return null;
83
+		if ($this->lazyLoad()) {
84
+			return $this->lazyLoad()->$name;
85
+		} else {
86
+        	return null;
87
+        }
78 88
 	}
79 89
 
80 90
 	public function __isset($name) {
Please login to merge, or discard this patch.