Passed
Push — master ( 8f5295...39bb9c )
by Tom
02:11
created
Maphper/Lib/Sql/In.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -2,28 +2,28 @@
 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
-        $value = array_values($value); // fix numeric index being different than $i
14
-        for ($i = 0; $i < $count; $i++) {
15
-            $args[$key . $i] = $value[$i];
16
-            $inSql[] = ':' . $key . $i;
17
-        }
9
+	public function getSql($key, $value, $mode) {
10
+		$args = [];
11
+		$inSql = [];
12
+		$count = count($value);
13
+		$value = array_values($value); // fix numeric index being different than $i
14
+		for ($i = 0; $i < $count; $i++) {
15
+			$args[$key . $i] = $value[$i];
16
+			$inSql[] = ':' . $key . $i;
17
+		}
18 18
 
19
-        $notText = '';
20
-        if (\Maphper\Maphper::FIND_NOT & $mode) {
21
-            $notText = ' NOT';
22
-        }
19
+		$notText = '';
20
+		if (\Maphper\Maphper::FIND_NOT & $mode) {
21
+			$notText = ' NOT';
22
+		}
23 23
 
24
-        if (count($inSql) == 0) return ['args' => [], 'sql' => ''];
25
-        else $sql = [$key . $notText . ' IN ( ' .  implode(', ', $inSql) . ')'];
24
+		if (count($inSql) == 0) return ['args' => [], 'sql' => ''];
25
+		else $sql = [$key . $notText . ' IN ( ' .  implode(', ', $inSql) . ')'];
26 26
 
27
-        return ['args' => $args, 'sql' => $sql];
28
-    }
27
+		return ['args' => $args, 'sql' => $sql];
28
+	}
29 29
 }
Please login to merge, or discard this patch.
Maphper/Maphper.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -83,21 +83,21 @@  discard block
 block discarded – undo
83 83
 	}
84 84
 
85 85
 	public function offsetSet($offset, $valueObj) {
86
-        if ($valueObj instanceof \Maphper\Relation) throw new \Exception();
86
+		if ($valueObj instanceof \Maphper\Relation) throw new \Exception();
87 87
 
88
-        //Extract private properties from the object
89
-        $visibilityOverride = new \Maphper\Lib\VisibilityOverride($valueObj);
90
-        $value = $visibilityOverride->getProperties($valueObj);
88
+		//Extract private properties from the object
89
+		$visibilityOverride = new \Maphper\Lib\VisibilityOverride($valueObj);
90
+		$value = $visibilityOverride->getProperties($valueObj);
91 91
 
92
-        $value = $this->processFilters($value);
93
-        $pk = $this->dataSource->getPrimaryKey();
94
-        if ($offset !== null) $value->{$pk[0]} = $offset;
95
-        $valueCopy = $this->removeRelations(clone $value, $pk);
96
-        $value = $this->entity->wrap($this->relations, $value);
97
-        $this->dataSource->save($value);
98
-        $visibilityOverride->write($value);
99
-        $value = $this->entity->create((array_merge((array)$value, (array)$valueCopy)), $this->relations);
100
-        $visibilityOverride->write($value);
92
+		$value = $this->processFilters($value);
93
+		$pk = $this->dataSource->getPrimaryKey();
94
+		if ($offset !== null) $value->{$pk[0]} = $offset;
95
+		$valueCopy = $this->removeRelations(clone $value, $pk);
96
+		$value = $this->entity->wrap($this->relations, $value);
97
+		$this->dataSource->save($value);
98
+		$visibilityOverride->write($value);
99
+		$value = $this->entity->create((array_merge((array)$value, (array)$valueCopy)), $this->relations);
100
+		$visibilityOverride->write($value);
101 101
 	}
102 102
 
103 103
 	private function removeRelations($obj, $pk) { // Prevent saving ManyMany twice except when pk isn't initially set
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 
111 111
 	public function offsetExists($offset) {
112 112
 		if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey());
113
-        if (!empty($this->settings['filter'])) {
114
-            $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset]));
115
-            return isset($data[0]);
116
-        }
113
+		if (!empty($this->settings['filter'])) {
114
+			$data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset]));
115
+			return isset($data[0]);
116
+		}
117 117
 		return (bool) $this->dataSource->findById($offset);
118 118
 	}
119 119
 
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
 
124 124
 	public function offsetGet($offset) {
125 125
 		if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey());
