@@ -39,7 +39,7 @@ final class Differ
3939 'groupedOpcodesGnu ' => [],
4040 'oldNoEolAtEofIdx ' => -1 ,
4141 'newNoEolAtEofIdx ' => -1 ,
42- 'oldNewComparison ' => 0 ,
42+ 'oldNewAreSame ' => false ,
4343 ];
4444
4545 /**
@@ -84,10 +84,9 @@ final class Differ
8484 private int $ newNoEolAtEofIdx = -1 ;
8585
8686 /**
87- * @var int the result of comparing the old and the new with the spaceship operator
88- * `-1` means `old < new`, `0` means `old == new`, `1` means `old > new`
87+ * @var bool the result of spaceship operator comparing old and new (0 if they are the same, 1 if they are different)
8988 */
90- private int $ oldNewComparison = 0 ;
89+ private bool $ oldNewAreSame = false ;
9190
9291 /**
9392 * @var int[][][] array containing the generated opcodes for the differences between the two items
@@ -232,12 +231,22 @@ public function getNewNoEolAtEofIdx(): int
232231 return $ this ->finalize ()->newNoEolAtEofIdx ;
233232 }
234233
234+ /**
235+ * Check whether the old and the new are the same.
236+ */
237+ public function getOldNewAreSame (): bool
238+ {
239+ return $ this ->finalize ()->oldNewAreSame ;
240+ }
241+
235242 /**
236243 * Compare the old and the new with the spaceship operator.
244+ *
245+ * @deprecated Use getOldNewAreSame() instead
237246 */
238247 public function getOldNewComparison (): int
239248 {
240- return $ this ->finalize ()-> oldNewComparison ;
249+ return $ this ->getOldNewAreSame () ? 0 : 1 ;
241250 }
242251
243252 /**
@@ -302,7 +311,7 @@ public function getGroupedOpcodes(): array
302311
303312 $ this ->getGroupedOpcodesPre ($ old , $ new );
304313
305- if ($ this ->oldNewComparison === 0 && $ this ->options ->fullContextIfIdentical ) {
314+ if ($ this ->oldNewAreSame && $ this ->options ->fullContextIfIdentical ) {
306315 $ opcodes = [
307316 [
308317 [SequenceMatcher::OP_EQ , 0 , \count ($ old ), 0 , \count ($ new )],
@@ -338,7 +347,7 @@ public function getGroupedOpcodesGnu(): array
338347
339348 $ this ->getGroupedOpcodesGnuPre ($ old , $ new );
340349
341- if ($ this ->oldNewComparison === 0 && $ this ->options ->fullContextIfIdentical ) {
350+ if ($ this ->oldNewAreSame && $ this ->options ->fullContextIfIdentical ) {
342351 $ opcodes = [
343352 [
344353 [SequenceMatcher::OP_EQ , 0 , \count ($ old ), 0 , \count ($ new )],
@@ -483,7 +492,7 @@ private function finalize(): self
483492
484493 $ this ->oldNoEolAtEofIdx = $ this ->getOld (-1 ) === ['' ] ? -1 : \count ($ this ->old );
485494 $ this ->newNoEolAtEofIdx = $ this ->getNew (-1 ) === ['' ] ? -1 : \count ($ this ->new );
486- $ this ->oldNewComparison = $ this ->old <=> $ this ->new ;
495+ $ this ->oldNewAreSame = $ this ->old === $ this ->new ;
487496
488497 $ this ->sequenceMatcher ->setOptions ($ this ->options ->toSequenceMatcherOptions ());
489498 }
0 commit comments