Completed
Push — master ( 51a51b...3888f6 )
by Michael
06:55
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 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 57
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A register() 0 4 1
A getConfigService() 0 4 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