Passed
Push — master ( cd5206...92cf14 )
by Tom
02:02
created

PropertyWriter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A processDates() 0 3 1
A write() 0 4 3
1
<?php
2
namespace Maphper\Lib;
3
class PropertyWriter {
4
	private $closure;
5
	public function __construct($object) {
6
		if ($object instanceof \stdclass) {
7
			$this->closure = function ($field, $value) use ($object) { $object->$field = $value; };
8
		}
9
		else {
10
			$this->closure = function ($field, $value) { $this->$field = $value; };
11
			$this->closure = $this->closure->bindTo($object, $object);
12
		}
13
	}
14
15
	public function write($data) {
16
		if ($data != null) {
17
			foreach ($data as $key => $value) {
18
				($this->closure)($key,  $this->processDates($value));
19
			}
20
		}
21
	}
22
23
	private function processDates($obj) {
24
		$injector = new DateInjector;
25
		return $injector->replaceDates($obj);
26
	}
27
}