| Total Complexity | 3 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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() |
||
| 62 | ); |
||
| 63 | } |
||
| 65 |