Image::setType()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace LaraComponents\Seo\OpenGraph;
4
5
use LaraComponents\Seo\OpenGraph\Traits\HasUrl;
6
use LaraComponents\Seo\OpenGraph\Traits\HasWidthAndHeight;
7
8
class Image extends Media
9
{
10
    use HasUrl, HasWidthAndHeight;
11
12
    CONST VALID_TYPES = [
13
        'image/jpeg',
14
        'image/png',
15
        'image/gif',
16
        'image/svg+sml',
17
        'image/vnd.microsoft.icon',
18
    ];
19
20
    public function setType($type)
21
    {
22
        if (in_array($type, Image::VALID_TYPES)) {
23
            $this->type = $type;
24
        }
25
26
        return $this;
27
    }
28
29
    public function toArray()
30
    {
31
        $result = [];
32
33
        $result['og:image'] = $this->getUrl();
34
        $result['og:image:type'] = $this->getType();
35
        $result['og:image:secure_url'] = $this->getSecureUrl();
36
        $result['og:image:width'] = $this->getWidth();
37
        $result['og:image:height'] = $this->getHeight();
38
39
        return array_filter($result);
40
    }
41
}
42