Passed
Push — master ( 8f5295...39bb9c )
by Tom
02:11
created
Maphper/DataSource/GeneralEditDatabase.php 1 patch
Braces   +29 added lines, -13 removed lines patch added patch discarded remove patch
@@ -25,23 +25,36 @@  discard block
 block discarded – undo
25 25
 	}
26 26
 
27 27
     public function getType($val) {
28
-		if ($val instanceof \DateTimeInterface) return $this->dataTypes['datetime'];
29
-		else if ($result = $this->doNumberTypes($val)) return $result;
30
-		else if ($result = $this->doStringTypes($val)) return $result;
31
-		else return $this->dataTypes['other'];
28
+		if ($val instanceof \DateTimeInterface) {
29
+			return $this->dataTypes['datetime'];
30
+		} else if ($result = $this->doNumberTypes($val)) {
31
+			return $result;
32
+		} else if ($result = $this->doStringTypes($val)) {
33
+			return $result;
34
+		} else {
35
+			return $this->dataTypes['other'];
36
+		}
32 37
 	}
33 38
 
34 39
     private function doNumberTypes($val) {
35
-        if (is_int($val)) return $this->dataTypes['int'];
36
-		else if (is_double($val)) return $this->dataTypes['decimal'] . '(9,' . (strlen($val) - strrpos($val, '.') - 1) . ')';
37
-        else return false;
40
+        if (is_int($val)) {
41
+        	return $this->dataTypes['int'];
42
+        } else if (is_double($val)) {
43
+			return $this->dataTypes['decimal'] . '(9,' . (strlen($val) - strrpos($val, '.') - 1) . ')';
44
+		} else {
45
+        	return false;
46
+        }
38 47
     }
39 48
 
40 49
     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
-		else return $this->dataTypes['long_string'];
50
+        if (!is_string($val)) {
51
+        	return false;
52
+        }
53
+        if (strlen($val) <= $this->dataTypes['short_string_max_len']) {
54
+                    return $this->dataTypes['short_string'] . '(' . $this->dataTypes['short_string_max_len'] . ')';
55
+        } else {
56
+			return $this->dataTypes['long_string'];
57
+		}
45 58
     }
46 59
 
47 60
     public function isNotSavableType($value, $key, $primaryKey) {
@@ -54,8 +67,11 @@  discard block
 block discarded – undo
54 67
 		$parts = [];
55 68
 		foreach ($primaryKey as $key) {
56 69
 			$pk = $data->$key;
57
-			if ($pk == null) $parts[] = $key . ' ' . $this->dataTypes['pk_default'];
58
-			else $parts[] = $key . ' ' . $this->getType($pk) . ' NOT NULL';
70
+			if ($pk == null) {
71
+				$parts[] = $key . ' ' . $this->dataTypes['pk_default'];
72
+			} else {
73
+				$parts[] = $key . ' ' . $this->getType($pk) . ' NOT NULL';
74
+			}
59 75
 		}
60 76
 
61 77
 		$pkField = implode(', ', $parts) . ', PRIMARY KEY(' . implode(', ', $primaryKey) . ')';
Please login to merge, or discard this patch.
Maphper/Lib/CrudBuilder.php 1 patch
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,10 +20,15 @@  discard block
 block discarded – undo
20 20
 			//For dates with times set, search on time, if the time is not set, search on date only.
21 21
 			//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
22 22
 			if ($value instanceof \DateTimeInterface) {
23
-				if ($value->format('H:i:s')  == '00:00:00') $value = $value->format('Y-m-d');
24
-				else $value = $value->format('Y-m-d H:i:s');
23
+				if ($value->format('H:i:s')  == '00:00:00') {
24
+					$value = $value->format('Y-m-d');
25
+				} else {
26
+					$value = $value->format('Y-m-d H:i:s');
27
+				}
28
+			}
29
+			if (is_object($value)) {
30
+				continue;
25 31
 			}
26
-			if (is_object($value)) continue;
27 32
 			if ($prependField){
28 33
 				$sql[] = $this->quote($field) . ' = :' . $field;
29 34
 			} else {
@@ -42,7 +47,9 @@  discard block
 block discarded – undo
42 47
 	public function update($table, array $primaryKey, $data) {
43 48
 		$query = $this->buildSaveQuery($data, true);
44 49
 		$where = [];
45
-		foreach($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field;
50
+		foreach($primaryKey as $field) {
51
+			$where[] = $this->quote($field) . ' = :' . $field;
52
+		}
46 53
 		return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']). ' WHERE '. implode(' AND ', $where), $query['args']);
47 54
 	}
48 55
 }
Please login to merge, or discard this patch.
Maphper/Lib/DateInjector.php 1 patch
Braces   +27 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,26 +11,35 @@  discard block
 block discarded – undo
11 11
 
12 12
 	public function replaceDates($obj, $reset = true) {
13 13
 		//prevent infinite recursion, only process each object once
14
-		if ($this->checkCache($obj, $reset)) return $obj;
14
+		if ($this->checkCache($obj, $reset)) {
15
+			return $obj;
16
+		}
15 17
 
16
-		if ($this->isIterable($obj)) foreach ($obj as &$o) $o = $this->replaceDates($o, false);
17
-		if ($this->isPossiblyDateString($obj)) $obj = $this->tryToGetDateObjFromString($obj);
18
+		if ($this->isIterable($obj)) {
19
+			foreach ($obj as &$o) $o = $this->replaceDates($o, false);
20
+		}
21
+		if ($this->isPossiblyDateString($obj)) {
22
+			$obj = $this->tryToGetDateObjFromString($obj);
23
+		}
18 24
 		return $obj;
19 25
 	}
20 26
 
21 27
     private function tryToGetDateObjFromString($obj) {
22 28
         try {
23 29
             $date = new \DateTimeImmutable($obj);
24
-			if ($this->dateMatchesFormats($date, $obj)) $obj = $date;
25
-        }
26
-        catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date
30
+			if ($this->dateMatchesFormats($date, $obj)) {
31
+				$obj = $date;
32
+			}
33
+        } catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date
27 34
         }
28 35
         return $obj;
29 36
     }
30 37
 
31 38
 	private function dateMatchesFormats($date, $str) {
32 39
 		foreach ($this->dateFormats as list($format, $len)) {
33
-			if ($date->format($format) == substr($str, 0, $len)) return true;
40
+			if ($date->format($format) == substr($str, 0, $len)) {
41
+				return true;
42
+			}
34 43
 		}
35 44
 		return false;
36 45
 	}
@@ -44,11 +53,18 @@  discard block
 block discarded – undo
44 53
     }
45 54
 
46 55
 	private function checkCache($obj, $reset) {
47
-		if ($reset) $this->processCache = new \SplObjectStorage();
48
-        if (!is_object($obj)) return false;
56
+		if ($reset) {
57
+			$this->processCache = new \SplObjectStorage();
58
+		}
59
+        if (!is_object($obj)) {
60
+        	return false;
61
+        }
49 62
 
50
-		if ($this->processCache->contains($obj)) return $obj;
51
-		else $this->processCache->attach($obj, true);
63
+		if ($this->processCache->contains($obj)) {
64
+			return $obj;
65
+		} else {
66
+			$this->processCache->attach($obj, true);
67
+		}
52 68
 
53 69
 		return false;
54 70
 	}
Please login to merge, or discard this patch.