Failed Conditions
Push — master ( e58a5b...a04d7d )
by Alexander
03:00
created

RevisionLogFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 15

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 4
c 5
b 0
f 1
lcom 1
cbo 15
dl 0
loc 102
ccs 33
cts 33
cp 1
rs 9.1666

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getRevisionLog() 0 51 3
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy 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/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy\Repository\RevisionLog;
12
13
14
use ConsoleHelpers\ConsoleKit\ConsoleIO;
15
use ConsoleHelpers\SVNBuddy\Database\DatabaseCache;
16
use ConsoleHelpers\SVNBuddy\Database\StatementProfiler;
17
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector;
18
use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory;
19
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\BugsPlugin;
20
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\MergesPlugin;
21
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\PathsPlugin;
22
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\ProjectsPlugin;
23
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RefsPlugin;
24
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\SummaryPlugin;
25
26
class RevisionLogFactory
27
{
28
29
	/**
30
	 * Repository connector.
31
	 *
32
	 * @var Connector
33
	 */
34
	private $_repositoryConnector;
35
36
	/**
37
	 * Database manager.
38
	 *
39
	 * @var DatabaseManager
40
	 */
41
	private $_databaseManager;
42
43
	/**
44
	 * Log message parser factory
45
	 *
46
	 * @var LogMessageParserFactory
47
	 */
48
	private $_logMessageParserFactory;
49
50
	/**
51
	 * Create revision log.
52
	 *
53
	 * @param Connector               $repository_connector       Repository connector.
54
	 * @param DatabaseManager         $database_manager           Database manager.
55
	 * @param LogMessageParserFactory $log_message_parser_factory Log message parser factory.
56 2
	 */
57
	public function __construct(
58
		Connector $repository_connector,
59
		DatabaseManager $database_manager,
60
		LogMessageParserFactory $log_message_parser_factory
61 2
	) {
62 2
		$this->_repositoryConnector = $repository_connector;
63 2
		$this->_databaseManager = $database_manager;
64 2
		$this->_logMessageParserFactory = $log_message_parser_factory;
65
	}
66
67
	/**
68
	 * Returns revision log for url.
69
	 *
70
	 * @param string    $repository_url Repository url.
71
	 * @param ConsoleIO $io             Console IO.
72
	 *
73
	 * @return RevisionLog
74 1
	 */
75
	public function getRevisionLog($repository_url, ConsoleIO $io = null)
76
	{
77 1
		// Gets database for given repository url.
78 1
		$root_url = $this->_repositoryConnector->getRootUrl($repository_url);
79
		$database = $this->_databaseManager->getDatabase($root_url, $io);
80
81 1
		// Create dependencies.
82 1
		$database_cache = new DatabaseCache($database);
83
		$repository_filler = new RepositoryFiller($database, $database_cache);
84
85 1
		// Create blank revision log.
86
		$revision_log = new RevisionLog($repository_url, $this->_repositoryConnector, $io);
87
88 1
		// Add plugins to revision log.
89 1
		$revision_log->registerPlugin(new SummaryPlugin($database, $repository_filler));
90 1
		$revision_log->registerPlugin(new PathsPlugin(
91 1
			$database,
92 1
			$repository_filler,
93 1
			$database_cache,
94 1
			$this->_repositoryConnector,
95 1
			new PathCollisionDetector()
96 1
		));
97 1
		$revision_log->registerPlugin(new ProjectsPlugin($database, $repository_filler));
98 1
		$revision_log->registerPlugin(new BugsPlugin(
99 1
			$database,
100 1
			$repository_filler,
101 1
			$root_url,
102 1
			$this->_repositoryConnector,
103 1
			$this->_logMessageParserFactory
104 1
		));
105 1
		$revision_log->registerPlugin(new MergesPlugin($database, $repository_filler));
106
		$revision_log->registerPlugin(new RefsPlugin($database, $repository_filler));
107
108 1
		// Run migrations (includes initial schema creation).
109 1
		$context = new MigrationContext($database, clone $revision_log);
110
		$this->_databaseManager->runMigrations($context);
111 1
112
		$profiler = $database->getProfiler();
113 1
114
		if ( $profiler instanceof StatementProfiler ) {
115
			$profiler->trackDuplicates(true);
116
		}
117
118
		$revision_log->refresh(false);
119
120
		if ( $profiler instanceof StatementProfiler ) {
121
			$profiler->trackDuplicates(false);
122
		}
123
124
		return $revision_log;
125
	}
126
127
}
128