Failed Conditions
Push — master ( 17cdc3...604e06 )
by Alexander
05:14
created

DatabaseManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 45
ccs 0
cts 12
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDatabase() 0 4 1
A runMigrations() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Code-Insight library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/code-insight
9
 */
10
11
namespace ConsoleHelpers\CodeInsight\KnowledgeBase;
12
13
14
use Aura\Sql\ExtendedPdo;
15
use Aura\Sql\ExtendedPdoInterface;
16
use ConsoleHelpers\DatabaseMigration\MigrationManager;
17
use ConsoleHelpers\DatabaseMigration\MigrationContext;
18
19
class DatabaseManager
20
{
21
22
	/**
23
	 * Migration manager.
24
	 *
25
	 * @var MigrationManager
26
	 */
27
	private $_migrationManager;
28
29
	/**
30
	 * Database manager constructor.
31
	 *
32
	 * @param MigrationManager $migration_manager Migration manager.
33
	 */
34
	public function __construct(MigrationManager $migration_manager)
35
	{
36
		$this->_migrationManager = $migration_manager;
37
	}
38
39
	/**
40
	 * Returns db for given repository.
41
	 *
42
	 * @param string $project_path Project path.
43
	 *
44
	 * @return ExtendedPdoInterface
45
	 */
46
	public function getDatabase($project_path)
47
	{
48
		return new ExtendedPdo('sqlite:' . $project_path . '/code_insight.sqlite');
49
	}
50
51
	/**
52
	 * Runs outstanding migrations on the database.
53
	 *
54
	 * @param MigrationContext $context Context.
55
	 *
56
	 * @return void
57
	 */
58
	public function runMigrations(MigrationContext $context)
59
	{
60
		$this->_migrationManager->run($context);
61
	}
62
63
}
64