10
10
* A comprehensive library for generating differences between two strings
11
11
* in multiple formats (unified, side by side HTML etc)
12
12
*
13
- * PHP version 5
13
+ * PHP version 7.1 or greater
14
14
*
15
15
* Copyright (c) 2009 Chris Boulton <[email protected] >
16
16
*
40
40
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41
41
* POSSIBILITY OF SUCH DAMAGE.
42
42
*
43
- * @package Diff
43
+ * @package jblond
44
44
* @author Chris Boulton <[email protected] >
45
45
* @copyright (c) 2009 Chris Boulton
46
46
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
47
- * @version 1.6
47
+ * @version 1.10
48
48
* @link https://github.com/JBlond/php-diff
49
49
*/
50
50
class Diff
51
51
{
52
52
/**
53
53
* @var array The "old" sequence to use as the basis for the comparison.
54
54
*/
55
- private $ a = null ;
55
+ private $ old = null ;
56
56
57
57
/**
58
58
* @var array The "new" sequence to generate the changes for.
59
59
*/
60
- private $ b = null ;
60
+ private $ new = null ;
61
61
62
62
/**
63
63
* @var array Array containing the generated op codes for the differences between the two items.
@@ -83,14 +83,14 @@ class Diff
83
83
/**
84
84
* The constructor.
85
85
*
86
- * @param array $a Array containing the lines of the first string to compare.
87
- * @param array $b Array containing the lines for the second string to compare.
86
+ * @param array $oldArray Array containing the lines of the first string to compare.
87
+ * @param array $newArray Array containing the lines for the second string to compare.
88
88
* @param array $options Array for the options
89
89
*/
90
- public function __construct ($ a , $ b , $ options = array ())
90
+ public function __construct (array $ oldArray , array $ newArray , array $ options = array ())
91
91
{
92
- $ this ->a = $ a ;
93
- $ this ->b = $ b ;
92
+ $ this ->old = $ oldArray ;
93
+ $ this ->new = $ newArray ;
94
94
95
95
if (is_array ($ options )) {
96
96
$ this ->options = array_merge ($ this ->defaultOptions , $ options );
@@ -119,22 +119,21 @@ public function render($renderer)
119
119
* that line.
120
120
*
121
121
* @param int $start The starting number.
122
- * @param int $end The ending number. If not supplied, only the item in $start will be returned.
122
+ * @param int|null $end The ending number. If not supplied, only the item in $start will be returned.
123
123
* @return array Array of all of the lines between the specified range.
124
124
*/
125
- public function getA ( $ start = 0 , $ end = null ) : array
125
+ public function getOld ( int $ start = 0 , $ end = null ) : array
126
126
{
127
127
if ($ start == 0 && $ end === null ) {
128
- return $ this ->a ;
128
+ return $ this ->old ;
129
129
}
130
130
131
131
if ($ end === null ) {
132
- $ length = 1 ;
133
- } else {
134
- $ length = $ end - $ start ;
132
+ return array_slice ($ this ->old , $ start , 1 );
135
133
}
136
134
137
- return array_slice ($ this ->a , $ start , $ length );
135
+ $ length = $ end - $ start ;
136
+ return array_slice ($ this ->old , $ start , $ length );
138
137
}
139
138
140
139
/**
@@ -144,22 +143,21 @@ public function getA($start = 0, $end = null) : array
144
143
* that line.
145
144
*
146
145
* @param int $start The starting number.
147
- * @param int $end The ending number. If not supplied, only the item in $start will be returned.
146
+ * @param int|null $end The ending number. If not supplied, only the item in $start will be returned.
148
147
* @return array Array of all of the lines between the specified range.
149
148
*/
150
- public function getB ( $ start = 0 , $ end = null ) : array
149
+ public function getNew ( int $ start = 0 , $ end = null ) : array
151
150
{
152
151
if ($ start == 0 && $ end === null ) {
153
- return $ this ->b ;
152
+ return $ this ->new ;
154
153
}
155
154
156
155
if ($ end === null ) {
157
- $ length = 1 ;
158
- } else {
159
- $ length = $ end - $ start ;
156
+ return array_slice ($ this ->new , $ start , 1 );
160
157
}
161
158
162
- return array_slice ($ this ->b , $ start , $ length );
159
+ $ length = $ end - $ start ;
160
+ return array_slice ($ this ->new , $ start , $ length );
163
161
}
164
162
165
163
/**
@@ -176,7 +174,7 @@ public function getGroupedOpcodes() : array
176
174
return $ this ->groupedCodes ;
177
175
}
178
176
179
- $ sequenceMatcher = new SequenceMatcher ($ this ->a , $ this ->b , $ this ->options , null );
177
+ $ sequenceMatcher = new SequenceMatcher ($ this ->old , $ this ->new , $ this ->options , null );
180
178
$ this ->groupedCodes = $ sequenceMatcher ->getGroupedOpcodes ($ this ->options ['context ' ]);
181
179
return $ this ->groupedCodes ;
182
180
}
0 commit comments