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

DefaultConfigurator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 3
A configure() 0 9 1
A getConfig() 0 3 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