Repository navigation
Expand file tree
/
Copy pathHunk.php
More file actions
69 lines (60 loc) · 1.66 KB
/
Copy pathHunk.php
File metadata and controls
69 lines (60 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace Pharaonic\Diff;
/**
* A run of changed lines with the unchanged lines around them, as in a unified diff
*
* When a side has no lines in the hunk, its start is the number of the line the hunk comes
* after, or 0 at the start of the text, as Git and GNU diff write it.
*/
final class Hunk
{
/**
* @param list<DiffLine> $lines
*
* @internal Hunks are created by Diff::text().
*/
public function __construct(
private int $oldStart,
private int $oldLength,
private int $newStart,
private int $newLength,
private array $lines,
) {}
public function oldStart(): int
{
return $this->oldStart;
}
public function oldLength(): int
{
return $this->oldLength;
}
public function newStart(): int
{
return $this->newStart;
}
public function newLength(): int
{
return $this->newLength;
}
/**
* @return list<DiffLine>
*/
public function lines(): array
{
return $this->lines;
}
/**
* @return array{old_start: int, old_length: int, new_start: int, new_length: int, lines: list<array{type: string, content: string, old_line: int|null, new_line: int|null, inline: list<array{type: string, text: string}>}>}
*/
public function toArray(): array
{
return [
'old_start' => $this->oldStart,
'old_length' => $this->oldLength,
'new_start' => $this->newStart,
'new_length' => $this->newLength,
'lines' => array_map(static fn(DiffLine $line): array => $line->toArray(), $this->lines),
];
}
}