Code Duplication    Length = 3-3 lines in 4 locations

Str.php 3 locations

@@ 453-455 (lines=3) @@
450
        $length   = mb_strlen($haystack, $encoding);
451
452
        // Make sure the offset is contained in the initial string.
453
        if (abs($offset) >= $length) {
454
            throw new \OutOfBoundsException('The given $offset ['.$offset.'] does not exist within the string ['.static::truncate($haystack, 20, '...', false, $encoding).'].');
455
        }
456
457
        // With a negative offset, we'll convert it to a positive one for the initial part (before the inserted
458
        // substring), since we'll be using that as a length actually.
@@ 536-538 (lines=3) @@
533
        $length   = mb_strlen($haystack, $encoding);
534
535
        // Make sure the offset given exists within the $haystack.
536
        if (abs($offset) >= $length) {
537
            throw new \OutOfBoundsException('The given $offset ['.$offset.'] does not exist within the string ['.static::truncate($haystack, 20, '...', false, $encoding).'].');
538
        }
539
540
        $func   = $strict ? 'mb_strpos' : 'mb_stripos';
541
        $result = [];
@@ 955-957 (lines=3) @@
952
953
        // Check if the absolute starting index (to account for negative indices) + 1 (since it's 0-indexed
954
        // while length is > 1 at this point) is within the length of the string.
955
        if (abs($offset) >= mb_strlen($haystack, $encoding)) {
956
            throw new \OutOfBoundsException('The given $offset ['.$offset.'] does not exist within the string ['.static::truncate($haystack, 20, '...', false, $encoding).'].');
957
        }
958
959
        return mb_substr($haystack, $offset, $length, $encoding);
960
    }

str/Character.php 1 location

@@ 85-87 (lines=3) @@
82
83
        // Check if the absolute starting index (to account for negative indexes) + 1 (since it's 0-indexed
84
        // while length is > 1 at this point) is within the length of the string.
85
        if (abs($offset) >= mb_strlen($haystack, $encoding)) {
86
            throw new \OutOfBoundsException('The given $offset ['.$offset.'] does not exist within the string ['.utils\Str::truncate($haystack, 20, '...', $encoding).'].');
87
        }
88
89
        return mb_substr($haystack, $offset, 1, $encoding);
90
    }