126
-        if (!empty($this->settings['filter'])) {
127
-            $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset]));
128
-            return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations);
129
-        }
126
+		if (!empty($this->settings['filter'])) {
127
+			$data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset]));
128
+			return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations);
129
+		}
130 130
 		return $this->entity->create($this->dataSource->findById($offset), $this->relations);
131 131
 	}
132 132
 
Please login to merge, or discard this patch.
Maphper/DataSource/Mock.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -2,100 +2,100 @@
 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;
7
-
8
-    public function __construct(\ArrayObject $data, $id) {
9
-        $this->data = $data;
10
-        $this->id = is_array($id) ? $id : [$id];
11
-    }
12
-
13
-    public function getPrimaryKey() {
14
-        return $this->id;
15
-    }
16
-
17
-    public function findById($id) {
18
-        return isset($this->data[$id]) ? (array)$this->data[$id] : [];
19
-    }
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
-    }
5
+	private $data;
6
+	private $id;
7
+
8
+	public function __construct(\ArrayObject $data, $id) {
9
+		$this->data = $data;
10
+		$this->id = is_array($id) ? $id : [$id];
11
+	}
12
+
13
+	public function getPrimaryKey() {
14
+		return $this->id;
15
+	}
16
+
17
+	public function findById($id) {
18
+		return isset($this->data[$id]) ? (array)$this->data[$id] : [];
19
+	}
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
+	}
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) {
43
-            if (count($this->id) > 1) $id = $this->getMultiPkSaveId($val);
44
-            else $id = $val->{$this->id[0]};
45
-
46
-            unset($this->data[$id]);
47
-        }
48
-    }
49
-
50
-    public function save($data) {
51
-        if (count($this->id) > 1) return $this->saveMultiPk($data);
52
-        else return $this->saveSinglePk($data);
53
-    }
54
-
55
-    private function saveSinglePk($data) {
56
-        if (isset($data->{$this->id[0]})) {
57
-            $id = $data->{$this->id[0]};
58
-        }
59
-        else {
60
-            $id = count($this->data);
61
-            $data->{$this->id[0]} = $id;
62
-        }
63
-
64
-        $this->data[$id] = (object)array_merge($this->findById($id), (array)$data);
65
-    }
66
-
67
-    private function saveMultiPk($data) {
68
-        $saveId = $this->getMultiPkSaveId($data);
69
-
70
-        $this->data[$saveId] = (object)array_merge($this->findById($saveId), (array)$data);
71
-    }
72
-
73
-    private function getMultiPkSaveId($data) {
74
-        $keyVals = [];
75
-        foreach ($this->id as $keyName) {
76
-            $keyVals[] = $data->$keyName;
77
-        }
78
-        return implode(',', $keyVals);
79
-    }
80
-
81
-    public function getErrors() {
82
-        return [];
83
-    }
84
-
85
-    private function getOrderFunction($order, $columns) {
86
-        return function($a, $b) use ($order, $columns) {
87
-          foreach (explode(',', $columns) as $column) {
88
-            $aColumn = $a->$column;
89
-            $bColumn = $b->$column;
90
-            if ($aColumn === $bColumn) {
91
-              $sortVal = 0;
92
-              continue;
93
-            }
94
-            else $sortVal = ($aColumn < $bColumn) ? -1 : 1;
95
-            break;
96
-          }
97
-          if ($order === 'desc') return -$sortVal;
98
-          else return $sortVal;
99
-        };
100
-    }
42
+		foreach ($this->findByField($fields, $options) as $val) {
43
+			if (count($this->id) > 1) $id = $this->getMultiPkSaveId($val);
44
+			else $id = $val->{$this->id[0]};
45
+
46
+			unset($this->data[$id]);
47
+		}
48
+	}
49
+
50
+	public function save($data) {
51
+		if (count($this->id) > 1) return $this->saveMultiPk($data);
52
+		else return $this->saveSinglePk($data);
53
+	}
54
+
55
+	private function saveSinglePk($data) {
56
+		if (isset($data->{$this->id[0]})) {
57
+			$id = $data->{$this->id[0]};
58
+		}
59
+		else {
60
+			$id = count($this->data);
61
+			$data->{$this->id[0]} = $id;
62
+		}
63
+
64
+		$this->data[$id] = (object)array_merge($this->findById($id), (array)$data);
65
+	}
66
+
67
+	private function saveMultiPk($data) {
68
+		$saveId = $this->getMultiPkSaveId($data);
69
+
70
+		$this->data[$saveId] = (object)array_merge($this->findById($saveId), (array)$data);
71
+	}
72
+
73
+	private function getMultiPkSaveId($data) {
74
+		$keyVals = [];
75
+		foreach ($this->id as $keyName) {
76
+			$keyVals[] = $data->$keyName;
77
+		}
78
+		return implode(',', $keyVals);
79
+	}
80
+
81
+	public function getErrors() {
82
+		return [];
83
+	}
84
+
85
+	private function getOrderFunction($order, $columns) {
86
+		return function($a, $b) use ($order, $columns) {
87
+		  foreach (explode(',', $columns) as $column) {
88
+			$aColumn = $a->$column;
89
+			$bColumn = $b->$column;
90
+			if ($aColumn === $bColumn) {
91
+			  $sortVal = 0;
92
+			  continue;
93
+			}
94
+			else $sortVal = ($aColumn < $bColumn) ? -1 : 1;
95
+			break;
96
+		  }
97
+		  if ($order === 'desc') return -$sortVal;
98
+		  else return $sortVal;
99
+		};
100
+	}
101 101
 }
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 \DateTimeInterface) 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 \DateTimeInterface)) ||
49
-                in_array($key, $primaryKey);
50
-    }
47
+	public function isNotSavableType($value, $key, $primaryKey) {
48
+		return is_array($value) || (is_object($value) && !($value instanceof \DateTimeInterface)) ||
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/Lib/DateInjector.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
 		return $obj;
19 19
 	}
