Converter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace Soluble\Media;
3
4
use Zend\Cache\Storage\StorageInterface;
5
6
class Converter
7
{
8
    /**
9
     *
10
     * @var boolean
11
     */
12
    protected $cacheEnabled = false;
13
14
    /**
15
     *
16
     * @var StorageInterface
17
     */
18
    protected $cacheStorage;
19
20
    public function __construct()
21
    {
22
    }
23
24
    /**
25
     * @return Converter\ConverterInterface
26
     */
27
    public function createConverter($key, array $params = [])
28
    {
29
        switch (strtolower($key)) {
30
            case 'image':
31
                $converter = new Converter\ImageConverter($params);
32
                break;
33
34
            default:
35
                throw new \Exception("Only image converter is supported");
36
        }
37
        if ($this->cacheStorage !== null) {
38
            $converter->setCache($this->cacheStorage);
39
        }
40
        return $converter;
41
    }
42
43
    /**
44
     *
45
     * @param StorageInterface $storage
46
     * @return \Soluble\Media\Converter\ImageConverter
47
     */
48
    public function setCache(StorageInterface $storage)
49
    {
50
        $this->cacheStorage = $storage;
51
        $this->cacheEnabled = true;
52
        return $this;
53
    }
54
55
    /**
56
     * Unset cache (primarly for unit testing)
57
     * @return \Soluble\Media\Converter\ImageConverter
58
     */
59
    public function unsetCache()
60
    {
61
        $this->cacheEnabled = false;
62
        $this->cacheStorage = null;
63
        return $this;
64
    }
65
}
66