@@ -76,13 +76,17 @@ discard block  | 
                                                    ||
| 76 | 76 |  	private function processFilters($value) { | 
                                                        
| 77 | 77 | //When saving to a mapper with filters, write the filters back into the object being stored  | 
                                                        
| 78 | 78 |  		foreach ($this->settings['filter'] as $key => $filterValue) { | 
                                                        
| 79 | - if (empty($value->$key) && !is_array($filterValue)) $value->$key = $filterValue;  | 
                                                        |
| 79 | +			if (empty($value->$key) && !is_array($filterValue)) { | 
                                                        |
| 80 | + $value->$key = $filterValue;  | 
                                                        |
| 81 | + }  | 
                                                        |
| 80 | 82 | }  | 
                                                        
| 81 | 83 | return $value;  | 
                                                        
| 82 | 84 | }  | 
                                                        
| 83 | 85 | |
| 84 | 86 |  	public function offsetSet($offset, $valueObj) { | 
                                                        
| 85 | - if ($valueObj instanceof \Maphper\Relation) throw new \Exception();  | 
                                                        |
| 87 | +		if ($valueObj instanceof \Maphper\Relation) { | 
                                                        |
| 88 | + throw new \Exception();  | 
                                                        |
| 89 | + }  | 
                                                        |
| 86 | 90 | |
| 87 | 91 | //Extract private properties from the object  | 
                                                        
| 88 | 92 | $propertyReader = new \Maphper\Lib\VisibilityOverride();  | 
                                                        
@@ -90,7 +94,9 @@ discard block  | 
                                                    ||
| 90 | 94 | |
| 91 | 95 | $value = $this->processFilters($value);  | 
                                                        
| 92 | 96 | $pk = $this->dataSource->getPrimaryKey();  | 
                                                        
| 93 | -		if ($offset !== null) $value->{$pk[0]} = $offset; | 
                                                        |
| 97 | +		if ($offset !== null) { | 
                                                        |
| 98 | +			$value->{$pk[0]} = $offset; | 
                                                        |
| 99 | + }  | 
                                                        |
| 94 | 100 | $valueCopy = clone $value;  | 
                                                        
| 95 | 101 | $value = $this->wrap($value);  | 
                                                        
| 96 | 102 | $this->dataSource->save($value);  | 
                                                        
@@ -99,7 +105,9 @@ discard block  | 
                                                    ||
| 99 | 105 | }  | 
                                                        
| 100 | 106 | |
| 101 | 107 |  	public function offsetExists($offset) { | 
                                                        
| 102 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey());  | 
                                                        |
| 108 | +		if (count($this->dataSource->getPrimaryKey()) > 1) { | 
                                                        |
| 109 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey());  | 
                                                        |
| 110 | + }  | 
                                                        |
| 103 | 111 |          if (!empty($this->settings['filter'])) { | 
                                                        
| 104 | 112 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset]));  | 
                                                        
| 105 | 113 | return isset($data[0]);  | 
                                                        
@@ -112,7 +120,9 @@ discard block  | 
                                                    ||
| 112 | 120 | }  | 
                                                        
| 113 | 121 | |
| 114 | 122 |  	public function offsetGet($offset) { | 
                                                        
| 115 | - 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 | + }  | 
                                                        |
| 116 | 126 |          if (!empty($this->settings['filter'])) { | 
                                                        
| 117 | 127 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset]));  | 
                                                        
| 118 | 128 | return $this->wrap($this->createNew(isset($data[0]) ? $data[0] : null));  | 
                                                        
@@ -121,7 +131,9 @@ discard block  | 
                                                    ||
| 121 | 131 | }  | 
                                                        
