AbstractConfigurable::configure()   B
last analyzed

Complexity

Conditions 9
Paths 6

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 9

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 13
cts 13
cp 1
rs 7.756
c 0
b 0
f 0
cc 9
eloc 11
nc 6
nop 1
crap 9
1
<?php
2
3
namespace CSSPrites;
4
5
abstract class AbstractConfigurable
6
{
7 21
    public function configure(array $config = [])
8
    {
9 21
        if (is_array($config) && array_key_exists('filename', $config)) {
10 18
            $config['filepath']  = isset($config['filepath']) && is_string($config['filepath']) ? $config['filepath'] : '.';
11 18
            $config['filepath'] .= '/';
12 18
            $config['filepath'] .= isset($config['filename']) && is_string($config['filename']) ? $config['filename'] : 'sprite.png';
13 18
            unset($config['filename']);
14 18
        }
15
16 21
        foreach ($config as $key => $value) {
17 21
            if (!property_exists($this, $key)) {
18 3
                throw new \Exception('Undefined configuration property "'.$key.'"');
19
            }
20 18
            $this->$key = $value;
21 18
        }
22
23 18
        return $this;
24
    }
25
}
26