Total Complexity | 3 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
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 |
||
56 | ]; |
||
57 | } |
||
59 |