Completed
Push — master ( b3f9bf...16b026 )
by Sam
03:02
created

YamlReader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 41
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A readConfiguration() 0 16 3
1
<?php
2
3
namespace Jalle19\StatusManager\Configuration\Reader;
4
5
use Jalle19\StatusManager\Exception\InvalidConfigurationException;
6
use Symfony\Component\Yaml\Exception\ParseException;
7
use Symfony\Component\Yaml\Yaml;
8
9
/**
10
 * Class YamlReader
11
 * @package   Jalle19\StatusManager\Configuration\Reader
12
 * @copyright Copyright &copy; Sam Stenvall 2016-
13
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
14
 */
15
class YamlReader implements ReaderInterface
16
{
17
18
	/**
19
	 * @var string
20
	 */
21
	private $_file;
22
23
24
	/**
25
	 * YamlReader constructor.
26
	 *
27
	 * @param string $file
28
	 */
29 3
	public function __construct($file)
30
	{
31 3
		$this->_file = $file;
32 3
	}
33
34
35
	/**
36
	 * @inheritdoc
37
	 */
38 3
	public function readConfiguration()
39
	{
40
		// Check that the configuration file is readable
41 3
		if (!is_readable($this->_file))
42 3
			throw new InvalidConfigurationException('The configuration file does not exist or is not readable');
43
44
		// Parse the configuration file
45
		try
46
		{
47 2
			return (array)Yaml::parse(file_get_contents($this->_file));
48
		}
49 1
		catch (ParseException $e)
50
		{
51 1
			throw new InvalidConfigurationException('Failed to parse the specified configuration file: ' . $e->getMessage());
52
		}
53
	}
54
55
}
56