Passed
Push — master ( 03179d...66acfb )
by Richard
01:36
created
maphper/datasource/DatabaseModify.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -2,25 +2,25 @@
 block discarded – undo
2 2
 namespace Maphper\DataSource;
3 3
 
4 4
 class DatabaseModify {
5
-    private $adapter;
6
-    private $alterDb;
7
-    private $table;
5
+	private $adapter;
6
+	private $alterDb;
7
+	private $table;
8 8
 
9
-    public function __construct(DatabaseAdapter $adapter, $alterDb, $table) {
10
-        $this->adapter = $adapter;
11
-        $this->alterDb = $alterDb;
12
-        $this->table = $table;
13
-    }
9
+	public function __construct(DatabaseAdapter $adapter, $alterDb, $table) {
10
+		$this->adapter = $adapter;
11
+		$this->alterDb = $alterDb;
12
+		$this->table = $table;
13
+	}
14 14
 
15
-    public function addIndex($args) {
15
+	public function addIndex($args) {
16 16
 		if (Database::EDIT_INDEX & $this->alterDb) $this->adapter->addIndex($this->table, $args);
17 17
 	}
18 18
 
19
-    public function optimizeColumns() {
20
-        if (Database::EDIT_OPTIMISE & $this->alterDb && rand(0,500) == 1) $this->adapter->optimiseColumns($this->table);
21
-    }
19
+	public function optimizeColumns() {
20
+		if (Database::EDIT_OPTIMISE & $this->alterDb && rand(0,500) == 1) $this->adapter->optimiseColumns($this->table);
21
+	}
22 22
 
23
-    public function getTryInsertAgain($tryagain) {
24
-        return $tryagain && Database::EDIT_STRUCTURE & $this->alterDb;
25
-    }
23
+	public function getTryInsertAgain($tryagain) {
24
+		return $tryagain && Database::EDIT_STRUCTURE & $this->alterDb;
25
+	}
26 26
 }
Please login to merge, or discard this patch.
maphper/datasource/DatabaseSelect.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -2,31 +2,31 @@  discard block
 block discarded – undo
2 2
 namespace Maphper\DataSource;
3 3
 
4 4
 class DatabaseSelect {
5
-    private $resultCache = [];
6
-    private $idCache = [];
7
-    private $selectBuilder;
8
-    private $whereBuilder;
9
-    private $adapter;
10
-    private $databaseModify;
11
-    private $defaultSort;
12
-    private $table;
13
-
14
-    public function __construct(DatabaseAdapter $adapter, DatabaseModify $databaseModify, $table, $defaultSort) {
15
-        $this->adapter = $adapter;
16
-        $this->databaseModify = $databaseModify;
17
-        $this->selectBuilder = new \Maphper\Lib\SelectBuilder();
18
-        $this->whereBuilder = new \Maphper\Lib\Sql\WhereBuilder();
19
-        $this->defaultSort = $defaultSort;
20
-        $this->table = $table;
21
-    }
22
-
23
-    public function findById($id, $pk) {
5
+	private $resultCache = [];
6
+	private $idCache = [];
7
+	private $selectBuilder;
8
+	private $whereBuilder;
9
+	private $adapter;
10
+	private $databaseModify;
11
+	private $defaultSort;
12
+	private $table;
13
+
14
+	public function __construct(DatabaseAdapter $adapter, DatabaseModify $databaseModify, $table, $defaultSort) {
15
+		$this->adapter = $adapter;
16
+		$this->databaseModify = $databaseModify;
17
+		$this->selectBuilder = new \Maphper\Lib\SelectBuilder();
18
+		$this->whereBuilder = new \Maphper\Lib\Sql\WhereBuilder();
19
+		$this->defaultSort = $defaultSort;
20
+		$this->table = $table;
21
+	}
22
+
23
+	public function findById($id, $pk) {
24 24
 		if (!isset($this->idCache[$id])) {
25 25
 			try {
26 26
 				$result = $this->selectQuery($this->selectBuilder->select($this->table, $pk . ' = :id', [':id' => $id], ['limit' => 1]));
27 27
 			}
28 28
 			catch (\Exception $e) {
29
-                // Don't issue an error if it cannot be found since we return null
29
+				// Don't issue an error if it cannot be found since we return null
30 30
 			}
31 31
 
32 32
 			if (isset($result[0])) 	$this->idCache[$id] = $result[0];
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 		return $this->idCache[$id];
36 36
 	}
37 37
 
38
-    public function findByField(array $fields, $options = []) {
38
+	public function findByField(array $fields, $options = []) {
39 39
 		$cacheId = md5(serialize(func_get_args()));
40 40
 		if (!isset($this->resultCache[$cacheId])) {
41 41
 			$query = $this->whereBuilder->createSql($fields);
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 		return $this->resultCache[$cacheId];
56 56
 	}
57 57
 
58
-    public function findAggregate($function, $field, $group = null, array $criteria = [], array $options = []) {
58
+	public function findAggregate($function, $field, $group = null, array $criteria = [], array $options = []) {
59 59
 		//Cannot count/sum/max multiple fields, pick the first one. This should only come into play when trying to count() a mapper with multiple primary keys
60 60
 		if (is_array($field)) $field = $field[0];
61 61
 		$query = $this->whereBuilder->createSql($criteria);
@@ -72,34 +72,34 @@  discard block
 block discarded – undo
72 72
 		}
73 73
 	}
74 74
 
75
-    private function determineAggregateResult($result, $group, $field) {
76
-        if ($group != null) {
77
-            $ret = [];
78
-            foreach ($result as $res) $ret[$res->$field] = $res->val;
79
-            return $ret;
80
-        }
81
-        else if (isset($result[0])) return $result[0]->val;
82
-        else return 0;
83
-    }
84
-
85
-    private function selectQuery(\Maphper\Lib\Query $query) {
86
-        return $this->adapter->query($query)->fetchAll(\PDO::FETCH_OBJ);
87
-    }
88
-
89
-    public function clearResultCache() {
90
-        $this->resultCache = [];
91
-    }
92
-
93
-    public function clearIDCache() {
94
-        $this->idCache = [];
95
-    }
96
-
97
-    public function updateCache($data, $pkValue) {
75
+	private function determineAggregateResult($result, $group, $field) {
76
+		if ($group != null) {
77
+			$ret = [];
78
+			foreach ($result as $res) $ret[$res->$field] = $res->val;
79
+			return $ret;
80
+		}
81
+		else if (isset($result[0])) return $result[0]->val;
82
+		else return 0;
83
+	}
84
+
85
+	private function selectQuery(\Maphper\Lib\Query $query) {
86
+		return $this->adapter->query($query)->fetchAll(\PDO::FETCH_OBJ);
87
+	}
88
+
89
+	public function clearResultCache() {
90
+		$this->resultCache = [];
91
+	}
92
+
93
+	public function clearIDCache() {
94
+		$this->idCache = [];
95
+	}
96
+
97
+	public function updateCache($data, $pkValue) {
98 98
 		if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data);
99 99
 		else $this->cache[$pkValue] = $data;
100
-    }
100
+	}
101 101
 
102
-    public function deleteIDFromCache($id) {
103
-        unset($this->idCache[$id]);
104
-    }
102
+	public function deleteIDFromCache($id) {
103
+		unset($this->idCache[$id]);
104
+	}
105 105
 }
Please login to merge, or discard this patch.
maphper/datasource/mock.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -2,76 +2,76 @@
 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
-        $arrayFilter = new \Maphper\Lib\ArrayFilter(iterator_to_array($this->data->getIterator()));
23
-        $filteredArray = $arrayFilter->filter($fields);
24
-        if (isset($options['order'])) {
25
-            list($columns, $order) = explode(' ', $options['order']);
26
-            usort($filteredArray, $this->getOrderFunction($order, $columns));
27
-        }
28
-        if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']);
29
-        if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']);
30
-        return $filteredArray;
31
-    }
21
+	public function findByField(array $fields, $options = []) {
22
+		$arrayFilter = new \Maphper\Lib\ArrayFilter(iterator_to_array($this->data->getIterator()));
23
+		$filteredArray = $arrayFilter->filter($fields);
24
+		if (isset($options['order'])) {
25
+			list($columns, $order) = explode(' ', $options['order']);
26
+			usort($filteredArray, $this->getOrderFunction($order, $columns));
27
+		}
28
+		if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']);
29
+		if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']);
30
+		return $filteredArray;
31
+	}
32 32
 
33 33
   	public function findAggregate($function, $field, $group = null, array $criteria = [], array $options = []) {
34
-        return $function($this->findByField($criteria));
35
-    }
34
+		return $function($this->findByField($criteria));
35
+	}
36 36
 
37 37
   	public function deleteById($id) {
38
-        unset($this->data[$id]);
39
-    }
38
+		unset($this->data[$id]);
39
+	}
40 40
 
41 41
   	public function deleteByField(array $fields, array $options) {
42
-        foreach ($this->findByField($fields, $options) as $val) unset($this->data[$val->{$this->id[0]}]);
43
-    }
42
+		foreach ($this->findByField($fields, $options) as $val) unset($this->data[$val->{$this->id[0]}]);
43
+	}
44 44
 
