Code Duplication    Length = 28-28 lines in 2 locations

src/Facility.php 1 location

@@ 13-40 (lines=28) @@
10
use CultuurNet\UDB3\Model\ValueObject\Taxonomy\Category\Category as Udb3ModelCategory;
11
use InvalidArgumentException;
12
13
final class Facility extends Category
14
{
15
    const DOMAIN = 'facility';
16
17
    public function __construct($id, $label)
18
    {
19
        parent::__construct($id, $label, self::DOMAIN);
20
    }
21
22
    public static function deserialize(array $data): Facility
23
    {
24
        return new self($data['id'], $data['label']);
25
    }
26
27
    public static function fromUdb3ModelCategory(Udb3ModelCategory $category): Facility
28
    {
29
        $label = $category->getLabel();
30
31
        if (is_null($label)) {
32
            throw new InvalidArgumentException('Category label is required.');
33
        }
34
35
        return new self(
36
            $category->getId()->toString(),
37
            $label->toString()
38
        );
39
    }
40
}
41

src/Theme.php 1 location

@@ 13-40 (lines=28) @@
10
use CultuurNet\UDB3\Model\ValueObject\Taxonomy\Category\Category as Udb3ModelCategory;
11
use InvalidArgumentException;
12
13
final class Theme extends Category
14
{
15
    const DOMAIN = 'theme';
16
17
    public function __construct($id, $label)
18
    {
19
        parent::__construct($id, $label, self::DOMAIN);
20
    }
21
22
    public static function deserialize(array $data): Theme
23
    {
24
        return new self($data['id'], $data['label']);
25
    }
26
27
    public static function fromUdb3ModelCategory(Udb3ModelCategory $category): Theme
28
    {
29
        $label = $category->getLabel();
30
31
        if (is_null($label)) {
32
            throw new InvalidArgumentException('Category label is required.');
33
        }
34
35
        return new self(
36
            $category->getId()->toString(),
37
            $label->toString()
38
        );
39
    }
40
}
41