AbstractTransformer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
ccs 0
cts 21
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaults() 0 4 1
B parseOptions() 0 19 5
parseOptionsString() 0 1 ?
1
<?php
2
namespace SvImages\Transformer;
3
4
use Intervention\Image;
5
use SvImages\Exception\InvalidArgumentException;
6
7
/**
8
 * @author Vytautas Stankus <[email protected]>
9
 * @license MIT
10
 */
11
abstract class AbstractTransformer implements TransformerInterface
12
{
13
    /**
14
     * Default transformer options
15
     *
16
     * @var array
17
     */
18
    protected $defaults = [];
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function setDefaults(array $defaults)
24
    {
25
        $this->defaults = array_merge($this->defaults, $defaults);
26
    }
27
28
    /**
29
     * Parse and validates options
30
     *
31
     * @param string|array $options
32
     *
33
     * @return array
34
     * @throws InvalidArgumentException
35
     */
36
    protected function parseOptions($options)
37
    {
38
        $parsed_options = [];
39
40
        if (!empty($options)) {
41
            if (is_string($options)) {
42
                $parsed_options = $this->parseOptionsString($options);
43
            } elseif (is_array($options)) {
44
                $parsed_options = $options;
45
            } else {
46
                throw new InvalidArgumentException(sprintf(
47
                    'Expected string or array as parameters but got %s',
48
                    (is_object($options) ? get_class($options) : gettype($options))
49
                ));
50
            }
51
        }
52
53
        return array_merge($this->defaults, $parsed_options);
54
    }
55
56
    /**
57
     * Parse and validates options from string
58
     *
59
     * @param $options
60
     *
61
     * @return array
62
     */
63
    abstract protected function parseOptionsString($options);
64
}
65