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

KnowledgeBaseFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getKnowledgeBase() 0 14 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 ConsoleHelpers\ConsoleKit\ConsoleIO;
15
use ConsoleHelpers\DatabaseMigration\MigrationContext;
16
17
class KnowledgeBaseFactory
18
{
19
20
	/**
21
	 * Database manager.
22
	 *
23
	 * @var DatabaseManager
24
	 */
25
	private $_databaseManager;
26
27
	/**
28
	 * Create knowledge base factory instance.
29
	 *
30
	 * @param DatabaseManager $database_manager Database manager.
31
	 */
32
	public function __construct(DatabaseManager $database_manager)
33
	{
34
		$this->_databaseManager = $database_manager;
35
	}
36
37
	/**
38
	 * Returns knowledge base for project path.
39
	 *
40
	 * @param string    $project_path Project path.
41
	 * @param ConsoleIO $io           Console IO.
42
	 *
43
	 * @return KnowledgeBase
44
	 */
45
	public function getKnowledgeBase($project_path, ConsoleIO $io = null)
46
	{
47
		// Gets database for given project path.
48
		$database = $this->_databaseManager->getDatabase($project_path);
49
50
		// Create blank revision log.
51
		$knowledge_base = new KnowledgeBase($project_path, $database, $io);
52
53
		// Run migrations (includes initial schema creation).
54
		$context = new MigrationContext($database);
55
		$this->_databaseManager->runMigrations($context);
56
57
		return $knowledge_base;
58
	}
59
60
}
61