Passed
Push — master ( 4b5f24...20219f )
by Brent
02:15
created

DefaultConfigurator::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace brendt\image\config;
4
5
use brendt\image\exception\InvalidConfigurationException;
6
use brendt\image\ResponsiveFactory;
7
8
class DefaultConfigurator implements ResponsiveFactoryConfigurator {
9
10
    protected $config = [
11
        'driver'       => 'gd',
12
        'publicPath'   => './',
13
        'sourcePath'   => './',
14
        'enableCache'  => false,
15
        'stepModifier' => 0.1,
16
        'minSize'      => 300,
17
    ];
18
19
    /**
20
     * ResponsiveFactoryConfigurator constructor.
21
     *
22
     * @param array $config
23
     *
24
     * @throws InvalidConfigurationException
25
     */
26
    public function __construct(array $config = []) {
27
        if (isset($config['driver']) && !in_array($config['driver'], ['gd', 'imagick'])) {
28
            throw new InvalidConfigurationException('Invalid driver. Possible drivers are `gd` and `imagick`');
29
        }
30
31
        $this->config = array_merge($this->config, $config);
32
    }
33
34
    /**
35
     * @param ResponsiveFactory $factory
36
     *
37
     * @return void
38
     */
39
    public function configure(ResponsiveFactory $factory) {
40
        $factory
41
            ->setDriver($this->config['driver'])
42
            ->setPublicPath($this->config['publicPath'])
43
            ->setSourcePath($this->config['sourcePath'])
44
            ->setEnableCache($this->config['enableCache'])
45
            ->setStepModifier($this->config['stepModifier'])
46
            ->setMinSize($this->config['minSize']);
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function getConfig() {
53
        return $this->config;
54
    }
55
}
56