Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / includes / diff / ArrayDiffFormatter.php
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 /**
28 * A pseudo-formatter that just passes along the Diff::$edits array
29 * @ingroup DifferenceEngine
30 */
31 class ArrayDiffFormatter extends DiffFormatter {
32
33 /**
34 * @param Diff $diff A Diff object.
35 *
36 * @return array[] List of associative arrays, each describing a difference.
37 * @suppress PhanParamSignatureMismatch
38 */
39 public function format( $diff ) {
40 $oldline = 1;
41 $newline = 1;
42 $retval = [];
43 foreach ( $diff->getEdits() as $edit ) {
44 switch ( $edit->getType() ) {
45 case 'add':
46 foreach ( $edit->getClosing() as $line ) {
47 $retval[] = [
48 'action' => 'add',
49 'new' => $line,
50 'newline' => $newline++
51 ];
52 }
53 break;
54 case 'delete':
55 foreach ( $edit->getOrig() as $line ) {
56 $retval[] = [
57 'action' => 'delete',
58 'old' => $line,
59 'oldline' => $oldline++,
60 ];
61 }
62 break;
63 case 'change':
64 foreach ( $edit->getOrig() as $key => $line ) {
65 $retval[] = [
66 'action' => 'change',
67 'old' => $line,
68 'new' => $edit->getClosing( $key ),
69 'oldline' => $oldline++,
70 'newline' => $newline++,
71 ];
72 }
73 break;
74 case 'copy':
75 $oldline += count( $edit->getOrig() );
76 $newline += count( $edit->getOrig() );
77 }
78 }
79
80 return $retval;
81 }
82
83 }