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 | * @license GPL-2.0-or-later |
| 9 | * @file |
| 10 | * @ingroup DifferenceEngine |
| 11 | * @defgroup DifferenceEngine DifferenceEngine |
| 12 | */ |
| 13 | |
| 14 | namespace Wikimedia\Diff; |
| 15 | |
| 16 | /** |
| 17 | * The base class for all other DiffOp classes. |
| 18 | * |
| 19 | * The classes that extend DiffOp are: DiffOpCopy, DiffOpDelete, DiffOpAdd and |
| 20 | * DiffOpChange. FakeDiffOp also extends DiffOp, but it is not located in this file. |
| 21 | * |
| 22 | * @ingroup DifferenceEngine |
| 23 | */ |
| 24 | abstract class DiffOp { |
| 25 | |
| 26 | /** |
| 27 | * @var string |
| 28 | * @private Please use {@see getType} |
| 29 | */ |
| 30 | public $type; |
| 31 | |
| 32 | /** |
| 33 | * @var string[]|false The left ("old") side of the diff, or false when it's an "add" |
| 34 | * @private Please use {@see getOrig} |
| 35 | */ |
| 36 | public $orig; |
| 37 | |
| 38 | /** |
| 39 | * @var string[]|false The right ("new") side of the diff, or false when it's a "delete" |
| 40 | * @private Please use {@see getClosing} |
| 41 | */ |
| 42 | public $closing; |
| 43 | |
| 44 | /** |
| 45 | * @return string Either "add", "change", "copy", or "delete" |
| 46 | */ |
| 47 | public function getType() { |
| 48 | return $this->type; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns either all lines on the left ("old") side of the diff, or false when it's an add |
| 53 | * operation. |
| 54 | * |
| 55 | * @return string[]|false |
| 56 | */ |
| 57 | public function getOrig() { |
| 58 | return $this->orig; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Without a line number this returns either all lines on the right ("new") side of the diff, or |
| 63 | * false when it's a delete operation. |
| 64 | * |
| 65 | * With a line number this returns either the line or null if the line doesn't exist. |
| 66 | * |
| 67 | * @param int|null $i Line number, or null for all lines in the operation |
| 68 | * @return string[]|false|string|null |
| 69 | */ |
| 70 | public function getClosing( $i = null ) { |
| 71 | if ( $i === null ) { |
| 72 | return $this->closing; |
| 73 | } |
| 74 | if ( array_key_exists( $i, $this->closing ) ) { |
| 75 | return $this->closing[$i]; |
| 76 | } |
| 77 | return null; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @return self Inverted operation (a.k.a. revert or undo), e.g. "delete" becomes "add" |
| 82 | */ |
| 83 | abstract public function reverse(); |
| 84 | |
| 85 | /** |
| 86 | * @return int Number of lines on the left ("old") side of the diff, {@see getOrig} |
| 87 | */ |
| 88 | public function norig() { |
| 89 | return $this->orig ? count( $this->orig ) : 0; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @return int Number of lines on the right ("new") side of the diff, see {@see getClosing} |
| 94 | */ |
| 95 | public function nclosing() { |
| 96 | return $this->closing ? count( $this->closing ) : 0; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /** @deprecated class alias since 1.41 */ |
| 101 | class_alias( DiffOp::class, 'DiffOp' ); |