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
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
15
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLogFactory; |
16
|
|
|
|
17
|
|
|
abstract class AbstractMergeTemplate |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Repository connector. |
22
|
|
|
* |
23
|
|
|
* @var Connector |
24
|
|
|
*/ |
25
|
|
|
protected $repositoryConnector; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Revision log factory. |
29
|
|
|
* |
30
|
|
|
* @var RevisionLogFactory |
31
|
|
|
*/ |
32
|
|
|
protected $revisionLogFactory; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Creates commit message builder instance. |
36
|
|
|
* |
37
|
|
|
* @param Connector $repository_connector Repository connector. |
38
|
|
|
* @param RevisionLogFactory $revision_log_factory Revision log factory. |
39
|
|
|
*/ |
40
|
21 |
|
public function __construct( |
41
|
|
|
Connector $repository_connector, |
42
|
|
|
RevisionLogFactory $revision_log_factory |
43
|
|
|
) { |
44
|
21 |
|
$this->repositoryConnector = $repository_connector; |
45
|
21 |
|
$this->revisionLogFactory = $revision_log_factory; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Returns merge template name. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
abstract public function getName(); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Applies merge template to a working copy. |
57
|
|
|
* |
58
|
|
|
* @param string $wc_path Working copy path. |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
abstract public function apply($wc_path); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Flattens groups in revisions. |
66
|
|
|
* |
67
|
|
|
* @param array $grouped_revisions Grouped revisions. |
68
|
|
|
* |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
12 |
|
protected function flattenMergedRevisions(array $grouped_revisions) |
72
|
|
|
{ |
73
|
|
|
// Not a merge commit. |
74
|
12 |
|
if ( !$grouped_revisions ) { |
|
|
|
|
75
|
3 |
|
return array(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// Multi-source merge commit. |
79
|
9 |
|
if ( count($grouped_revisions) > 1 ) { |
80
|
6 |
|
return \call_user_func_array('array_merge', \array_values($grouped_revisions)); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// Single source merge commit. |
84
|
9 |
|
return \array_values(reset($grouped_revisions)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
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.