private function endsWith(string $haystack, string $needle): bool
    {
        $length = \mb_strlen($needle);

        if ($length === 0) {
            return true;
        }

        return \mb_substr($haystack, -$length) === $needle;
    }