@@ -25,12 +25,12 @@ final class Diff
2525 /**
2626 * @var string[] the "old" sequence to use as the basis for the comparison
2727 */
28- private $ a = [];
28+ private $ old = [];
2929
3030 /**
3131 * @var string[] the "new" sequence to generate the changes for
3232 */
33- private $ b = [];
33+ private $ new = [];
3434
3535 /**
3636 * @var null|SequenceMatcher the sequence matcher
@@ -57,63 +57,63 @@ final class Diff
5757 /**
5858 * The constructor.
5959 *
60- * @param string[] $a array containing the lines of the first string to compare
61- * @param string[] $b array containing the lines for the second string to compare
60+ * @param string[] $old array containing the lines of the old string to compare
61+ * @param string[] $new array containing the lines for the new string to compare
6262 * @param array $options
6363 */
64- public function __construct (array $ a , array $ b , array $ options = [])
64+ public function __construct (array $ old , array $ new , array $ options = [])
6565 {
6666 $ this ->sequenceMatcher = new SequenceMatcher ([], []);
6767
68- $ this ->setAB ( $ a , $ b )->setOptions ($ options );
68+ $ this ->setOldNew ( $ old , $ new )->setOptions ($ options );
6969 }
7070
7171 /**
72- * Set a and b .
72+ * Set old and new .
7373 *
74- * @param string[] $a the a
75- * @param string[] $b the b
74+ * @param string[] $old the old
75+ * @param string[] $new the new
7676 *
7777 * @return self
7878 */
79- public function setAB (array $ a , array $ b ): self
79+ public function setOldNew (array $ old , array $ new ): self
8080 {
81- $ this ->setA ( $ a )->setB ( $ b );
81+ $ this ->setOld ( $ old )->setNew ( $ new );
8282
8383 return $ this ;
8484 }
8585
8686 /**
87- * Set a .
87+ * Set old .
8888 *
89- * @param string[] $a the a
89+ * @param string[] $old the old
9090 *
9191 * @return self
9292 */
93- public function setA (array $ a ): self
93+ public function setOld (array $ old ): self
9494 {
95- if ($ this ->a !== $ a ) {
96- $ this ->a = $ a ;
95+ if ($ this ->old !== $ old ) {
96+ $ this ->old = $ old ;
9797 $ this ->groupedCodes = null ;
98- $ this ->sequenceMatcher ->setSeq1 ($ a );
98+ $ this ->sequenceMatcher ->setSeq1 ($ old );
9999 }
100100
101101 return $ this ;
102102 }
103103
104104 /**
105- * Set b .
105+ * Set new .
106106 *
107- * @param string[] $b the b
107+ * @param string[] $new the new
108108 *
109109 * @return self
110110 */
111- public function setB (array $ b ): self
111+ public function setNew (array $ new ): self
112112 {
113- if ($ this ->b !== $ b ) {
114- $ this ->b = $ b ;
113+ if ($ this ->new !== $ new ) {
114+ $ this ->new = $ new ;
115115 $ this ->groupedCodes = null ;
116- $ this ->sequenceMatcher ->setSeq2 ($ b );
116+ $ this ->sequenceMatcher ->setSeq2 ($ new );
117117 }
118118
119119 return $ this ;
@@ -136,8 +136,7 @@ public function setOptions(array $options): self
136136 }
137137
138138 /**
139- * Get a range of lines from $start to $end from the first comparison string
140- * and return them as an array.
139+ * Get a range of lines from $start to $end from the old string and return them as an array.
141140 *
142141 * If $end is null, it returns array sliced from the $start to the end.
143142 *
@@ -146,14 +145,13 @@ public function setOptions(array $options): self
146145 *
147146 * @return string[] array of all of the lines between the specified range
148147 */
149- public function getA (int $ start = 0 , ?int $ end = null ): array
148+ public function getOld (int $ start = 0 , ?int $ end = null ): array
150149 {
151- return $ this ->getText ($ this ->a , $ start , $ end );
150+ return $ this ->getText ($ this ->old , $ start , $ end );
152151 }
153152
154153 /**
155- * Get a range of lines from $start to $end from the second comparison string
156- * and return them as an array.
154+ * Get a range of lines from $start to $end from the new string and return them as an array.
157155 *
158156 * If $end is null, it returns array sliced from the $start to the end.
159157 *
@@ -162,9 +160,9 @@ public function getA(int $start = 0, ?int $end = null): array
162160 *
163161 * @return string[] array of all of the lines between the specified range
164162 */
165- public function getB (int $ start = 0 , ?int $ end = null ): array
163+ public function getNew (int $ start = 0 , ?int $ end = null ): array
166164 {
167- return $ this ->getText ($ this ->b , $ start , $ end );
165+ return $ this ->getText ($ this ->new , $ start , $ end );
168166 }
169167
170168 /**
@@ -216,11 +214,90 @@ public function render(AbstractRenderer $renderer): string
216214
217215 // the "no difference" situation may happen frequently
218216 // let's save some calculation if possible
219- return $ this ->a === $ this ->b
217+ return $ this ->old === $ this ->new
220218 ? $ renderer ::getIdenticalResult ()
221219 : $ renderer ->render ();
222220 }
223221
222+ /**
223+ * Set a and b.
224+ *
225+ * @deprecated 5.0.0
226+ *
227+ * @param string[] $a the a
228+ * @param string[] $b the b
229+ *
230+ * @return self
231+ */
232+ public function setAB (array $ a , array $ b ): self
233+ {
234+ return $ this ->setOldNew ($ a , $ b );
235+ }
236+
237+ /**
238+ * Set a.
239+ *
240+ * @deprecated 5.0.0
241+ *
242+ * @param string[] $a the a
243+ *
244+ * @return self
245+ */
246+ public function setA (array $ a ): self
247+ {
248+ return $ this ->setOld ($ a );
249+ }
250+
251+ /**
252+ * Set b.
253+ *
254+ * @deprecated 5.0.0
255+ *
256+ * @param string[] $b the b
257+ *
258+ * @return self
259+ */
260+ public function setB (array $ b ): self
261+ {
262+ return $ this ->setNew ($ b );
263+ }
264+
265+ /**
266+ * Get a range of lines from $start to $end from the first comparison string
267+ * and return them as an array.
268+ *
269+ * If $end is null, it returns array sliced from the $start to the end.
270+ *
271+ * @deprecated 5.0.0
272+ *
273+ * @param int $start the starting number. If null, the whole array will be returned.
274+ * @param null|int $end the ending number. If null, only the item in $start will be returned.
275+ *
276+ * @return string[] array of all of the lines between the specified range
277+ */
278+ public function getA (int $ start = 0 , ?int $ end = null ): array
279+ {
280+ return $ this ->getOld ($ start , $ end );
281+ }
282+
283+ /**
284+ * Get a range of lines from $start to $end from the second comparison string
285+ * and return them as an array.
286+ *
287+ * If $end is null, it returns array sliced from the $start to the end.
288+ *
289+ * @deprecated 5.0.0
290+ *
291+ * @param int $start the starting number
292+ * @param null|int $end the ending number
293+ *
294+ * @return string[] array of all of the lines between the specified range
295+ */
296+ public function getB (int $ start = 0 , ?int $ end = null ): array
297+ {
298+ return $ this ->getNew ($ start , $ end );
299+ }
300+
224301 /**
225302 * The work horse of getA() and getB().
226303 *
0 commit comments