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

DatabaseServiceProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 57.14%

Importance

Changes 10
Bugs 1 Features 3
Metric Value
wmc 1
c 10
b 1
f 3
lcom 0
cbo 6
dl 0
loc 42
ccs 12
cts 21
cp 0.5714
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 1
A getDbService() 0 11 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\Database\DatabaseDriver;
12
use Joomla\DI\{
13
	Container, ServiceProviderInterface
14
};
15
use Joomla\StatsServer\Database\Mysql\MysqlDriver;
16
use League\Flysystem\Adapter\Local;
17
use League\Flysystem\Filesystem;
18
use Joomla\StatsServer\Database\Migrations;
19
20
/**
21
 * Database service provider
22
 */
23
class DatabaseServiceProvider implements ServiceProviderInterface
24
{
25
	/**
26
	 * Registers the service provider with a DI container.
27
	 *
28
	 * @param   Container  $container  The DI container.
29
	 *
30
	 * @return  void
31
	 */
32 1
	public function register(Container $container)
33
	{
34 1
		$container->alias('db', DatabaseDriver::class)
35 1
			->share(DatabaseDriver::class, [$this, 'getDbService'], true);
36
37 1
		$container->alias('db.migrations', Migrations::class)
38 1
			->share(Migrations::class, [$this, 'getDbMigrationsService'], true);
39 1
	}
40
41
	/**
42
	 * Get the `db` service
43
	 *
44
	 * @param   Container  $container  The DI container.
45
	 *
46
	 * @return  DatabaseDriver
47
	 */
48 1
	public function getDbService(Container $container) : DatabaseDriver
49
	{
50
		/** @var \Joomla\Registry\Registry $config */
51 1
		$config = $container->get('config');
52
53 1
		$db = new MysqlDriver(array_merge((array) $config->get('database'), ['select' => true]));
54 1
		$db->setDebug($config->get('database.debug'));
55 1
		$db->setLogger($container->get('monolog.logger.database'));
56
57 1
		return $db;
58
	}
59
60
	/**
61
	 * Get the `db.migrations` service
62
	 *
63
	 * @param   Container  $container  The DI container.
64
	 *
65
	 * @return  Migrations
66
	 */
67 1
	public function getDbMigrationsService(Container $container) : Migrations
68
	{
69 1
		return new Migrations(
70 1
			$container->get('db'),
71 1
			new Filesystem(new Local(APPROOT . '/etc'))
72
		);
73
	}
74
}
75