Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
97.22% |
35 / 36 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
ArrayDiffFormatter | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
9 | |
100.00% |
1 / 1 |
format | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
9 |
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 pseudo-formatter that just passes along the Diff::$edits array |
31 | * @newable |
32 | * @ingroup DifferenceEngine |
33 | */ |
34 | class ArrayDiffFormatter extends DiffFormatter { |
35 | |
36 | /** |
37 | * @param Diff $diff A Diff object. |
38 | * |
39 | * @return array[] List of associative arrays, each describing a difference. |
40 | * @suppress PhanParamSignatureMismatch |
41 | */ |
42 | public function format( $diff ) { |
43 | $oldline = 1; |
44 | $newline = 1; |
45 | $retval = []; |
46 | foreach ( $diff->getEdits() as $edit ) { |
47 | switch ( $edit->getType() ) { |
48 | case 'add': |
49 | foreach ( $edit->getClosing() as $line ) { |
50 | $retval[] = [ |
51 | 'action' => 'add', |
52 | 'new' => $line, |
53 | 'newline' => $newline++ |
54 | ]; |
55 | } |
56 | break; |
57 | case 'delete': |
58 | foreach ( $edit->getOrig() as $line ) { |
59 | $retval[] = [ |
60 | 'action' => 'delete', |
61 | 'old' => $line, |
62 | 'oldline' => $oldline++, |
63 | ]; |
64 | } |
65 | break; |
66 | case 'change': |
67 | foreach ( $edit->getOrig() as $key => $line ) { |
68 | $retval[] = [ |
69 | 'action' => 'change', |
70 | 'old' => $line, |
71 | 'new' => $edit->getClosing( $key ), |
72 | 'oldline' => $oldline++, |
73 | 'newline' => $newline++, |
74 | ]; |
75 | } |
76 | break; |
77 | case 'copy': |
78 | $oldline += $edit->norig(); |
79 | $newline += $edit->norig(); |
80 | } |
81 | } |
82 | |
83 | return $retval; |
84 | } |
85 | |
86 | } |
87 | |
88 | /** @deprecated class alias since 1.41 */ |
89 | class_alias( ArrayDiffFormatter::class, 'ArrayDiffFormatter' ); |