1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the php-merge package. |
4
|
|
|
* |
5
|
|
|
* (c) Fabian Bircher <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PhpMerge; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class MergeConflict |
15
|
|
|
* |
16
|
|
|
* This represents a merge conflict it includes the lines of the original and |
17
|
|
|
* both variations as well as the index on the original text where the conflict |
18
|
|
|
* starts. |
19
|
|
|
* |
20
|
|
|
* @package PhpMerge |
21
|
|
|
* @author Fabian Bircher <[email protected]> |
22
|
|
|
* @copyright Fabian Bircher <[email protected]> |
23
|
|
|
* @license https://opensource.org/licenses/MIT |
24
|
|
|
* @version Release: @package_version@ |
25
|
|
|
* @link http://github.com/bircher/php-merge |
26
|
|
|
*/ |
27
|
|
|
final class MergeConflict |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The lines from the original. |
32
|
|
|
* |
33
|
|
|
* @var string[] |
34
|
|
|
*/ |
35
|
|
|
protected $base; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The conflicting line changes from the first source. |
39
|
|
|
* |
40
|
|
|
* @var string[] |
41
|
|
|
*/ |
42
|
|
|
protected $remote; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The conflicting line changes from the second source. |
46
|
|
|
* |
47
|
|
|
* @var string[] |
48
|
|
|
*/ |
49
|
|
|
protected $local; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The line number in the original text. |
53
|
|
|
* |
54
|
|
|
* @var int |
55
|
|
|
*/ |
56
|
|
|
protected $baseLine; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The line number in the merged text. |
60
|
|
|
* |
61
|
|
|
* @var int |
62
|
|
|
*/ |
63
|
|
|
protected $mergedLine; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* MergeConflict constructor. |
67
|
|
|
* |
68
|
|
|
* @param string[] $base |
69
|
|
|
* The original lines where the conflict happened. |
70
|
|
|
* @param string[] $remote |
71
|
|
|
* The conflicting line changes from the first source. |
72
|
|
|
* @param string[] $local |
73
|
|
|
* The conflicting line changes from the second source. |
74
|
|
|
* @param int $baseLine |
75
|
|
|
* The line number in the original text. |
76
|
|
|
* @param int $mergedLine |
77
|
|
|
* The line number in the merged text. |
78
|
|
|
*/ |
79
|
10 |
|
public function __construct($base, $remote, $local, $baseLine, $mergedLine) |
80
|
|
|
{ |
81
|
|
|
// Compatibility for 2.x branch and sebastian/diff 2.x and 3.x. |
82
|
10 |
|
$this->base = static::fixEOL($base); |
|
|
|
|
83
|
10 |
|
$this->remote = static::fixEOL($remote); |
|
|
|
|
84
|
10 |
|
$this->local = static::fixEOL($local); |
|
|
|
|
85
|
10 |
|
$this->baseLine = $baseLine; |
86
|
10 |
|
$this->mergedLine = $mergedLine; |
87
|
10 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the base text of the conflict. |
91
|
|
|
* |
92
|
|
|
* @return string[] |
93
|
|
|
* The array of lines which are involved in the conflict. |
94
|
|
|
*/ |
95
|
6 |
|
public function getBase() |
96
|
|
|
{ |
97
|
6 |
|
return $this->base; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the lines from the first text. |
102
|
|
|
* |
103
|
|
|
* @return string[] |
104
|
|
|
* The array of lines from the first text involved in the conflict. |
105
|
|
|
*/ |
106
|
2 |
|
public function getRemote() |
107
|
|
|
{ |
108
|
2 |
|
return $this->remote; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get the lines from the second text. |
113
|
|
|
* |
114
|
|
|
* @return string[] |
115
|
|
|
* The array of lines from the first text involved in the conflict. |
116
|
|
|
*/ |
117
|
2 |
|
public function getLocal() |
118
|
|
|
{ |
119
|
2 |
|
return $this->local; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get the line number in the original text where the conflict starts. |
124
|
|
|
* |
125
|
|
|
* @return int |
126
|
|
|
* The line number as in the original text. |
127
|
|
|
*/ |
128
|
6 |
|
public function getBaseLine() |
129
|
|
|
{ |
130
|
6 |
|
return $this->baseLine; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get the line number in the merged text where the conflict starts. |
135
|
|
|
* |
136
|
|
|
* @return int |
137
|
|
|
* The line number in the merged text. |
138
|
|
|
*/ |
139
|
2 |
|
public function getMergedLine() |
140
|
|
|
{ |
141
|
2 |
|
return $this->mergedLine; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Remove the trailing EOL that are now added by sebastian/diff. |
146
|
|
|
* |
147
|
|
|
* @param string[] $lines |
148
|
|
|
* The lines to fix. |
149
|
|
|
* |
150
|
|
|
* @return string[] |
151
|
|
|
* The fixed lines. |
152
|
|
|
*/ |
153
|
10 |
|
private static function fixEOL(array $lines) |
154
|
|
|
{ |
155
|
|
|
$ltrim = function ($line) { |
156
|
10 |
|
return rtrim($line, "\n"); |
157
|
10 |
|
}; |
158
|
10 |
|
return array_map($ltrim, $lines); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
Late static binding only has effect in subclasses. A
final
class cannot be extended anymore so late static binding cannot occurr. Consider replacingstatic::
withself::
.To learn more about late static binding, please refer to the PHP core documentation.