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

ConfigServiceProvider::getConfigService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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