Passed
Push — master ( 260455...4746f9 )
by Brent
04:30
created

DefaultConfigurator::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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