@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | public function overwrite($parentObject, &$data) { |
| 32 | 32 | $this->results = $data; |
| 33 | 33 | $this->object = $parentObject; |
| 34 | - foreach ($data as $dt) $this[] = $dt; |
|
| 34 | + foreach ($data as $dt) { |
|
| 35 | + $this[] = $dt; |
|
| 36 | + } |
|
| 35 | 37 | } |
| 36 | 38 | |
| 37 | 39 | //bit hacky, breaking encapsulation, but simplest way to work out the info for the other side of the many:many relationship. |
@@ -86,8 +88,9 @@ discard block |
||
| 86 | 88 | |
| 87 | 89 | public function offsetSet($name, $value) { |
| 88 | 90 | list($relatedField, $valueField, $mapper) = $this->getOtherFieldNameInfo(); |
| 89 | - if ($this->autoTraverse) $this->offsetSetAutotraverse($value, $relatedField, $valueField); |
|
| 90 | - else if ($this->doUpdateInterMapper($value, $relatedField, $valueField)) { |
|
| 91 | + if ($this->autoTraverse) { |
|
| 92 | + $this->offsetSetAutotraverse($value, $relatedField, $valueField); |
|
| 93 | + } else if ($this->doUpdateInterMapper($value, $relatedField, $valueField)) { |
|
| 91 | 94 | $record = $value; |
| 92 | 95 | $record->{$this->parentField} = $value->{$this->intermediateName}->{$this->localField}; |
| 93 | 96 | $record->$valueField = $this->object->{$relatedField}; |
@@ -9,7 +9,9 @@ discard block |
||
| 9 | 9 | private $siblings = []; |
| 10 | 10 | |
| 11 | 11 | public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $criteria = []) { |
| 12 | - if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
| 12 | + if ($criteria) { |
|
| 13 | + $mapper = $mapper->filter($this->criteira); |
|
| 14 | + } |
|
| 13 | 15 | $this->mapper = $mapper; |
| 14 | 16 | $this->parentField = $parentField; |
| 15 | 17 | $this->localField = $localField; |
@@ -29,7 +31,9 @@ discard block |
||
| 29 | 31 | private function lazyLoad() { |
| 30 | 32 | if (!isset($this->data)) { |
| 31 | 33 | |
| 32 | - if ($this->parentObject == null) throw new \Exception('Error, no object set'); |
|
| 34 | + if ($this->parentObject == null) { |
|
| 35 | + throw new \Exception('Error, no object set'); |
|
| 36 | + } |
|
| 33 | 37 | |
| 34 | 38 | $this->eagerLoad(); |
| 35 | 39 | |
@@ -69,13 +73,18 @@ discard block |
||
| 69 | 73 | } |
| 70 | 74 | |
| 71 | 75 | public function __call($func, array $args = []) { |
| 72 | - if ($this->lazyLoad() == null) return ''; |
|
| 76 | + if ($this->lazyLoad() == null) { |
|
| 77 | + return ''; |
|
| 78 | + } |
|
| 73 | 79 | return call_user_func_array([$this->lazyLoad(), $func], $args); |
| 74 | 80 | } |
| 75 | 81 | |
| 76 | 82 | public function __get($name) { |
| 77 | - if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
|
| 78 | - else return null; |
|
| 83 | + if ($this->lazyLoad()) { |
|
| 84 | + return $this->lazyLoad()->$name; |
|
| 85 | + } else { |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 79 | 88 | } |
| 80 | 89 | |
| 81 | 90 | public function __isset($name) { |
@@ -27,7 +27,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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) { |