Completed
Push — master ( 51a51b...3888f6 )
by Michael
06:55
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
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Stats\Providers;
4
5
use Joomla\DI\Container;
6
use Joomla\DI\ServiceProviderInterface;
7
use Joomla\Registry\Registry;
8
9
/**
10
 * Configuration service provider
11
 *
12
 * @since  1.0
13
 */
14
class ConfigServiceProvider implements ServiceProviderInterface
15
{
16
	/**
17
	 * Configuration instance
18
	 *
19
	 * @var    Registry
20
	 * @since  1.0
21
	 */
22
	private $config;
23
24
	/**
25
	 * Constructor.
26
	 *
27
	 * @param   string  $file  Path to the config file.
28
	 *
29
	 * @since   1.0
30
	 * @throws  \RuntimeException
31
	 */
32 2
	public function __construct($file)
33
	{
34
		// Verify the configuration exists and is readable.
35 2
		if (!is_readable($file))
36 2
		{
37 1
			throw new \RuntimeException('Configuration file does not exist or is unreadable.');
38
		}
39
40 1
		$this->config = (new Registry)->loadFile($file);
41 1
	}
42
43
	/**
44
	 * Registers the service provider with a DI container.
45
	 *
46
	 * @param   Container  $container  The DI container.
47
	 *
48
	 * @return  void
49
	 *
50
	 * @since   1.0
51
	 */
52 1
	public function register(Container $container)
53
	{
54 1
		$container->share('config', [$this, 'getConfigService'], true);
55 1
	}
56
57
	/**
58
	 * Get the `config` service
59
	 *
60
	 * @param   Container  $container  The DI container.
61
	 *
62
	 * @return  Registry
63
	 *
64
	 * @since   1.0
65
	 */
66 1
	public function getConfigService(Container $container)
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...
67
	{
68 1
		return $this->config;
69
	}
70
}
71