Passed
Push — master ( 509b8c...0b1212 )
by Richard
01:44
created
maphper/datasource/mysqladapter.php 2 patches
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.
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -27,7 +27,9 @@  discard block
 block discarded – undo
27 27
 
28 28
     private function alterColumns($table, array $primaryKey, $data) {
29 29
         foreach ($data as $key => $value) {
30
-			if ($this->generalEditor->isNotSavableType($value, $key, $primaryKey)) continue;
30
+			if ($this->generalEditor->isNotSavableType($value, $key, $primaryKey)) {
31
+				continue;
32
+			}
31 33
             
32 34
 			$type = $this->generalEditor->getType($value);
33 35
 			$this->tryAlteringColumn($table, $key, $type);
@@ -36,9 +38,10 @@  discard block
 block discarded – undo
36 38
 
37 39
     private function tryAlteringColumn($table, $key, $type) {
38 40
         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) {
41
+            if (!$this->pdo->query('ALTER TABLE ' . $table . ' ADD ' . $this->quote($key) . ' ' . $type)) {
42
+            	throw new \Exception('Could not alter table');
43
+            }
44
+        } catch (\Exception $e) {
42 45
             $this->pdo->query('ALTER TABLE ' . $table . ' MODIFY ' . $this->quote($key) . ' ' . $type);
43 46
         }
44 47
     }
@@ -60,7 +63,9 @@  discard block
 block discarded – undo
60 63
 		$keyName = $this->quote(implode('_', $fields));
61 64
 
62 65
 		$results = $this->pdo->query('SHOW INDEX FROM ' . $this->quote($table) . ' WHERE Key_Name = "' . $keyName . '"');
63
-		if ($results && count($results->fetchAll()) == 0)  $this->pdo->query('CREATE INDEX ' . $keyName . ' ON ' . $this->quote($table) . ' (' . implode(', ', $fields) . ')');
66
+		if ($results && count($results->fetchAll()) == 0) {
67
+			$this->pdo->query('CREATE INDEX ' . $keyName . ' ON ' . $this->quote($table) . ' (' . implode(', ', $fields) . ')');
68
+		}
64 69
 	}
65 70
 
66 71
 	public function optimiseColumns($table) {
Please login to merge, or discard this patch.