@@ -21,8 +21,11 @@ |
||
21 | 21 | $notText = ' NOT'; |
22 | 22 | } |
23 | 23 | |
24 | - if (count($inSql) == 0) return ['args' => [], 'sql' => '']; |
|
25 | - else $sql = [$key . $notText . ' IN ( ' . implode(', ', $inSql) . ')']; |
|
24 | + if (count($inSql) == 0) { |
|
25 | + return ['args' => [], 'sql' => '']; |
|
26 | + } else { |
|
27 | + $sql = [$key . $notText . ' IN ( ' . implode(', ', $inSql) . ')']; |
|
28 | + } |
|
26 | 29 | |
27 | 30 | return ['args' => $args, 'sql' => $sql]; |
28 | 31 | } |
@@ -60,7 +60,9 @@ discard block |
||
60 | 60 | |
61 | 61 | $siblings = new \ArrayObject(); |
62 | 62 | |
63 | - foreach ($results as &$result) $result = $this->entity->create($result, $this->relations, $siblings); |
|
63 | + foreach ($results as &$result) { |
|
64 | + $result = $this->entity->create($result, $this->relations, $siblings); |
|
65 | + } |
|
64 | 66 | |
65 | 67 | return $results; |
66 | 68 | } |
@@ -77,13 +79,17 @@ discard block |
||
77 | 79 | private function processFilters($value) { |
78 | 80 | //When saving to a mapper with filters, write the filters back into the object being stored |
79 | 81 | foreach ($this->settings['filter'] as $key => $filterValue) { |
80 | - if (empty($value->$key) && !is_array($filterValue)) $value->$key = $filterValue; |
|
82 | + if (empty($value->$key) && !is_array($filterValue)) { |
|
83 | + $value->$key = $filterValue; |
|
84 | + } |
|
81 | 85 | } |
82 | 86 | return $value; |
83 | 87 | } |
84 | 88 | |
85 | 89 | public function offsetSet($offset, $valueObj) { |
86 | - if ($valueObj instanceof \Maphper\Relation) throw new \Exception(); |
|
90 | + if ($valueObj instanceof \Maphper\Relation) { |
|
91 | + throw new \Exception(); |
|
92 | + } |
|
87 | 93 | |
88 | 94 | //Extract private properties from the object |
89 | 95 | $visibilityOverride = new \Maphper\Lib\VisibilityOverride($valueObj); |
@@ -91,7 +97,9 @@ discard block |
||
91 | 97 | |
92 | 98 | $value = $this->processFilters($value); |
93 | 99 | $pk = $this->dataSource->getPrimaryKey(); |
94 | - if ($offset !== null) $value->{$pk[0]} = $offset; |
|
100 | + if ($offset !== null) { |
|
101 | + $value->{$pk[0]} = $offset; |
|
102 | + } |
|
95 | 103 | $valueCopy = $this->removeRelations(clone $value, $pk); |
96 | 104 | $value = $this->entity->wrap($this->relations, $value); |
97 | 105 | $this->dataSource->save($value); |
@@ -101,15 +109,20 @@ discard block |
||
101 | 109 | } |
102 | 110 | |
103 | 111 | private function removeRelations($obj, $pk) { // Prevent saving ManyMany twice except when pk isn't initially set |
104 | - foreach ($this->relations as $name => $relation) |
|
105 | - if ($relation instanceOf \Maphper\Relation\ManyMany && isset($obj->$name) && !empty($obj->{$pk[0]})) unset($obj->$name); |
|
112 | + foreach ($this->relations as $name => $relation) { |
|
113 | + if ($relation instanceOf \Maphper\Relation\ManyMany && isset($obj->$name) && !empty($obj->{$pk[0]})) unset($obj->$name); |
|
114 | + } |
|
106 | 115 | |
107 | - if (empty($obj->{$pk[0]})) unset($obj->{$pk[0]}); |
|
116 | + if (empty($obj->{$pk[0]})) { |
|
117 | + unset($obj->{$pk[0]}); |
|
118 | + } |
|
108 | 119 | return $obj; |
109 | 120 | } |
110 | 121 | |
111 | 122 | public function offsetExists($offset) { |
112 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
123 | + if (count($this->dataSource->getPrimaryKey()) > 1) { |
|
124 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
125 | + } |
|
113 | 126 | if (!empty($this->settings['filter'])) { |
114 | 127 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
115 | 128 | return isset($data[0]); |
@@ -122,7 +135,9 @@ discard block |
||
122 | 135 | } |
123 | 136 | |
124 | 137 | public function offsetGet($offset) { |
125 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
138 | + if (count($this->dataSource->getPrimaryKey()) > 1) { |
|
139 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
140 | + } |
|
126 | 141 | if (!empty($this->settings['filter'])) { |
127 | 142 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
128 | 143 | return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations); |
@@ -133,11 +148,15 @@ discard block |
||
133 | 148 | public function __call($method, $args) { |
134 | 149 | if (array_key_exists($method, $this->settings)) { |
135 | 150 | $maphper = new Maphper($this->dataSource, $this->settings, $this->relations); |
136 | - if (is_array($maphper->settings[$method])) $maphper->settings[$method] = $args[0] + $maphper->settings[$method]; |
|
137 | - else $maphper->settings[$method] = $args[0]; |
|
151 | + if (is_array($maphper->settings[$method])) { |
|
152 | + $maphper->settings[$method] = $args[0] + $maphper->settings[$method]; |
|
153 | + } else { |
|
154 | + $maphper->settings[$method] = $args[0]; |
|
155 | + } |
|
138 | 156 | return $maphper; |
157 | + } else { |
|
158 | + throw new \Exception('Method Maphper::' . $method . ' does not exist'); |
|
139 | 159 | } |
140 | - else throw new \Exception('Method Maphper::' . $method . ' does not exist'); |
|
141 | 160 | } |
142 | 161 | |
143 | 162 | public function findAggregate($function, $field, $group = null) { |
@@ -25,8 +25,12 @@ discard block |
||
25 | 25 | list($columns, $order) = explode(' ', $options['order']); |
26 | 26 | usort($filteredArray, $this->getOrderFunction($order, $columns)); |
27 | 27 | } |
28 | - if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']); |
|
29 | - if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']); |
|
28 | + if (isset($options['offset'])) { |
|
29 | + $filteredArray = array_slice($filteredArray, $options['offset']); |
|
30 | + } |
|
31 | + if (isset($options['limit'])) { |
|
32 | + $filteredArray = array_slice($filteredArray, 0, $options['limit']); |
|
33 | + } |
|
30 | 34 | return $filteredArray; |
31 | 35 | } |
32 | 36 | |
@@ -40,23 +44,28 @@ discard block |
||
40 | 44 | |
41 | 45 | public function deleteByField(array $fields, array $options) { |
42 | 46 | foreach ($this->findByField($fields, $options) as $val) { |
43 | - if (count($this->id) > 1) $id = $this->getMultiPkSaveId($val); |
|
44 | - else $id = $val->{$this->id[0]}; |
|
47 | + if (count($this->id) > 1) { |
|
48 | + $id = $this->getMultiPkSaveId($val); |
|
49 | + } else { |
|
50 | + $id = $val->{$this->id[0]}; |
|
51 | + } |
|
45 | 52 | |
46 | 53 | unset($this->data[$id]); |
47 | 54 | } |
48 | 55 | } |
49 | 56 | |
50 | 57 | public function save($data) { |
51 | - if (count($this->id) > 1) return $this->saveMultiPk($data); |
|
52 | - else return $this->saveSinglePk($data); |
|
58 | + if (count($this->id) > 1) { |
|
59 | + return $this->saveMultiPk($data); |
|
60 | + } else { |
|
61 | + return $this->saveSinglePk($data); |
|
62 | + } |
|
53 | 63 | } |
54 | 64 | |
55 | 65 | private function saveSinglePk($data) { |
56 | 66 | if (isset($data->{$this->id[0]})) { |
57 | 67 | $id = $data->{$this->id[0]}; |
58 | - } |
|
59 | - else { |
|
68 | + } else { |
|
60 | 69 | $id = count($this->data); |
61 | 70 | $data->{$this->id[0]} = $id; |
62 | 71 | } |
@@ -90,12 +99,16 @@ discard block |
||
90 | 99 | if ($aColumn === $bColumn) { |
91 | 100 | $sortVal = 0; |
92 | 101 | continue; |
102 | + } else { |
|
103 | + $sortVal = ($aColumn < $bColumn) ? -1 : 1; |
|
93 | 104 | } |
94 | - else $sortVal = ($aColumn < $bColumn) ? -1 : 1; |
|
95 | 105 | break; |
96 | 106 | } |
97 | - if ($order === 'desc') return -$sortVal; |
|
98 | - else return $sortVal; |
|
107 | + if ($order === 'desc') { |
|
108 | + return -$sortVal; |
|
109 | + } else { |
|
110 | + return $sortVal; |
|
111 | + } |
|
99 | 112 | }; |
100 | 113 | } |
101 | 114 | } |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | } |
11 | 11 | |
12 | 12 | public function getAdapter() { |
13 | - if ($this->db instanceof \Maphper\DataSource) return $this->db; |
|
13 | + if ($this->db instanceof \Maphper\DataSource) { |
|
14 | + return $this->db; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | $adapter = '\\Maphper\\DataSource\\' . ucfirst($this->db->getAttribute(\PDO::ATTR_DRIVER_NAME)) . 'Adapter'; |
16 | 18 | |
@@ -18,7 +20,9 @@ discard block |
||
18 | 20 | } |
19 | 21 | |
20 | 22 | public function getEditMode() { |
21 | - if (!isset($this->options['editmode'])) return false; |
|
23 | + if (!isset($this->options['editmode'])) { |
|
24 | + return false; |
|
25 | + } |
|
22 | 26 | |
23 | 27 | return $this->options['editmode'] === true ? Database::EDIT_STRUCTURE | Database::EDIT_INDEX | Database::EDIT_OPTIMISE : $this->options['editmode']; |
24 | 28 | } |
@@ -25,23 +25,36 @@ discard block |
||
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 |
||
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) . ')'; |
@@ -20,10 +20,15 @@ discard block |
||
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 |
||
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 | } |
@@ -11,26 +11,35 @@ discard block |
||
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 |
||
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 | } |
@@ -24,12 +24,21 @@ discard block |
||
24 | 24 | |
25 | 25 | private function cacheUpdateRequired($id) { |
26 | 26 | if ($this->cacheMode > 0) { |
27 | - if (!isset($this->idCacheTime[$id])) return true; // Cache time has not been set for first time |
|
27 | + if (!isset($this->idCacheTime[$id])) { |
|
28 | + return true; |
|
29 | + } |
|
30 | + // Cache time has not been set for first time |
|
28 | 31 | |
29 | - if (time() - $this->idCacheTime[$id] > $this->cacheMode) return true; // Cache time has expired |
|
32 | + if (time() - $this->idCacheTime[$id] > $this->cacheMode) { |
|
33 | + return true; |
|
34 | + } |
|
35 | + // Cache time has expired |
|
30 | 36 | } |
31 | 37 | |
32 | - if (!isset($this->idCache[$id])) return true; // Cache has not been set for first time |
|
38 | + if (!isset($this->idCache[$id])) { |
|
39 | + return true; |
|
40 | + } |
|
41 | + // Cache has not been set for first time |
|
33 | 42 | |
34 | 43 | return false; |
35 | 44 | } |
@@ -38,16 +47,21 @@ discard block |
||
38 | 47 | if ($this->cacheMode < 0 || $this->cacheUpdateRequired($id)) { |
39 | 48 | try { |
40 | 49 | $result = $this->selectQuery($this->selectBuilder->select($this->table, $pk . ' = :id', [':id' => $id], ['limit' => 1])); |
41 | - } |
|
42 | - catch (\Exception $e) { |
|
50 | + } catch (\Exception $e) { |
|
43 | 51 | // Don't issue an error if it cannot be found since we return null |
44 | 52 | } |
45 | 53 | |
46 | - if (isset($result[0])) $result = $result[0]; |
|
47 | - else return null; |
|
54 | + if (isset($result[0])) { |
|
55 | + $result = $result[0]; |
|
56 | + } else { |
|
57 | + return null; |
|
58 | + } |
|
48 | 59 | } |
49 | 60 | |
50 | - if ($this->cacheMode < 0) return $result; // Cache mode is off |
|
61 | + if ($this->cacheMode < 0) { |
|
62 | + return $result; |
|
63 | + } |
|
64 | + // Cache mode is off |
|
51 | 65 | |
52 | 66 | if ($this->cacheUpdateRequired()) { |
53 | 67 | $this->idCache[$id] = $result; |
@@ -63,20 +77,24 @@ discard block |
||
63 | 77 | if ($this->cacheMode < 0 || $this->cacheUpdateRequired($cacheId)) { |
64 | 78 | $query = $this->whereBuilder->createSql($fields); |
65 | 79 | |
66 | - if (!isset($options['order'])) $options['order'] = $this->defaultSort; |
|
80 | + if (!isset($options['order'])) { |
|
81 | + $options['order'] = $this->defaultSort; |
|
82 | + } |
|
67 | 83 | |
68 | 84 | try { |
69 | 85 | $result = $this->selectQuery($this->selectBuilder->select($this->table, $query['sql'], $query['args'], $options)); |
70 | 86 | $this->databaseModify->addIndex(array_keys($query['args'])); |
71 | 87 | $this->databaseModify->addIndex(explode(',', $options['order'])); |
72 | - } |
|
73 | - catch (\Exception $e) { |
|
88 | + } catch (\Exception $e) { |
|
74 | 89 | $this->errors[] = $e; |
75 | 90 | $result = []; |
76 | 91 | } |
77 | 92 | } |
78 | 93 | |
79 | - if ($this->cacheMode < 0) return $result; // Cache mode is off |
|
94 | + if ($this->cacheMode < 0) { |
|
95 | + return $result; |
|
96 | + } |
|
97 | + // Cache mode is off |
|
80 | 98 | |
81 | 99 | if ($this->cacheUpdateRequired($cacheId)) { |
82 | 100 | $this->idCache[$cacheId] = $result; |
@@ -88,7 +106,9 @@ discard block |
||
88 | 106 | |
89 | 107 | public function findAggregate($function, $field, $group = null, array $criteria = [], array $options = []) { |
90 | 108 | //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 |
91 | - if (is_array($field)) $field = $field[0]; |
|
109 | + if (is_array($field)) { |
|
110 | + $field = $field[0]; |
|
111 | + } |
|
92 | 112 | $query = $this->whereBuilder->createSql($criteria); |
93 | 113 | |
94 | 114 | try { |
@@ -97,8 +117,7 @@ discard block |
||
97 | 117 | $result = $this->selectQuery($this->selectBuilder->aggregate($this->table, $function, $field, $query['sql'], $query['args'], $group)); |
98 | 118 | |
99 | 119 | return $this->determineAggregateResult($result, $group, $field); |
100 | - } |
|
101 | - catch (\Exception $e) { |
|
120 | + } catch (\Exception $e) { |
|
102 | 121 | return $group ? [] : 0; |
103 | 122 | } |
104 | 123 | } |
@@ -106,11 +125,15 @@ discard block |
||
106 | 125 | private function determineAggregateResult($result, $group, $field) { |
107 | 126 | if ($group != null) { |
108 | 127 | $ret = []; |
109 | - foreach ($result as $res) $ret[$res->$field] = $res->val; |
|
128 | + foreach ($result as $res) { |
|
129 | + $ret[$res->$field] = $res->val; |
|
130 | + } |
|
110 | 131 | return $ret; |
132 | + } else if (isset($result[0])) { |
|
133 | + return $result[0]->val; |
|
134 | + } else { |
|
135 | + return 0; |
|
111 | 136 | } |
112 | - else if (isset($result[0])) return $result[0]->val; |
|
113 | - else return 0; |
|
114 | 137 | } |
115 | 138 | |
116 | 139 | private function selectQuery(\Maphper\Lib\Query $query) { |
@@ -118,17 +141,24 @@ discard block |
||
118 | 141 | } |
119 | 142 | |
120 | 143 | public function clearResultCache() { |
121 | - if ($this->cacheMode >= 0) $this->resultCache = []; |
|
144 | + if ($this->cacheMode >= 0) { |
|
145 | + $this->resultCache = []; |
|
146 | + } |
|
122 | 147 | } |
123 | 148 | |
124 | 149 | public function clearIDCache() { |
125 | - if ($this->cacheMode >= 0) $this->idCache = []; |
|
150 | + if ($this->cacheMode >= 0) { |
|
151 | + $this->idCache = []; |
|
152 | + } |
|
126 | 153 | } |
127 | 154 | |
128 | 155 | public function updateCache($data, $pkValue) { |
129 | 156 | if ($this->cacheMode >= 0) { |
130 | - if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data); |
|
131 | - else $this->cache[$pkValue] = $data; |
|
157 | + if (isset($this->cache[$pkValue])) { |
|
158 | + $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data); |
|
159 | + } else { |
|
160 | + $this->cache[$pkValue] = $data; |
|
161 | + } |
|
132 | 162 | } |
133 | 163 | } |
134 | 164 |