Completed
Push — master ( 2f3970...67291b )
by Alexander
03:41
created

GroupByRevisionMergeTemplate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 51
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
B generateGroupBody() 0 26 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\CommitMessage;
12
13
14
class GroupByRevisionMergeTemplate extends AbstractGroupByMergeTemplate
15
{
16
17
	/**
18
	 * Returns merge template name.
19
	 *
20
	 * @return string
21
	 */
22 2
	public function getName()
23
	{
24 2
		return 'group_by_revision';
25
	}
26
27
	/**
28
	 * Builds group body.
29
	 *
30
	 * @param string $path           Path.
31
	 * @param array  $revisions      Revisions.
32
	 * @param string $repository_url Repository URL.
33
	 * @param string $relative_path  Relative path.
34
	 *
35
	 * @return string
36
	 */
37 1
	protected function generateGroupBody($path, array $revisions, $repository_url, $relative_path)
38
	{
39 1
		$merged_messages = array();
40 1
		$revision_log = $this->revisionLogFactory->getRevisionLog($repository_url . $path);
41 1
		$revisions_data = $revision_log->getRevisionsData('summary', $revisions);
42
43 1
		foreach ( $revisions as $revision ) {
44 1
			$merged_messages[] = ' * r' . $revision . ': ' . $revisions_data[$revision]['msg'];
45
		}
46
47 1
		$merged_messages = array_unique(array_map('trim', $merged_messages));
48
49 1
		if ( count($revisions) > 1 ) {
50 1
			$ret = '';
51 1
			$ret .= $this->generateGroupHeading($path, $relative_path) . PHP_EOL;
52 1
			$ret .= implode(PHP_EOL, $merged_messages);
53
54 1
			return $ret;
55
		}
56
57 1
		$ret = '';
58 1
		$ret .= '[' . $this->generateGroupHeading($path, $relative_path, false) . '] ';
59 1
		$ret .= implode(PHP_EOL, $merged_messages);
60
61 1
		return $ret;
62
	}
63
64
}
65