1 | <?php |
||
26 | final class Hunk |
||
27 | { |
||
28 | |||
29 | const ADDED = 1; |
||
30 | const REMOVED = 2; |
||
31 | const REPLACED = 3; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $start; |
||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $end; |
||
41 | /** |
||
42 | * @var Line[] |
||
43 | */ |
||
44 | protected $lines; |
||
45 | /** |
||
46 | * @var int |
||
47 | */ |
||
48 | protected $type; |
||
49 | |||
50 | /** |
||
51 | * The Hunk constructor. |
||
52 | * |
||
53 | * @param Line|Line[] $lines |
||
54 | * The lines belonging to the hunk. |
||
55 | * @param int $type |
||
56 | * The type of the hunk: Hunk::ADDED Hunk::REMOVED Hunk::REPLACED |
||
57 | * @param int $start |
||
58 | * The line index where the hunk starts. |
||
59 | * @param int $end |
||
60 | * The line index where the hunk stops. |
||
61 | */ |
||
62 | 52 | public function __construct($lines, $type, $start, $end = null) |
|
75 | |||
76 | /** |
||
77 | * Add a new line to the hunk. |
||
78 | * |
||
79 | * @param \PhpMerge\Line $line |
||
80 | * The line to add. |
||
81 | */ |
||
82 | 36 | public function addLine(Line $line) |
|
87 | |||
88 | /** |
||
89 | * Create an array of hunks out of an array of lines. |
||
90 | * |
||
91 | * @param Line[] $lines |
||
92 | * The lines of the diff. |
||
93 | * @return Hunk[] |
||
94 | * The hunks in the lines. |
||
95 | */ |
||
96 | 52 | public static function createArray($lines) |
|
146 | |||
147 | /** |
||
148 | * Set the type of the hunk. |
||
149 | * |
||
150 | * @param int $type |
||
151 | */ |
||
152 | 36 | protected function setType($type) |
|
156 | |||
157 | /** |
||
158 | * Get the line index where the hunk starts. |
||
159 | * |
||
160 | * @return int |
||
161 | */ |
||
162 | 48 | public function getStart() |
|
166 | |||
167 | /** |
||
168 | * Get the line index where the hunk ends. |
||
169 | * |
||
170 | * @return int |
||
171 | */ |
||
172 | 28 | public function getEnd() |
|
176 | |||
177 | /** |
||
178 | * Get the type of the hunk. |
||
179 | * |
||
180 | * @return int |
||
181 | */ |
||
182 | 40 | public function getType() |
|
186 | |||
187 | /** |
||
188 | * Get the lines of the hunk. |
||
189 | * |
||
190 | * @return Line[] |
||
191 | */ |
||
192 | 4 | public function getLines() |
|
196 | |||
197 | /** |
||
198 | * Get the removed lines. |
||
199 | * |
||
200 | * @return Line[] |
||
201 | */ |
||
202 | 12 | public function getRemovedLines() |
|
211 | |||
212 | /** |
||
213 | * Get the added lines. |
||
214 | * |
||
215 | * @return Line[] |
||
216 | */ |
||
217 | 40 | public function getAddedLines() |
|
226 | |||
227 | /** |
||
228 | * Get the lines content. |
||
229 | * |
||
230 | * @return string[] |
||
231 | */ |
||
232 | 24 | public function getLinesContent() |
|
241 | |||
242 | /** |
||
243 | * Test whether the hunk is to be considered for a conflict resolution. |
||
244 | * |
||
245 | * @param int $line |
||
246 | * The line number in the original text to test. |
||
247 | * |
||
248 | * @return bool |
||
249 | * Whether the line is affected by the hunk. |
||
250 | */ |
||
251 | 28 | public function isLineNumberAffected($line) |
|
258 | |||
259 | /** |
||
260 | * @param \PhpMerge\Hunk|null $hunk |
||
261 | * @return bool |
||
262 | */ |
||
263 | 36 | public function hasIntersection(Hunk $hunk = null) |
|
274 | } |
||
275 |