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

DefaultConfigurator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 49
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
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