Passed
Push — master ( 4b6b7b...8885c8 )
by Richard
02:15
created
Maphper/MultiPk.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 	private $parent;
5 5
 	private $primaryKey;
6 6
 	private $lookup;
7
-    private $mapper;
7
+	private $mapper;
8 8
 
9 9
 	public function __construct(Maphper $mapper, $lookup, array $primaryKey, MultiPk $parent = null) {
10 10
 		$this->parent = $parent;
Please login to merge, or discard this patch.
Maphper/DataSource/DatabaseCrud.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -2,30 +2,30 @@  discard block
 block discarded – undo
2 2
 namespace Maphper\DataSource;
3 3
 
4 4
 class DatabaseCrud {
5
-    private $crudBuilder;
6
-    private $whereBuilder;
7
-    private $adapter;
8
-    private $databaseModify;
9
-    private $databaseSelect;
10
-    private $table;
11
-    private $primaryKey;
12
-
13
-    public function __construct(DatabaseAdapter $adapter, DatabaseModify $databaseModify, DatabaseSelect $databaseSelect, $table, $primaryKey) {
14
-        $this->adapter = $adapter;
15
-        $this->databaseModify = $databaseModify;
16
-        $this->databaseSelect = $databaseSelect;
17
-        $this->crudBuilder = new \Maphper\Lib\CrudBuilder();
18
-        $this->whereBuilder = new \Maphper\Lib\Sql\WhereBuilder();
19
-        $this->table = $table;
20
-        $this->primaryKey = $primaryKey;
21
-    }
22
-
23
-    public function deleteById($id) {
24
-        $this->adapter->query($this->crudBuilder->delete($this->table, $this->primaryKey[0] . ' = :id', [':id' => $id]));
25
-        $this->databaseSelect->deleteIDFromCache($id);
5
+	private $crudBuilder;
6
+	private $whereBuilder;
7
+	private $adapter;
8
+	private $databaseModify;
9
+	private $databaseSelect;
10
+	private $table;
11
+	private $primaryKey;
12
+
13
+	public function __construct(DatabaseAdapter $adapter, DatabaseModify $databaseModify, DatabaseSelect $databaseSelect, $table, $primaryKey) {
14
+		$this->adapter = $adapter;
15
+		$this->databaseModify = $databaseModify;
16
+		$this->databaseSelect = $databaseSelect;
17
+		$this->crudBuilder = new \Maphper\Lib\CrudBuilder();
18
+		$this->whereBuilder = new \Maphper\Lib\Sql\WhereBuilder();
19
+		$this->table = $table;
20
+		$this->primaryKey = $primaryKey;
26 21
 	}
27 22
 
28
-    public function deleteByField(array $fields, array $options = []) {
23
+	public function deleteById($id) {
24
+		$this->adapter->query($this->crudBuilder->delete($this->table, $this->primaryKey[0] . ' = :id', [':id' => $id]));
25
+		$this->databaseSelect->deleteIDFromCache($id);
26
+	}
27
+
28
+	public function deleteByField(array $fields, array $options = []) {
29 29
 		$query = $this->whereBuilder->createSql($fields);
30 30
 		$this->adapter->query($this->crudBuilder->delete($this->table, $query['sql'], $query['args'], $options['limit'], null, $options['order']));
31 31
 		$this->databaseModify->addIndex(array_keys($query['args']));
@@ -35,22 +35,22 @@  discard block
 block discarded – undo
35 35
 		$this->databaseSelect->clearResultCache();
36 36
 	}
37 37
 
38
-    private function getIfNew($data) {
39
-        $new = false;
40
-        foreach ($this->primaryKey as $k) {
41
-            if (empty($data->$k)) {
42
-                $data->$k = null;
43
-                $new = true;
44
-            }
45
-        }
46
-        return $new;
47
-    }
38
+	private function getIfNew($data) {
39
+		$new = false;
40
+		foreach ($this->primaryKey as $k) {
41
+			if (empty($data->$k)) {
42
+				$data->$k = null;
43
+				$new = true;
44
+			}
45
+		}
46
+		return $new;
47
+	}
48 48
 
49
-    public function save($data, $tryagain = true) {
50
-        $new = $this->getIfNew($data);
49
+	public function save($data, $tryagain = true) {
50
+		$new = $this->getIfNew($data);
51 51
 
52 52
 		try {
53
-            $result = $this->insert($this->table, $this->primaryKey, $data);
53
+			$result = $this->insert($this->table, $this->primaryKey, $data);
54 54
 
55 55
 			//If there was an error but PDO is silent, trigger the catch block anyway
56 56
 			if ($result->errorCode() !== '00000') throw new \Exception('Could not insert into ' . $this->table);
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 		$this->databaseSelect->updateCache($data, $data->{$this->primaryKey[0]});
69 69
 	}
70 70
 
71
-    private function updatePK($data, $new) {
72
-        if ($new && count($this->primaryKey) == 1) $data->{$this->primaryKey[0]} = $this->adapter->lastInsertId();
73
-    }
71
+	private function updatePK($data, $new) {
72
+		if ($new && count($this->primaryKey) == 1) $data->{$this->primaryKey[0]} = $this->adapter->lastInsertId();
73
+	}
74 74
 
75
-    private function checkIfUpdateWorked($data) {
76
-        $updateWhere = $this->whereBuilder->createSql($data);
77
-        $matched = $this->databaseSelect->findByField($updateWhere['args']);
78
-        if (count($matched) == 0) throw new \InvalidArgumentException('Record inserted into table ' . $this->table . ' fails table constraints');
79
-    }
75
+	private function checkIfUpdateWorked($data) {
76
+		$updateWhere = $this->whereBuilder->createSql($data);
77
+		$matched = $this->databaseSelect->findByField($updateWhere['args']);
78
+		if (count($matched) == 0) throw new \InvalidArgumentException('Record inserted into table ' . $this->table . ' fails table constraints');
79
+	}
80 80
 
81 81
 	private function insert($table, array $primaryKey, $data) {
82 82
 		$error = 0;
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
 		}
89 89
 
90 90
  		if ($error || $result->errorCode() !== '00000') {
91
-            $result = $this->tryUpdate($table, $primaryKey, $data);
92
-        }
91
+			$result = $this->tryUpdate($table, $primaryKey, $data);
92
+		}
93 93
 
94 94
 		return $result;
95 95
 	}
96 96
 
97
-    private function tryUpdate($table, array $primaryKey, $data) {
98
-        $result = $this->adapter->query($this->crudBuilder->update($table, $primaryKey, $data));
99
-        if ($result->rowCount() === 0) $this->checkIfUpdateWorked($data);
97
+	private function tryUpdate($table, array $primaryKey, $data) {
98
+		$result = $this->adapter->query($this->crudBuilder->update($table, $primaryKey, $data));
99
+		if ($result->rowCount() === 0) $this->checkIfUpdateWorked($data);
100 100
 
101
-        return $result;
102
-    }
101
+		return $result;
102
+	}
103 103
 }
Please login to merge, or discard this patch.
Maphper/DataSource/GeneralEditDatabase.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -2,55 +2,55 @@
 block discarded – undo
2 2
 namespace Maphper\DataSource;
3 3
 
4 4
 class GeneralEditDatabase {
5
-    private $pdo;
6
-    private $dataTypes = [
7
-        'datetime' => 'DATETIME',
8
-        'int' => 'INT(11)',
9
-        'decimal' => 'DECIMAL',
10
-        'short_string' => 'VARCHAR',
11
-        'long_string' => 'LONGBLOG',
12
-        'short_string_max_len' => 255,
13
-        'other' => 'VARCHAR(255)',
5
+	private $pdo;
6
+	private $dataTypes = [
7
+		'datetime' => 'DATETIME',
8
+		'int' => 'INT(11)',
9
+		'decimal' => 'DECIMAL',
10
+		'short_string' => 'VARCHAR',
11
+		'long_string' => 'LONGBLOG',
12
+		'short_string_max_len' => 255,
13
+		'other' => 'VARCHAR(255)',
14 14
 
15
-        'pk_default' => 'INT(11) NOT NULL AUTO_INCREMENT'
16
-    ];
15
+		'pk_default' => 'INT(11) NOT NULL AUTO_INCREMENT'
16
+	];
17 17
 
18
-    public function __construct(\PDO $pdo, array $dataTypes) {
19
-        $this->pdo = $pdo;
20
-        $this->dataTypes = array_merge($this->dataTypes, $dataTypes);
21
-    }
18
+	public function __construct(\PDO $pdo, array $dataTypes) {
19
+		$this->pdo = $pdo;
20
+		$this->dataTypes = array_merge($this->dataTypes, $dataTypes);
21
+	}
22 22
 
23
-    public function quote($str) {
23
+	public function quote($str) {
24 24
 		return '`' . str_replace('.', '`.`', trim($str, '`')) . '`';
25 25
 	}
26 26
 
27
-    public function getType($val) {
27
+	public function getType($val) {
28 28
 		if ($val instanceof \DateTime) return $this->dataTypes['datetime'];
29 29
 		else if ($result = $this->doNumberTypes($val)) return $result;
30 30
 		else if ($result = $this->doStringTypes($val)) return $result;
31 31
 		else return $this->dataTypes['other'];
32 32
 	}
33 33
 
34
-    private function doNumberTypes($val) {
35
-        if (is_int($val)) return $this->dataTypes['int'];
34
+	private function doNumberTypes($val) {
35
+		if (is_int($val)) return $this->dataTypes['int'];
36 36
 		else if (is_double($val)) return $this->dataTypes['decimal'] . '(9,' . strlen($val) - strrpos($val, '.') - 1 . ')';
37
-        else return false;
38
-    }
37
+		else return false;
38
+	}
39 39
 
40
-    private function doStringTypes($val) {
41
-        if (!is_string($val)) return false;
42
-        if (strlen($val) <= $this->dataTypes['short_string_max_len'])
43
-            return $this->dataTypes['short_string'] . '(' . $this->dataTypes['short_string_max_len'] . ')';
40
+	private function doStringTypes($val) {
41
+		if (!is_string($val)) return false;
42
+		if (strlen($val) <= $this->dataTypes['short_string_max_len'])
43
+			return $this->dataTypes['short_string'] . '(' . $this->dataTypes['short_string_max_len'] . ')';
44 44
 		else return $this->dataTypes['long_string'];
45
-    }
45
+	}
46 46
 
47
-    public function isNotSavableType($value, $key, $primaryKey) {
48
-        return is_array($value) || (is_object($value) && !($value instanceof \DateTime)) ||
49
-                in_array($key, $primaryKey);
50
-    }
47
+	public function isNotSavableType($value, $key, $primaryKey) {
48
+		return is_array($value) || (is_object($value) && !($value instanceof \DateTime)) ||
49
+				in_array($key, $primaryKey);
50
+	}
51 51
 
52
-    //Alter the database so that it can store $data
53
-    public function createTable($table, array $primaryKey, $data) {
52
+	//Alter the database so that it can store $data
53
+	public function createTable($table, array $primaryKey, $data) {
54 54
 		$parts = [];
55 55
 		foreach ($primaryKey as $key) {
56 56
 			$pk = $data->$key;
Please login to merge, or discard this patch.
Maphper/DataSource/StmtCache.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace Maphper\DataSource;
3 3
 class StmtCache {
4
-    private $pdo;
5
-    private $queryCache = [];
4
+	private $pdo;
5
+	private $queryCache = [];
6 6
 
7
-    public function __construct(\PDO $pdo) {
8
-        $this->pdo = $pdo;
9
-    }
7
+	public function __construct(\PDO $pdo) {
8
+		$this->pdo = $pdo;
9
+	}
10 10
 
11
-    public function getCachedStmt($sql) {
11
+	public function getCachedStmt($sql) {
12 12
 		$queryId = $this->getQueryId($sql);
13 13
 		if (isset($this->queryCache[$queryId])) $stmt = $this->queryCache[$queryId];
14 14
 		else {
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
 		return $stmt;
19 19
 	}
20 20
 
21
-    private function getQueryId($sql) {
22
-        return md5($sql);
23
-    }
21
+	private function getQueryId($sql) {
22
+		return md5($sql);
23
+	}
24 24
 
25
-    public function deleteQueryFromCache($sql) {
26
-        unset($this->queryCache[$this->getQueryId($sql)]);
27
-    }
25
+	public function deleteQueryFromCache($sql) {
26
+		unset($this->queryCache[$this->getQueryId($sql)]);
27
+	}
28 28
 
29
-    public function clearCache() {
30
-        $this->queryCache = [];
31
-    }
29
+	public function clearCache() {
30
+		$this->queryCache = [];
31
+	}
32 32
 }
Please login to merge, or discard this patch.
Maphper/DataSource/Database.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
 
8 8
 	private $primaryKey;
9 9
 	private $fields = '*';
10
-    private $databaseSelect;
11
-    private $databaseCrud;
10
+	private $databaseSelect;
11
+	private $databaseCrud;
12 12
 
13 13
 	public function __construct($db, $table, $primaryKey = 'id', array $options = []) {
14 14
 		$options = new DatabaseOptions($db, $options);
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 
21 21
 		$defaultSort = $options->read('defaultSort') !== false ? $options->read('defaultSort')  : implode(', ', $this->primaryKey);
22 22
 
23
-        $databaseModify = new DatabaseModify($adapter, $options->getEditMode(), $table);
23
+		$databaseModify = new DatabaseModify($adapter, $options->getEditMode(), $table);
24 24
 
25
-        $this->databaseSelect = new DatabaseSelect($adapter, $databaseModify, $table, $defaultSort);
26
-        $this->databaseCrud = new DatabaseCrud($adapter, $databaseModify, $this->databaseSelect, $table, $this->primaryKey);
25
+		$this->databaseSelect = new DatabaseSelect($adapter, $databaseModify, $table, $defaultSort);
26
+		$this->databaseCrud = new DatabaseCrud($adapter, $databaseModify, $this->databaseSelect, $table, $this->primaryKey);
27 27
 
28 28
 		$databaseModify->optimizeColumns();
29 29
 	}
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	}
46 46
 
47 47
 	public function findByField(array $fields, $options = []) {
48
-        return $this->databaseSelect->findByField($fields, $options);
48
+		return $this->databaseSelect->findByField($fields, $options);
49 49
 	}
50 50
 
51 51
 	public function deleteByField(array $fields, array $options = []) {
@@ -53,6 +53,6 @@  discard block
 block discarded – undo
53 53
 	}
54 54
 
55 55
 	public function save($data) {
56
-        $this->databaseCrud->save($data, true);
56
+		$this->databaseCrud->save($data, true);
57 57
 	}
58 58
 }
Please login to merge, or discard this patch.
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/SqliteAdapter.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -4,15 +4,15 @@  discard block
 block discarded – undo
4 4
 class SqliteAdapter implements DatabaseAdapter {
5 5
 	private $pdo;
6 6
 	private $stmtCache;
7
-    private $generalEditor;
7
+	private $generalEditor;
8 8
 
9 9
 	public function __construct(\PDO $pdo) {
10 10
 		$this->pdo = $pdo;
11
-        $this->stmtCache = new StmtCache($pdo);
12
-        $this->generalEditor = new GeneralEditDatabase($this->pdo, [
13
-            'int' => 'INTEGER',
14
-            'pk_default' => 'INTEGER NOT NULL',
15
-        ]);
11
+		$this->stmtCache = new StmtCache($pdo);
12
+		$this->generalEditor = new GeneralEditDatabase($this->pdo, [
13
+			'int' => 'INTEGER',
14
+			'pk_default' => 'INTEGER NOT NULL',
15
+		]);
16 16
 	}
17 17
 
18 18
 	public function quote($str) {
@@ -20,19 +20,19 @@  discard block
 block discarded – undo
20 20
 	}
21 21
 
22 22
 	public function query(\Maphper\Lib\Query $query) {
23
-        $stmt = $this->stmtCache->getCachedStmt($query->getSql());
23
+		$stmt = $this->stmtCache->getCachedStmt($query->getSql());
24 24
 		$args = $query->getArgs();
25 25
 
26
-        //Handle SQLite when PDO_ERRMODE is set to SILENT
27
-        if ($stmt === false) throw new \Exception('Invalid query');
26
+		//Handle SQLite when PDO_ERRMODE is set to SILENT
27
+		if ($stmt === false) throw new \Exception('Invalid query');
28 28
 
29
-        $stmt->execute($args);
30
-        if ($stmt->errorCode() !== '00000' && $stmt->errorInfo()[2] == 'database schema has changed') {
29
+		$stmt->execute($args);
30
+		if ($stmt->errorCode() !== '00000' && $stmt->errorInfo()[2] == 'database schema has changed') {
31 31
 			$this->stmtCache->deleteQueryFromCache($query->getSql());
32 32
 			return $this->query($query);
33
-        }
33
+		}
34 34
 
35
-        return $stmt;
35
+		return $stmt;
36 36
 	}
37 37
 
38 38
 	public function lastInsertId() {
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 		// SQLSTATE[HY000]: General error: 17 database schema has changed
60 60
 		$this->stmtCache->clearCache();
61 61
 
62
-        // Create temp table to create a new structure
62
+		// Create temp table to create a new structure
63 63
 		$affix = '_'.substr(md5($table), 0, 6);
64
-        $tempTable = $table . $affix;
64
+		$tempTable = $table . $affix;
65 65
 		$this->generalEditor->createTable($tempTable, $primaryKey, $data);
66
-        $this->alterColumns($tempTable, $primaryKey, $data);
66
+		$this->alterColumns($tempTable, $primaryKey, $data);
67 67
 		$this->copyTableData($table, $tempTable);
68 68
 
69 69
 		$this->pdo->query('DROP TABLE IF EXISTS ' . $table );
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 
72 72
 	}
73 73
 
74
-    private function copyTableData($tableFrom, $tableTo) {
75
-        try {
74
+	private function copyTableData($tableFrom, $tableTo) {
75
+		try {
76 76
 			if ($this->tableExists($tableFrom)) {
77 77
 				$columns = implode(', ', $this->getColumns($tableFrom));
78 78
 
@@ -83,19 +83,19 @@  discard block
 block discarded – undo
83 83
 			// No data to copy
84 84
 			echo $e->getMessage();
85 85
 		}
86
-    }
86
+	}
87 87
 
88
-    private function alterColumns($table, array $primaryKey, $data) {
89
-        foreach ($data as $key => $value) {
88
+	private function alterColumns($table, array $primaryKey, $data) {
89
+		foreach ($data as $key => $value) {
90 90
 			if ($this->generalEditor->isNotSavableType($value, $key, $primaryKey)) continue;
91 91
 
92 92
 			$type = $this->generalEditor->getType($value);
93 93
 
94 94
 			$this->pdo->query('ALTER TABLE ' . $table . ' ADD ' . $this->quote($key) . ' ' . $type);
95 95
 		}
96
-    }
96
+	}
97 97
 
98
-    public function addIndex($table, array $fields) {
98
+	public function addIndex($table, array $fields) {
99 99
 		if (empty($fields)) return false;
100 100
 
101 101
 		//SQLite doesn't support ASC/DESC indexes, remove the keywords
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/MysqlAdapter.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -3,14 +3,14 @@  discard block
 block discarded – undo
3 3
 class MysqlAdapter implements DatabaseAdapter {
4 4
 	private $pdo;
5 5
 	private $stmtCache;
6
-    private $generalEditor;
6
+	private $generalEditor;
7 7
 
8 8
 	public function __construct(\PDO $pdo) {
9 9
 		$this->pdo = $pdo;
10 10
 		//Set to strict mode to detect 'out of range' errors, action at a distance but it needs to be set for all INSERT queries
11 11
 		$this->pdo->query('SET sql_mode = STRICT_ALL_TABLES');
12
-        $this->stmtCache = new StmtCache($pdo);
13
-        $this->generalEditor = new GeneralEditDatabase($this->pdo, ['short_string_max_len' => 191]);
12
+		$this->stmtCache = new StmtCache($pdo);
13
+		$this->generalEditor = new GeneralEditDatabase($this->pdo, ['short_string_max_len' => 191]);
14 14
 	}
15 15
 
16 16
 	public function quote($str) {
@@ -20,32 +20,32 @@  discard block
 block discarded – undo
20 20
 	public function query(\Maphper\Lib\Query $query) {
21 21
 		$stmt = $this->stmtCache->getCachedStmt($query->getSql());
22 22
 		$args = $query->getArgs();
23
-        $stmt->execute($args);
23
+		$stmt->execute($args);
24 24
 
25 25
 		return $stmt;
26 26
 	}
27 27
 
28
-    private function alterColumns($table, array $primaryKey, $data) {
29
-        foreach ($data as $key => $value) {
28
+	private function alterColumns($table, array $primaryKey, $data) {
29
+		foreach ($data as $key => $value) {
30 30
 			if ($this->generalEditor->isNotSavableType($value, $key, $primaryKey)) continue;
31 31
             
32 32
 			$type = $this->generalEditor->getType($value);
33 33
 			$this->tryAlteringColumn($table, $key, $type);
34 34
 		}
35
-    }
35
+	}
36 36
 
37
-    private function tryAlteringColumn($table, $key, $type) {
38
-        try {
39
-            if (!$this->pdo->query('ALTER TABLE ' . $table . ' ADD ' . $this->quote($key) . ' ' . $type)) throw new \Exception('Could not alter table');
40
-        }
41
-        catch (\Exception $e) {
42
-            $this->pdo->query('ALTER TABLE ' . $table . ' MODIFY ' . $this->quote($key) . ' ' . $type);
43
-        }
44
-    }
37
+	private function tryAlteringColumn($table, $key, $type) {
38
+		try {
39
+			if (!$this->pdo->query('ALTER TABLE ' . $table . ' ADD ' . $this->quote($key) . ' ' . $type)) throw new \Exception('Could not alter table');
40
+		}
41
+		catch (\Exception $e) {
42
+			$this->pdo->query('ALTER TABLE ' . $table . ' MODIFY ' . $this->quote($key) . ' ' . $type);
43
+		}
44
+	}
45 45
 
46 46
 	public function alterDatabase($table, array $primaryKey, $data) {
47 47
 		$this->generalEditor->createTable($table, $primaryKey, $data);
48
-        $this->alterColumns($table, $primaryKey, $data);
48
+		$this->alterColumns($table, $primaryKey, $data);
49 49
 	}
50 50
 
51 51
 	public function lastInsertId() {
Please login to merge, or discard this patch.