Passed
Branch master (cd5206)
by Tom
02:53 queued 58s
created

PropertyWriter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 2 1
A __construct() 0 7 2
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 __set($field, $value) {
16
		($this->closure)($field, $value);
17
	}
18
}