Completed
Push — master ( 11a376...8d38b3 )
by Andrii
03:54
created

AbstractModifier::create()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6.0073

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
ccs 16
cts 17
cp 0.9412
rs 8.7624
cc 6
eloc 13
nc 24
nop 1
crap 6.0073
1
<?php
2
/**
3
 * Changelog keeper
4
 *
5
 * @link      https://github.com/hiqdev/chkipper
6
 * @package   chkipper
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\chkipper\modifiers;
12
13
use hiqdev\chkipper\history\History;
14
15
/**
16
 * Abstract modifier class.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
abstract class AbstractModifier implements ModifierInterface
21
{
22
    abstract public function run(History $history);
23
24
    /**
25
     * Creates modifier from given config.
26
     *
27
     * @param string|array $config
28
     * @return AbstractModifier
29
     */
30 2
    public static function create($config = [])
31
    {
32 2
        if (is_string($config)) {
33 2
            $config = ['class' => $config];
34 2
        }
35 2
        $class = isset($config['class']) ? $config['class'] : get_called_class();
36 2
        unset($config['class']);
37
38 2
        if (!class_exists($class)) {
39 2
            $local = __NAMESPACE__ . '\\' . $class;
40 2
            if (class_exists($local)) {
41 2
                $class = $local;
42 2
            }
43 2
        }
44 2
        $modifier = new $class();
45 2
        foreach ($config as $key => $value) {
46
            $modifier->$key = $value;
47 2
        }
48
49 2
        return $modifier;
50
    }
51
}
52