20 20
 
21
-    private function tryToGetDateObjFromString($obj) {
22
-        try {
23
-            $date = new \DateTimeImmutable($obj);
21
+	private function tryToGetDateObjFromString($obj) {
22
+		try {
23
+			$date = new \DateTimeImmutable($obj);
24 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
27
-        }
28
-        return $obj;
29
-    }
25
+		}
26
+		catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date
27
+		}
28
+		return $obj;
29
+	}
30 30
 
31 31
 	private function dateMatchesFormats($date, $str) {
32 32
 		foreach ($this->dateFormats as list($format, $len)) {
@@ -35,17 +35,17 @@  discard block
 block discarded – undo
35 35
 		return false;
36 36
 	}
37 37
 
38
-    private function isIterable($obj) {
39
-        return is_array($obj) || (is_object($obj) && ($obj instanceof \Iterator));
40
-    }
38
+	private function isIterable($obj) {
39
+		return is_array($obj) || (is_object($obj) && ($obj instanceof \Iterator));
40
+	}
41 41
 
42
-    private function isPossiblyDateString($obj) {
43
-        return is_string($obj) && isset($obj[0]) && is_numeric($obj[0]) && strlen($obj) <= 20;
44
-    }
42
+	private function isPossiblyDateString($obj) {
43
+		return is_string($obj) && isset($obj[0]) && is_numeric($obj[0]) && strlen($obj) <= 20;
44
+	}
45 45
 
46 46
 	private function checkCache($obj, $reset) {
47 47
 		if ($reset) $this->processCache = new \SplObjectStorage();
48
-        if (!is_object($obj)) return false;
48
+		if (!is_object($obj)) return false;
49 49
 
50 50
 		if ($this->processCache->contains($obj)) return $obj;
51 51
 		else $this->processCache->attach($obj, true);
Please login to merge, or discard this patch.
Maphper/Lib/VisibilityOverride.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
 			$this->writeClosure = function ($field, $value) use ($object) { $object->$field = $value; };
12 12
 		}
13 13
 		else {
14
-            $visOverride = $this;
14
+			$visOverride = $this;
15 15
 			$this->readClosure = function() use ($visOverride) {
16
-                return (object) array_filter(get_object_vars($this), [$visOverride, 'isReturnableDataType']);
16
+				return (object) array_filter(get_object_vars($this), [$visOverride, 'isReturnableDataType']);
17 17
 			};
18 18
 			$this->readClosure = $this->readClosure->bindTo($object, $object);
19 19
 
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
 
24 24
 	}
25 25
 
26
-    public function isReturnableDataType($v) {
27
-        return is_scalar($v) || is_null($v) || (is_object($v) && $v instanceof \DateTimeInterface);
28
-    }
26
+	public function isReturnableDataType($v) {
27
+		return is_scalar($v) || is_null($v) || (is_object($v) && $v instanceof \DateTimeInterface);
28
+	}
29 29
 
30 30
 	public function getProperties() {
31 31
 		return ($this->readClosure)();
Please login to merge, or discard this patch.