Completed
Push — master ( 10f95b...bf15d4 )
by Michael
09:02
created

ConfigServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A register() 0 4 1
1
<?php
2
/**
3
 * Joomla! Statistics Server
4
 *
5
 * @copyright  Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved.
6
 * @license    http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
7
 */
8
9
namespace Joomla\StatsServer\Providers;
10
11
use Joomla\DI\{
12
	Container, ServiceProviderInterface
13
};
14
use Joomla\Registry\Registry;
15
16
/**
17
 * Configuration service provider
18
 *
19
 * @since  1.0
20
 */
21
class ConfigServiceProvider implements ServiceProviderInterface
22
{
23
	/**
24
	 * Configuration instance
25
	 *
26
	 * @var    Registry
27
	 * @since  1.0
28
	 */
29
	private $config;
30
31
	/**
32
	 * Constructor.
33
	 *
34
	 * @param   string  $file  Path to the config file.
35
	 *
36
	 * @since   1.0
37
	 * @throws  \RuntimeException
38
	 */
39 2
	public function __construct(string $file)
40
	{
41
		// Verify the configuration exists and is readable.
42 2
		if (!is_readable($file))
43
		{
44 1
			throw new \RuntimeException('Configuration file does not exist or is unreadable.');
45
		}
46
47 1
		$this->config = (new Registry)->loadFile($file);
48 1
	}
49
50
	/**
51
	 * Registers the service provider with a DI container.
52
	 *
53
	 * @param   Container  $container  The DI container.
54
	 *
55
	 * @return  void
56
	 *
57
	 * @since   1.0
58
	 */
59 1
	public function register(Container $container)
60
	{
61 1
		$container->share('config', [$this, 'getConfigService'], true);
62 1
	}
63
64
	/**
65
	 * Get the `config` service
66
	 *
67
	 * @param   Container  $container  The DI container.
68
	 *
69
	 * @return  Registry
70
	 *
71
	 * @since   1.0
72
	 */
73 1
	public function getConfigService(Container $container) : Registry
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
	{
75 1
		return $this->config;
76
	}
77
}
78