Conditions | 7 |
Paths | 2 |
Total Lines | 26 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 7 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
49 | 3 | public function getFillFn() |
|
50 | { |
||
51 | 3 | if (!$this->fillFn) { |
|
52 | 1 | $this->fillFn = function (array $doc, array $mapping, TypeConverter $typeConverter) { |
|
53 | |||
54 | 1 | foreach ($doc as $name => $val) { |
|
55 | 1 | if (!array_key_exists($name, $mapping)) { |
|
56 | 1 | continue; |
|
57 | } |
||
58 | |||
59 | 1 | $prop = $mapping[$name]; |
|
60 | |||
61 | 1 | $modelName = array_key_exists('prop', $prop) ? $prop['prop'] : $name; |
|
62 | 1 | $setter = array_key_exists('set', $prop) ? $prop['set'] : null; |
|
63 | |||
64 | 1 | $val = $typeConverter->toModel($val, $prop); |
|
65 | |||
66 | $setter |
||
67 | 1 | ? call_user_func([$this, $setter], $val) |
|
68 | 1 | : $this->{$modelName} = $val; |
|
69 | 1 | } |
|
70 | 1 | }; |
|
71 | 3 | } |
|
72 | |||
73 | 3 | return $this->fillFn; |
|
74 | } |
||
75 | } |