| Total Complexity | 4 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class Image |
||
| 16 | { |
||
| 17 | protected $imagePath; |
||
| 18 | public $file; |
||
| 19 | public $type; |
||
| 20 | public $size; |
||
| 21 | public $set; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Image constructor. |
||
| 25 | * @param \stdClass $image |
||
| 26 | * @param string $imagePath |
||
| 27 | */ |
||
| 28 | public function __construct(\stdClass $image, $imagePath = 'images') |
||
| 29 | { |
||
| 30 | $this->file = $image->file; |
||
| 31 | $this->type = $image->type; |
||
| 32 | $this->size = $image->size; |
||
| 33 | $this->set = $image->set; |
||
| 34 | $this->imagePath = $imagePath; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param string $imageVariant |
||
| 39 | * @return string |
||
| 40 | * @throws \Exception |
||
| 41 | */ |
||
| 42 | public function get($imageVariant = 'original') |
||
| 43 | { |
||
| 44 | if (!isset($this->set->{$imageVariant})) { |
||
| 45 | throw new \Exception('Image variant `' . $imageVariant . '` does not exist. Existing variants are ' . implode(', ', |
||
| 46 | array_keys((array)$this->set))); |
||
| 47 | } |
||
| 48 | return Request::$subfolders . $this->imagePath . '/' . $this->set->{$imageVariant}; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | public function __toString() |
||
| 57 | } |
||
| 58 | } |