| 122 | 132 | |
| 123 | 133 |  	private function createNew($data = [], $obj = null) { | 
                                                        
| 124 | - if (!$obj) $obj = (is_callable($this->settings['resultClass'])) ? call_user_func($this->settings['resultClass']) : new $this->settings['resultClass'];  | 
                                                        |
| 134 | +		if (!$obj) { | 
                                                        |
| 135 | + $obj = (is_callable($this->settings['resultClass'])) ? call_user_func($this->settings['resultClass']) : new $this->settings['resultClass'];  | 
                                                        |
| 136 | + }  | 
                                                        |
| 125 | 137 | $writer = new Lib\PropertyWriter($obj);  | 
                                                        
| 126 | 138 | $writer->write($data);  | 
                                                        
| 127 | 139 | return $obj;  | 
                                                        
@@ -132,7 +144,9 @@ discard block  | 
                                                    ||
| 132 | 144 |  		foreach ($this->relations as $name => $relation) { | 
                                                        
| 133 | 145 |  			if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation) ) { | 
                                                        
| 134 | 146 | //After overwriting the relation, does the parent object ($object) need overwriting as well?  | 
                                                        
| 135 | - if ($relation->overwrite($object, $object->$name)) $this[] = $object;  | 
                                                        |
| 147 | +				if ($relation->overwrite($object, $object->$name)) { | 
                                                        |
| 148 | + $this[] = $object;  | 
                                                        |
| 149 | + }  | 
                                                        |
| 136 | 150 | }  | 
                                                        
| 137 | 151 | |
| 138 | 152 | $object->$name = $relation->getData($object, $siblings);  | 
                                                        
@@ -144,11 +158,15 @@ discard block  | 
                                                    ||
| 144 | 158 |  	public function __call($method, $args) { | 
                                                        
| 145 | 159 |  		if (array_key_exists($method, $this->settings)) { | 
                                                        
| 146 | 160 | $maphper = new Maphper($this->dataSource, $this->settings, $this->relations);  | 
                                                        
| 147 | - if (is_array($maphper->settings[$method])) $maphper->settings[$method] = $args[0] + $maphper->settings[$method];  | 
                                                        |
| 148 | - else $maphper->settings[$method] = $args[0];  | 
                                                        |
| 161 | +			if (is_array($maphper->settings[$method])) { | 
                                                        |
| 162 | + $maphper->settings[$method] = $args[0] + $maphper->settings[$method];  | 
                                                        |
| 163 | +			} else { | 
                                                        |
| 164 | + $maphper->settings[$method] = $args[0];  | 
                                                        |
| 165 | + }  | 
                                                        |
| 149 | 166 | return $maphper;  | 
                                                        
| 167 | +		} else { | 
                                                        |
| 168 | +			throw new \Exception('Method Maphper::' . $method . ' does not exist'); | 
                                                        |
| 150 | 169 | }  | 
                                                        
| 151 | -		else throw new \Exception('Method Maphper::' . $method . ' does not exist'); | 
                                                        |
| 152 | 170 | }  | 
                                                        
| 153 | 171 | |
| 154 | 172 |  	public function findAggregate($function, $field, $group = null) { | 
                                                        
@@ -6,25 +6,35 @@  | 
                                                    ||
| 6 | 6 | |
| 7 | 7 |  	public function replaceDates($obj, $reset = true) { | 
                                                        
| 8 | 8 | //prevent infinite recursion, only process each object once  | 
                                                        
| 9 | - if ($this->checkCache($obj, $reset) == false) return $obj;  | 
                                                        |
| 9 | +		if ($this->checkCache($obj, $reset) == false) { | 
                                                        |
| 10 | + return $obj;  | 
                                                        |
| 11 | + }  | 
                                                        |
| 10 | 12 | |
| 11 | - if (is_array($obj) || (is_object($obj) && ($obj instanceof \Iterator))) foreach ($obj as &$o) $o = $this->replaceDates($o, false);  | 
                                                        |
| 13 | +		if (is_array($obj) || (is_object($obj) && ($obj instanceof \Iterator))) { | 
                                                        |
| 14 | + foreach ($obj as &$o) $o = $this->replaceDates($o, false);  | 
                                                        |
| 15 | + }  | 
                                                        |
| 12 | 16 |  		if (is_string($obj) && isset($obj[0]) && is_numeric($obj[0]) && strlen($obj) <= 20) { | 
                                                        
| 13 | 17 |  			try { | 
                                                        
| 14 | 18 | $date = new \DateTime($obj);  | 
                                                        
| 15 | -				if ($date->format('Y-m-d H:i:s') == substr($obj, 0, 20) || $date->format('Y-m-d') == substr($obj, 0, 10)) $obj = $date; | 
                                                        |
| 16 | - }  | 
                                                        |
| 17 | -			catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date | 
                                                        |
| 19 | +				if ($date->format('Y-m-d H:i:s') == substr($obj, 0, 20) || $date->format('Y-m-d') == substr($obj, 0, 10)) { | 
                                                        |
| 20 | + $obj = $date;  | 
                                                        |
| 21 | + }  | 
                                                        |
| 22 | +			} catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date | 
                                                        |
| 18 | 23 | }  | 
                                                        
| 19 | 24 | }  | 
                                                        
