Configuration   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 2
dl 0
loc 95
ccs 16
cts 24
cp 0.6667
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromFile() 0 4 1
A defaults() 0 4 1
A getLevelMapping() 0 4 1
A get() 0 4 1
A set() 0 4 1
A extractMapping() 0 7 2
A merge() 0 6 2
1
<?php
2
3
namespace PHPSemVerChecker\Configuration;
4
5
use Noodlehaus\Config;
6
use PHPSemVerChecker\SemanticVersioning\Level;
7
8
class Configuration
9
{
10
	/**
11
	 * @var array
12
	 */
13
	protected $mapping = [];
14
	/**
15
	 * @var \Noodlehaus\Config
16
	 */
17
	protected $config;
18
19
	/**
20
	 * @param string|array $path
21
	 * @throws \Noodlehaus\Exception\EmptyDirectoryException
22
	 */
23 5
	public function __construct($path)
24
	{
25 5
		$this->config = new Config($path);
26 5
		$this->extractMapping($this->get('level.mapping', []));
27 5
	}
28
29
	/**
30
	 * @param string|array $file
31
	 * @return \PHPSemVerChecker\Configuration\Configuration
32
	 * @throws \Noodlehaus\Exception\EmptyDirectoryException
33
	 */
34
	public static function fromFile($file)
35
	{
36
		return new Configuration($file);
37
	}
38
39
	/**
40
	 * @param string $name
41
	 * @return \PHPSemVerChecker\Configuration\Configuration
42
	 * @throws \Noodlehaus\Exception\EmptyDirectoryException
43
	 */
44
	public static function defaults($name)
45
	{
46
		return self::fromFile(['?' . $name . '.yml.dist', '?' . $name . '.yml']);
47
	}
48
49
	/**
50
	 * @param array $mapping
51
	 */
52 5
	protected function extractMapping(array $mapping)
53
	{
54 5
		foreach ($mapping as &$level) {
55 4
			$level = Level::fromString($level);
56
		}
57 5
		$this->mapping = $mapping;
58 5
	}
59
60
	/**
61
	 * @return array
62
	 */
63 1
	public function getLevelMapping()
64
	{
65 1
		return $this->mapping;
66
	}
67
68
	/**
69
	 * @see \Noodlehaus\Config::get
70
	 * @param string     $key
71
	 * @param mixed|null $default
72
	 * @return array|mixed|null
73
	 */
74 5
	public function get($key, $default = null)
75
	{
76 5
		return $this->config->get($key, $default);
77
	}
78
79
	/**
80
	 * @see \Noodlehaus\Config::set
81
	 * @param string $key
82
	 * @param mixed  $value
83
	 */
84 2
	public function set($key, $value)
85
	{
86 2
		$this->config->set($key, $value);
87 2
	}
88
89
	/**
90
	 * Merge this configuration with an associative array.
91
	 *
92
	 * Note that dot notation is used for keys.
93
	 *
94
	 * @param array $data
95
	 */
96
	public function merge($data)
97
	{
98
		foreach ($data as $key => $value) {
99
			$this->set($key, $value);
100
		}
101
	}
102
}
103