Completed
Push — master ( d252f0...d75c62 )
by Jonas
22s queued 11s
created

Theme::deserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3;
4
5
use CultuurNet\UDB3\Model\ValueObject\Taxonomy\Category\Category as Udb3ModelCategory;
6
use InvalidArgumentException;
7
8
final class Theme extends Category
9
{
10
    public const DOMAIN = 'theme';
11
12
    public function __construct(string $id, string $label)
13
    {
14
        parent::__construct($id, $label, self::DOMAIN);
15
    }
16
17
    public static function deserialize(array $data): Theme
18
    {
19
        return new self($data['id'], $data['label']);
20
    }
21
22
    public static function fromUdb3ModelCategory(Udb3ModelCategory $category): Theme
23
    {
24
        $label = $category->getLabel();
25
26
        if (is_null($label)) {
27
            throw new InvalidArgumentException('Category label is required.');
28
        }
29
30
        return new self(
31
            $category->getId()->toString(),
32
            $label->toString()
33
        );
34
    }
35
}
36