Passed
Push — master ( 7eed51...bf5fb9 )
by Charis
02:15
created

Photo::getAvailableRatios()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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