Completed
Push — master ( a04d7d...af82d7 )
by Alexander
03:22
created

RevisionLogFactory::getRevisionLog()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 51
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 3.0134

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 51
ccs 31
cts 35
cp 0.8857
rs 9.4109
cc 3
eloc 31
nc 4
nop 2
crap 3.0134

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
	 */
57 2
	public function __construct(
58
		Connector $repository_connector,
59
		DatabaseManager $database_manager,
60
		LogMessageParserFactory $log_message_parser_factory
61
	) {
62 2
		$this->_repositoryConnector = $repository_connector;
63 2
		$this->_databaseManager = $database_manager;
64 2
		$this->_logMessageParserFactory = $log_message_parser_factory;
65 2
	}
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
	 */
75 1
	public function getRevisionLog($repository_url, ConsoleIO $io = null)
76
	{
77
		// Gets database for given repository url.
78 1
		$root_url = $this->_repositoryConnector->getRootUrl($repository_url);
79 1
		$database = $this->_databaseManager->getDatabase($root_url, $io);
80
81
		// Create dependencies.
82 1
		$database_cache = new DatabaseCache($database);
83 1
		$repository_filler = new RepositoryFiller($database, $database_cache);
84
85
		// Create blank revision log.
86 1
		$revision_log = new RevisionLog($repository_url, $this->_repositoryConnector, $io);
87
88
		// 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 1
		$revision_log->registerPlugin(new RefsPlugin($database, $repository_filler));
107
108
		// Run migrations (includes initial schema creation).
109 1
		$context = new MigrationContext($database, clone $revision_log);
110 1
		$this->_databaseManager->runMigrations($context);
111
112 1
		$profiler = $database->getProfiler();
113
114 1
		if ( $profiler instanceof StatementProfiler ) {
115
			$profiler->trackDuplicates(true);
116
		}
117
118 1
		$revision_log->refresh(false);
119
120 1
		if ( $profiler instanceof StatementProfiler ) {
121
			$profiler->trackDuplicates(false);
122
		}
123
124 1
		return $revision_log;
125
	}
126
127
}
128