Asset::getMimetype()   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 Asset
20
 * @package SeamsCMS\Delivery\Model
21
 */
22
class Asset
23
{
24
    use HydratorTrait {
25
        fromArray as private fromArrayTrait;
26
    }
27
28
    /** @var string */
29
    private $link;
30
    /** @var string|null */
31
    private $thumbnailLink;
32
    /** @var int */
33
    private $size;
34
    /** @var string */
35
    private $path;
36
    /** @var string */
37
    private $title;
38
    /** @var string */
39
    private $mimetype;
40
    /** @var string */
41
    private $workspace;
42
    /** @var AssetMeta */
43
    private $meta;
44
45
46
    /**
47
     * Asset constructor.
48
     *
49
     */
50 7
    final protected function __construct()
51
    {
52 7
    }
53
54
    /**
55
     * @return string
56
     */
57 1
    public function getLink(): string
58
    {
59 1
        return $this->link;
60
    }
61
62
    /**
63
     * @return string|null
64
     */
65 1
    public function getThumbnailLink()
66
    {
67 1
        return $this->thumbnailLink;
68
    }
69
70
    /**
71
     * @return int
72
     */
73 1
    public function getSize(): int
74
    {
75 1
        return $this->size;
76
    }
77
78
    /**
79
     * @return string
80
     */
81 6
    public function getPath(): string
82
    {
83 6
        return $this->path;
84
    }
85
86
    /**
87
     * @return string
88
     */
89 1
    public function getTitle(): string
90
    {
91 1
        return $this->title;
92
    }
93
94
    /**
95
     * @return string
96
     */
97 1
    public function getMimetype(): string
98
    {
99 1
        return $this->mimetype;
100
    }
101
102
    /**
103
     * @return string
104
     */
105 6
    public function getWorkspace(): string
106
    {
107 6
        return $this->workspace;
108
    }
109
110
    /**
111
     * @return AssetMeta
112
     */
113 1
    public function getMeta(): AssetMeta
114
    {
115 1
        return $this->meta;
116
    }
117
118
    /**
119
     * @param array $data
120
     * @return Asset
121
     */
122 10
    public static function fromArray(array $data)
123
    {
124 10
        if (! isset($data['meta']) || ! isset($data['asset'])) {
125 3
            throw MissingFieldsException::metaOrAssetNotFound();
126
        }
127
128 7
        $meta = AssetMeta::fromArray($data['meta']);
129 7
        $data = $data['asset'];
130 7
        $data['meta'] = $meta;
131
132 7
        return self::fromArrayTrait($data);
133
    }
134
}
135