Completed
Push — mysql_improvements ( 2e95ce...dedbef )
by Michael
03:52
created

ConfigServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 3
c 5
b 0
f 0
lcom 1
cbo 2
dl 0
loc 50
ccs 13
cts 14
cp 0.9286
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
class ConfigServiceProvider implements ServiceProviderInterface
20
{
21
	/**
22
	 * Configuration instance
23
	 *
24
	 * @var  Registry
25
	 */
26
	private $config;
27
28
	/**
29
	 * Constructor.
30
	 *
31
	 * @param   string  $file  Path to the config file.
32
	 *
33
	 * @throws  \RuntimeException
34
	 */
35 2
	public function __construct(string $file)
36
	{
37
		// Verify the configuration exists and is readable.
38 2
		if (!is_readable($file))
39
		{
40 1
			throw new \RuntimeException('Configuration file does not exist or is unreadable.');
41
		}
42
43 1
		$this->config = (new Registry)->loadFile($file);
44 1
	}
45
46
	/**
47
	 * Registers the service provider with a DI container.
48
	 *
49
	 * @param   Container  $container  The DI container.
50
	 *
51
	 * @return  void
52
	 */
53 1
	public function register(Container $container)
54
	{
55 1
		$container->share('config', [$this, 'getConfigService'], true);
56 1
	}
57
58
	/**
59
	 * Get the `config` service
60
	 *
61
	 * @param   Container  $container  The DI container.
62
	 *
63
	 * @return  Registry
64
	 */
65 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...
66
	{
67 1
		return $this->config;
68
	}
69
}
70