| 20 | 25 | return $obj;  | 
                                                        
| 21 | 26 | }  | 
                                                        
| 22 | 27 | |
| 23 | 28 |  	private function checkCache($obj, $reset) { | 
                                                        
| 24 | - if ($reset) $this->processCache = new \SplObjectStorage();  | 
                                                        |
| 29 | +		if ($reset) { | 
                                                        |
| 30 | + $this->processCache = new \SplObjectStorage();  | 
                                                        |
| 31 | + }  | 
                                                        |
| 25 | 32 | |
| 26 | - if (is_object($obj) && $this->processCache->contains($obj)) return $obj;  | 
                                                        |
| 27 | - else if (is_object($obj)) $this->processCache->attach($obj, true);  | 
                                                        |
| 33 | +		if (is_object($obj) && $this->processCache->contains($obj)) { | 
                                                        |
| 34 | + return $obj;  | 
                                                        |
| 35 | +		} else if (is_object($obj)) { | 
                                                        |
| 36 | + $this->processCache->attach($obj, true);  | 
                                                        |
| 37 | + }  | 
                                                        |
| 28 | 38 | |
| 29 | 39 | return false;  | 
                                                        
| 30 | 40 | }  | 
                                                        
@@ -4,10 +4,10 @@ discard block  | 
                                                    ||
| 4 | 4 | private $closure;  | 
                                                        
| 5 | 5 |  	public function __construct($object) { | 
                                                        
| 6 | 6 |  		if ($object instanceof \stdclass) { | 
                                                        
| 7 | -			$this->closure = function ($field, $value) use ($object) { $object->$field = $value; }; | 
                                                        |
| 7 | +			$this->closure = function($field, $value) use ($object) { $object->$field = $value; }; | 
                                                        |
| 8 | 8 | }  | 
                                                        
| 9 | 9 |  		else { | 
                                                        
| 10 | -			$this->closure = function ($field, $value) { $this->$field = $value; }; | 
                                                        |
| 10 | +			$this->closure = function($field, $value) { $this->$field = $value; }; | 
                                                        |
| 11 | 11 | $this->closure = $this->closure->bindTo($object, $object);  | 
                                                        
| 12 | 12 | }  | 
                                                        
| 13 | 13 | }  | 
                                                        
@@ -15,7 +15,7 @@ discard block  | 
                                                    ||
| 15 | 15 |  	public function write($data) { | 
                                                        
| 16 | 16 |  		if ($data != null) { | 
                                                        
| 17 | 17 |  			foreach ($data as $key => $value) { | 
                                                        
| 18 | - ($this->closure)($key, $this->processDates($value));  | 
                                                        |
| 18 | + ($this->closure)($key, $this->processDates($value));  | 
                                                        |
| 19 | 19 | }  | 
                                                        
| 20 | 20 | }  | 
                                                        
| 21 | 21 | }  |