@@ -25,12 +25,12 @@ final class Diff
25
25
/**
26
26
* @var string[] the "old" sequence to use as the basis for the comparison
27
27
*/
28
- private $ a = [];
28
+ private $ old = [];
29
29
30
30
/**
31
31
* @var string[] the "new" sequence to generate the changes for
32
32
*/
33
- private $ b = [];
33
+ private $ new = [];
34
34
35
35
/**
36
36
* @var null|SequenceMatcher the sequence matcher
@@ -57,63 +57,63 @@ final class Diff
57
57
/**
58
58
* The constructor.
59
59
*
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
62
62
* @param array $options
63
63
*/
64
- public function __construct (array $ a , array $ b , array $ options = [])
64
+ public function __construct (array $ old , array $ new , array $ options = [])
65
65
{
66
66
$ this ->sequenceMatcher = new SequenceMatcher ([], []);
67
67
68
- $ this ->setAB ( $ a , $ b )->setOptions ($ options );
68
+ $ this ->setOldNew ( $ old , $ new )->setOptions ($ options );
69
69
}
70
70
71
71
/**
72
- * Set a and b .
72
+ * Set old and new .
73
73
*
74
- * @param string[] $a the a
75
- * @param string[] $b the b
74
+ * @param string[] $old the old
75
+ * @param string[] $new the new
76
76
*
77
77
* @return self
78
78
*/
79
- public function setAB (array $ a , array $ b ): self
79
+ public function setOldNew (array $ old , array $ new ): self
80
80
{
81
- $ this ->setA ( $ a )->setB ( $ b );
81
+ $ this ->setOld ( $ old )->setNew ( $ new );
82
82
83
83
return $ this ;
84
84
}
85
85
86
86
/**
87
- * Set a .
87
+ * Set old .
88
88
*
89
- * @param string[] $a the a
89
+ * @param string[] $old the old
90
90
*
91
91
* @return self
92
92
*/
93
- public function setA (array $ a ): self
93
+ public function setOld (array $ old ): self
94
94
{
95
- if ($ this ->a !== $ a ) {
96
- $ this ->a = $ a ;
95
+ if ($ this ->old !== $ old ) {
96
+ $ this ->old = $ old ;
97
97
$ this ->groupedCodes = null ;
98
- $ this ->sequenceMatcher ->setSeq1 ($ a );
98
+ $ this ->sequenceMatcher ->setSeq1 ($ old );
99
99
}
100
100
101
101
return $ this ;
102
102
}
103
103
104
104
/**
105
- * Set b .
105
+ * Set new .
106
106
*
107
- * @param string[] $b the b
107
+ * @param string[] $new the new
108
108
*
109
109
* @return self
110
110
*/
111
- public function setB (array $ b ): self
111
+ public function setNew (array $ new ): self
112
112
{
113
- if ($ this ->b !== $ b ) {
114
- $ this ->b = $ b ;
113
+ if ($ this ->new !== $ new ) {
114
+ $ this ->new = $ new ;
115
115
$ this ->groupedCodes = null ;
116
- $ this ->sequenceMatcher ->setSeq2 ($ b );
116
+ $ this ->sequenceMatcher ->setSeq2 ($ new );
117
117
}
118
118
119
119
return $ this ;
@@ -136,8 +136,7 @@ public function setOptions(array $options): self
136
136
}
137
137
138
138
/**
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.
141
140
*
142
141
* If $end is null, it returns array sliced from the $start to the end.
143
142
*
@@ -146,14 +145,13 @@ public function setOptions(array $options): self
146
145
*
147
146
* @return string[] array of all of the lines between the specified range
148
147
*/
149
- public function getA (int $ start = 0 , ?int $ end = null ): array
148
+ public function getOld (int $ start = 0 , ?int $ end = null ): array
150
149
{
151
- return $ this ->getText ($ this ->a , $ start , $ end );
150
+ return $ this ->getText ($ this ->old , $ start , $ end );
152
151
}
153
152
154
153
/**
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.
157
155
*
158
156
* If $end is null, it returns array sliced from the $start to the end.
159
157
*
@@ -162,9 +160,9 @@ public function getA(int $start = 0, ?int $end = null): array
162
160
*
163
161
* @return string[] array of all of the lines between the specified range
164
162
*/
165
- public function getB (int $ start = 0 , ?int $ end = null ): array
163
+ public function getNew (int $ start = 0 , ?int $ end = null ): array
166
164
{
167
- return $ this ->getText ($ this ->b , $ start , $ end );
165
+ return $ this ->getText ($ this ->new , $ start , $ end );
168
166
}
169
167
170
168
/**
@@ -216,11 +214,90 @@ public function render(AbstractRenderer $renderer): string
216
214
217
215
// the "no difference" situation may happen frequently
218
216
// let's save some calculation if possible
219
- return $ this ->a === $ this ->b
217
+ return $ this ->old === $ this ->new
220
218
? $ renderer ::getIdenticalResult ()
221
219
: $ renderer ->render ();
222
220
}
223
221
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
+
224
301
/**
225
302
* The work horse of getA() and getB().
226
303
*
0 commit comments