Conditions | 3 |
Paths | 3 |
Total Lines | 20 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3.054 |
Changes | 0 |
1 | <?php |
||
27 | 1 | public function factor(array $item) |
|
28 | { |
||
29 | //lowercase properties because the naming-strategy of jms serializer depends on lowercase'd prop's |
||
30 | 1 | $item = array_change_key_case($item, CASE_LOWER); |
|
31 | 1 | $json = json_encode($item); |
|
32 | |||
33 | 1 | $cacheKey = md5($json); |
|
34 | 1 | if (isset($this->cache[$cacheKey])) { |
|
35 | return $this->cache[$cacheKey]; |
||
36 | } |
||
37 | |||
38 | 1 | $object = $this->serializer->deserialize($json, $this->classname, 'json'); |
|
39 | 1 | $this->cache[$cacheKey] = $object; |
|
40 | |||
41 | 1 | if (count($this->cache) > 100) { |
|
42 | array_shift($this->cache); //cut last one |
||
43 | } |
||
44 | |||
45 | 1 | return $object; |
|
46 | } |
||
47 | } |
||
48 |