Failed Conditions
Push — master ( 7fcd15...bf9f4d )
by Alexander
02:44
created

SummaryMergeTemplate::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 SummaryMergeTemplate extends AbstractMergeTemplate
15
{
16
17
	/**
18
	 * Returns merge template name.
19
	 *
20
	 * @return string
21
	 */
22 2
	public function getName()
23
	{
24 2
		return 'summary';
25
	}
26
27
	/**
28
	 * Applies merge template to a working copy.
29
	 *
30
	 * @param string $wc_path Working copy path.
31
	 *
32
	 * @return string
33
	 */
34 2
	public function apply($wc_path)
35
	{
36 2
		$merged_revisions = $this->repositoryConnector->getFreshMergedRevisions($wc_path);
37
38 2
		if ( !$merged_revisions ) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $merged_revisions of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
39 1
			return '';
40
		}
41
42 1
		$target = $this->getMomentInTime(
43 1
			$this->repositoryConnector->getRelativePath($wc_path),
44 1
			$this->repositoryConnector->getLastRevision($wc_path)
45 1
		);
46
47 1
		$ret = '';
48
49 1
		foreach ( $merged_revisions as $path => $revisions ) {
50 1
			$source = $this->getMomentInTime($path, max($revisions));
51 1
			$ret .= PHP_EOL . 'Merge of "' . $source . '" to "' . $target . '".' . PHP_EOL;
52 1
		}
53
54 1
		return trim($ret);
55
	}
56
57
	/**
58
	 * Returns moment in time.
59
	 *
60
	 * @param string  $path     Path.
61
	 * @param integer $revision Revision.
62
	 *
63
	 * @return string
64
	 */
65 1
	protected function getMomentInTime($path, $revision)
66
	{
67 1
		return ltrim($path, '/') . '@' . $revision;
68
	}
69
70
}
71