ContentType::getFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Seams-CMS Delivery SDK package.
7
 *
8
 * (c) Seams-CMS.com
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace SeamsCMS\Delivery\Model;
15
16
use SeamsCMS\Delivery\Exception\MissingFieldsException;
17
18
/**
19
 * Class ContentType
20
 * @package SeamsCMS\Delivery\Model
21
 */
22
class ContentType
23
{
24
    use HydratorTrait {
25
        fromArray as private fromArrayTrait;
26
    }
27
28
    /** @var string */
29
    private $id = "";
30
    /** @var string */
31
    private $name = "";
32
    /** @var string */
33
    private $description = "";
34
    /** @var ContentTypeField[] */
35
    private $fields = [];
36
37
38
    /**
39
     * ContentType constructor.
40
     *
41
     */
42 2
    final protected function __construct()
43
    {
44 2
    }
45
46
    /**
47
     * @return string
48
     */
49 2
    public function getId(): string
50
    {
51 2
        return $this->id;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 2
    public function getName(): string
58
    {
59 2
        return $this->name;
60
    }
61
62
    /**
63
     * @return string
64
     */
65 2
    public function getDescription(): string
66
    {
67 2
        return $this->description;
68
    }
69
70
    /**
71
     * @return ContentTypeField[]
72
     */
73 1
    public function getFields(): array
74
    {
75 1
        return $this->fields;
76
    }
77
78
    /**
79
     * @param array $data
80
     * @return ContentType
81
     */
82 3
    public static function fromArray(array $data)
83
    {
84 3
        if (! isset($data['fields'])) {
85 1
            throw MissingFieldsException::fieldsNotFound();
86
        }
87
88 2
        $data['fields'] = array_map(function ($item) {
89 1
            return ContentTypeField::fromArray($item);
90 2
        }, $data['fields']);
91
92 2
        return self::fromArrayTrait($data);
93
    }
94
}
95