Passed
Push — main ( b13b1c...30676d )
by Emlyn
12:24
created

AbstractIO   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 55
ccs 12
cts 12
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfig() 0 3 1
A __construct() 0 3 1
A getConfig() 0 16 4
1
<?php
2
/**
3
 * @category Library
4
 * @license MIT http://opensource.org/licenses/MIT
5
 * @link https://github.com/emlynwest/changelog
6
 */
7
8
namespace ChangeLog;
9
10
/**
11
 * Common logic for providers
12
 */
13
abstract class AbstractIO implements IOInterface
14
{
15
16
	/**
17
	 * Stores the provider's config.
18
	 * @var array
19
	 */
20
	protected $config = [];
21
22
	/**
23
	 * Stores any default values for the config.
24
	 * @var array
25
	 */
26
	protected $configDefaults = [];
27
28
	/**
29
	 * @param array $config
30
	 */
31 25
	public function __construct($config = [])
32
	{
33 25
		$this->setConfig($config);
34
	}
35
36
	/**
37
	 * {@inheritdoc}
38
	 */
39 25
	public function setConfig($config)
40
	{
41 25
		$this->config = $config;
42
	}
43
44
	/**
45
	 * Gets the given config key, will load from config defaults if not set or return
46
	 * null if there is no default.
47
	 *
48
	 * @param string|int $key
49
	 *
50
	 * @return string|array
51
	 */
52 23
	public function getConfig($key = null)
53
	{
54 23
		if ($key === null)
55
		{
56 2
			return array_merge($this->configDefaults, $this->config);
57
		}
58 22
		elseif (isset($this->config[$key]))
59
		{
60 18
			return $this->config[$key];
61
		}
62 19
		elseif (isset($this->configDefaults[$key]))
63
		{
64 15
			return $this->configDefaults[$key];
65
		}
66
67 5
		return null;
68
	}
69
70
}
71