Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.00% |
9 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
DiffOp | |
100.00% |
9 / 9 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
1 / 1 |
getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOrig | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getClosing | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
reverse | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
norig | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
nclosing | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * A PHP diff engine for phpwiki. (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 | * @defgroup DifferenceEngine DifferenceEngine |
26 | */ |
27 | |
28 | namespace Wikimedia\Diff; |
29 | |
30 | /** |
31 | * The base class for all other DiffOp classes. |
32 | * |
33 | * The classes that extend DiffOp are: DiffOpCopy, DiffOpDelete, DiffOpAdd and |
34 | * DiffOpChange. FakeDiffOp also extends DiffOp, but it is not located in this file. |
35 | * |
36 | * @ingroup DifferenceEngine |
37 | */ |
38 | abstract class DiffOp { |
39 | |
40 | /** |
41 | * @var string |
42 | * @private Please use {@see getType} |
43 | */ |
44 | public $type; |
45 | |
46 | /** |
47 | * @var string[]|false The left ("old") side of the diff, or false when it's an "add" |
48 | * @private Please use {@see getOrig} |
49 | */ |
50 | public $orig; |
51 | |
52 | /** |
53 | * @var string[]|false The right ("new") side of the diff, or false when it's a "delete" |
54 | * @private Please use {@see getClosing} |
55 | */ |
56 | public $closing; |
57 | |
58 | /** |
59 | * @return string Either "add", "change", "copy", or "delete" |
60 | */ |
61 | public function getType() { |
62 | return $this->type; |
63 | } |
64 | |
65 | /** |
66 | * Returns either all lines on the left ("old") side of the diff, or false when it's an add |
67 | * operation. |
68 | * |
69 | * @return string[]|false |
70 | */ |
71 | public function getOrig() { |
72 | return $this->orig; |
73 | } |
74 | |
75 | /** |
76 | * Without a line number this returns either all lines on the right ("new") side of the diff, or |
77 | * false when it's a delete operation. |
78 | * |
79 | * With a line number this returns either the line or null if the line doesn't exist. |
80 | * |
81 | * @param int|null $i Line number, or null for all lines in the operation |
82 | * @return string[]|false|string|null |
83 | */ |
84 | public function getClosing( $i = null ) { |
85 | if ( $i === null ) { |
86 | return $this->closing; |
87 | } |
88 | if ( array_key_exists( $i, $this->closing ) ) { |
89 | return $this->closing[$i]; |
90 | } |
91 | return null; |
92 | } |
93 | |
94 | /** |
95 | * @return self Inverted operation (a.k.a. revert or undo), e.g. "delete" becomes "add" |
96 | */ |
97 | abstract public function reverse(); |
98 | |
99 | /** |
100 | * @return int Number of lines on the left ("old") side of the diff, {@see getOrig} |
101 | */ |
102 | public function norig() { |
103 | return $this->orig ? count( $this->orig ) : 0; |
104 | } |
105 | |
106 | /** |
107 | * @return int Number of lines on the right ("new") side of the diff, see {@see getClosing} |
108 | */ |
109 | public function nclosing() { |
110 | return $this->closing ? count( $this->closing ) : 0; |
111 | } |
112 | } |
113 | |
114 | /** @deprecated class alias since 1.41 */ |
115 | class_alias( DiffOp::class, 'DiffOp' ); |