Skip to content

Commit

Permalink
Fix "Uninitialized string offset -1" warning
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Oct 30, 2024
1 parent df95a6e commit 2c3940e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ScalarComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ private static function removeOverlongCommonSuffix(string $string1, string $stri

private static function findCommonSuffix(string $string1, string $string2): string
{
if ($string1 === '' || $string2 === '') {
return '';
}

$lastCharIndex1 = strlen($string1) - 1;
$lastCharIndex2 = strlen($string2) - 1;

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/ScalarComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ public static function assertEqualsFailsWithDiffProvider(): array
--- Expected
+++ Actual
@@ @@
-''
+'other string'
",
'',
'other string',
],
[
"
--- Expected
+++ Actual
@@ @@
-'...string which will be cut HERE some trailer'
+'...string which will be cut XYZ some trailer'
",
Expand Down

0 comments on commit 2c3940e

Please sign in to comment.