Image   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A __construct() 0 7 1
A get() 0 7 2
1
<?php
2
/**
3
 * Created by jensk on 12-10-2017.
4
 */
5
6
namespace CloudControl\Cms\storage\entities;
7
8
9
use CloudControl\Cms\cc\Request;
10
11
/**
12
 * Class Image
13
 * @package CloudControl\Cms\services\imageservice
14
 */
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()
55
    {
56
        return Request::$subfolders . $this->imagePath . '/' . $this->file;
57
    }
58
}