1010 * A comprehensive library for generating differences between two strings
1111 * in multiple formats (unified, side by side HTML etc)
1212 *
13- * PHP version 5
13+ * PHP version 7.1 or greater
1414 *
1515 * Copyright (c) 2009 Chris Boulton <chris.boulton@interspire.com>
1616 *
4040 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4141 * POSSIBILITY OF SUCH DAMAGE.
4242 *
43- * @package Diff
43+ * @package jblond
4444 * @author Chris Boulton <chris.boulton@interspire.com>
4545 * @copyright (c) 2009 Chris Boulton
4646 * @license New BSD License http://www.opensource.org/licenses/bsd-license.php
47- * @version 1.6
47+ * @version 1.10
4848 * @link https://github.com/JBlond/php-diff
4949 */
5050class Diff
5151{
5252 /**
5353 * @var array The "old" sequence to use as the basis for the comparison.
5454 */
55- private $ a = null ;
55+ private $ old = null ;
5656
5757 /**
5858 * @var array The "new" sequence to generate the changes for.
5959 */
60- private $ b = null ;
60+ private $ new = null ;
6161
6262 /**
6363 * @var array Array containing the generated op codes for the differences between the two items.
@@ -83,14 +83,14 @@ class Diff
8383 /**
8484 * The constructor.
8585 *
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.
8888 * @param array $options Array for the options
8989 */
90- public function __construct ($ a , $ b , $ options = array ())
90+ public function __construct (array $ oldArray , array $ newArray , array $ options = array ())
9191 {
92- $ this ->a = $ a ;
93- $ this ->b = $ b ;
92+ $ this ->old = $ oldArray ;
93+ $ this ->new = $ newArray ;
9494
9595 if (is_array ($ options )) {
9696 $ this ->options = array_merge ($ this ->defaultOptions , $ options );
@@ -119,22 +119,21 @@ public function render($renderer)
119119 * that line.
120120 *
121121 * @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.
123123 * @return array Array of all of the lines between the specified range.
124124 */
125- public function getA ( $ start = 0 , $ end = null ) : array
125+ public function getOld ( int $ start = 0 , $ end = null ) : array
126126 {
127127 if ($ start == 0 && $ end === null ) {
128- return $ this ->a ;
128+ return $ this ->old ;
129129 }
130130
131131 if ($ end === null ) {
132- $ length = 1 ;
133- } else {
134- $ length = $ end - $ start ;
132+ return array_slice ($ this ->old , $ start , 1 );
135133 }
136134
137- return array_slice ($ this ->a , $ start , $ length );
135+ $ length = $ end - $ start ;
136+ return array_slice ($ this ->old , $ start , $ length );
138137 }
139138
140139 /**
@@ -144,22 +143,21 @@ public function getA($start = 0, $end = null) : array
144143 * that line.
145144 *
146145 * @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.
148147 * @return array Array of all of the lines between the specified range.
149148 */
150- public function getB ( $ start = 0 , $ end = null ) : array
149+ public function getNew ( int $ start = 0 , $ end = null ) : array
151150 {
152151 if ($ start == 0 && $ end === null ) {
153- return $ this ->b ;
152+ return $ this ->new ;
154153 }
155154
156155 if ($ end === null ) {
157- $ length = 1 ;
158- } else {
159- $ length = $ end - $ start ;
156+ return array_slice ($ this ->new , $ start , 1 );
160157 }
161158
162- return array_slice ($ this ->b , $ start , $ length );
159+ $ length = $ end - $ start ;
160+ return array_slice ($ this ->new , $ start , $ length );
163161 }
164162
165163 /**
@@ -176,7 +174,7 @@ public function getGroupedOpcodes() : array
176174 return $ this ->groupedCodes ;
177175 }
178176
179- $ sequenceMatcher = new SequenceMatcher ($ this ->a , $ this ->b , $ this ->options , null );
177+ $ sequenceMatcher = new SequenceMatcher ($ this ->old , $ this ->new , $ this ->options , null );
180178 $ this ->groupedCodes = $ sequenceMatcher ->getGroupedOpcodes ($ this ->options ['context ' ]);
181179 return $ this ->groupedCodes ;
182180 }
0 commit comments