Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
UnifiedDiffFormatter | |
0.00% |
0 / 7 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
lines | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
added | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
deleted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
changed | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
blockHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Portions taken from phpwiki-1.3.3. |
4 | * |
5 | * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org> |
6 | * You may copy this code freely under the conditions of the GPL. |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; if not, write to the Free Software Foundation, Inc., |
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
21 | * http://www.gnu.org/copyleft/gpl.html |
22 | * |
23 | * @file |
24 | * @ingroup DifferenceEngine |
25 | */ |
26 | |
27 | namespace Wikimedia\Diff; |
28 | |
29 | /** |
30 | * A formatter that outputs unified diffs |
31 | * @newable |
32 | * @ingroup DifferenceEngine |
33 | */ |
34 | class UnifiedDiffFormatter extends DiffFormatter { |
35 | |
36 | /** @var int */ |
37 | protected $leadingContextLines = 2; |
38 | |
39 | /** @var int */ |
40 | protected $trailingContextLines = 2; |
41 | |
42 | /** |
43 | * @param string[] $lines |
44 | * @param string $prefix |
45 | */ |
46 | protected function lines( $lines, $prefix = ' ' ) { |
47 | foreach ( $lines as $line ) { |
48 | $this->writeOutput( "{$prefix}{$line}\n" ); |
49 | } |
50 | } |
51 | |
52 | /** |
53 | * @param string[] $lines |
54 | */ |
55 | protected function added( $lines ) { |
56 | $this->lines( $lines, '+' ); |
57 | } |
58 | |
59 | /** |
60 | * @param string[] $lines |
61 | */ |
62 | protected function deleted( $lines ) { |
63 | $this->lines( $lines, '-' ); |
64 | } |
65 | |
66 | /** |
67 | * @param string[] $orig |
68 | * @param string[] $closing |
69 | */ |
70 | protected function changed( $orig, $closing ) { |
71 | $this->deleted( $orig ); |
72 | $this->added( $closing ); |
73 | } |
74 | |
75 | /** |
76 | * @param int $xbeg |
77 | * @param int $xlen |
78 | * @param int $ybeg |
79 | * @param int $ylen |
80 | * |
81 | * @return string |
82 | */ |
83 | protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) { |
84 | return "@@ -$xbeg,$xlen +$ybeg,$ylen @@"; |
85 | } |
86 | |
87 | } |
88 | |
89 | /** @deprecated class alias since 1.41 */ |
90 | class_alias( UnifiedDiffFormatter::class, 'UnifiedDiffFormatter' ); |