45
-    public function save($data) {
46
-        if (isset($data->{$this->id[0]})) {
47
-            $id = $data->{$this->id[0]};
48
-        }
49
-        else {
50
-            $id = count($this->data);
51
-            $data->{$this->id[0]} = $id;
52
-        }
45
+	public function save($data) {
46
+		if (isset($data->{$this->id[0]})) {
47
+			$id = $data->{$this->id[0]};
48
+		}
49
+		else {
50
+			$id = count($this->data);
51
+			$data->{$this->id[0]} = $id;
52
+		}
53 53
 
54
-        $this->data[$id] = (object)array_merge($this->findById($id), (array)$data);
55
-    }
54
+		$this->data[$id] = (object)array_merge($this->findById($id), (array)$data);
55
+	}
56 56
 
57
-    public function getErrors() {
58
-        return [];
59
-    }
57
+	public function getErrors() {
58
+		return [];
59
+	}
60 60
 
61
-    private function getOrderFunction($order, $columns) {
62
-        return function($a, $b) use ($order, $columns) {
63
-          foreach (explode(',', $columns) as $column) {
64
-            $aColumn = $a->$column;
65
-            $bColumn = $b->$column;
66
-            if ($aColumn === $bColumn) {
67
-              $sortVal = 0;
68
-              continue;
69
-            }
70
-            else $sortVal = ($aColumn < $bColumn) ? -1 : 1;
71
-            break;
72
-          }
73
-          if ($order === 'desc') return -$sortVal;
74
-          else return $sortVal;
75
-        };
76
-    }
61
+	private function getOrderFunction($order, $columns) {
62
+		return function($a, $b) use ($order, $columns) {
63
+		  foreach (explode(',', $columns) as $column) {
64
+			$aColumn = $a->$column;
65
+			$bColumn = $b->$column;
66
+			if ($aColumn === $bColumn) {
67
+			  $sortVal = 0;
68
+			  continue;
69
+			}
70
+			else $sortVal = ($aColumn < $bColumn) ? -1 : 1;
71
+			break;
72
+		  }
73
+		  if ($order === 'desc') return -$sortVal;
74
+		  else return $sortVal;
75
+		};
76
+	}
77 77
 }
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/In.php 1 patch
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.
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/NullConditional.php 1 patch
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.
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.