BlockUnserializer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace TheCodingMachine\CMS\Serializer;
5
6
use TheCodingMachine\CMS\Block\Block;
7
use TheCodingMachine\CMS\Block\CacheableBlock;
8
9
/**
10
 * Class in charge of creating a block from a JSON message.
11
 */
12
class BlockUnserializer
13
{
14
    /**
15
     * @var ThemeUnserializerInterface
16
     */
17
    private $themeUnserializer;
18
19
    public function __construct(ThemeUnserializerInterface $themeUnserializer)
20
    {
21
        $this->themeUnserializer = $themeUnserializer;
22
    }
23
24
    /**
25
     * @param mixed[] $arr
26
     * @return Block
27
     */
28
    public function createFromArray(array $arr): Block
29
    {
30
        $context = $arr['context'];
31
        $themeDescriptor = $this->themeUnserializer->createFromArray($arr['theme']);
32
33
        if (isset($arr['ttl'])) {
34
            return new CacheableBlock($themeDescriptor, $context, $arr['key'], $arr['ttl'], $arr['tags']);
35
        } else {
36
            return new Block($themeDescriptor, $context);
37
        }
38
    }
39
40
}