Photo   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAvailableRatios() 0 8 1
A __construct() 0 15 2
1
<?php declare(strict_types=1);
2
3
namespace One\Model;
4
5
use One\Collection;
6
7
class Photo extends Model
8
{
9
    public const RATIO_SQUARE = '1:1';
10
11
    public const RATIO_RECTANGLE = '2:1';
12
13
    public const RATIO_HEADLINE = '3:2';
14
15
    public const RATIO_VERTICAL = '9:16';
16
17
    public const RATIO_COVER = 'cover';
18
19
    /**
20
     * constructor
21
     *
22
     * @param \Psr\Http\Message\UriInterface|string $url
23
     * @param string $ratio
24
     * @param string $description
25
     * @param string $information
26
     */
27
    public function __construct(
28
        $url,
29
        $ratio,
30
        $description = '',
31
        $information = ''
32
    ) {
33
        if (! in_array($ratio, $this->getAvailableRatios(), true)) {
34
            throw new \Exception("ratio ${ratio} not allowed, allowed ratio are " . implode(', ', $this->getAvailableRatios()));
35
        }
36
37
        $this->collection = new Collection([
38
            'url' => $this->filterUriInstance($url),
39
            'ratio' => $ratio,
40
            'description' => $this->filterStringInstance($description),
41
            'information' => $this->filterStringInstance($information),
42
        ]);
43
    }
44
45
    /**
46
     * get available ratio for photo attachment
47
     */
48
    private function getAvailableRatios(): array
49
    {
50
        return [
51
            self::RATIO_SQUARE,
52
            self::RATIO_RECTANGLE,
53
            self::RATIO_HEADLINE,
54
            self::RATIO_VERTICAL,
55
            self::RATIO_COVER,
56
        ];
57
    }
58
}
59