public static function ensureTrailing($needle, $haystack)
    {
        $needleLength = strlen($needle);
        $needlePart = substr($haystack, -1 * $needleLength);

        if ($needlePart !== $needle) {
            // append missing trailing character.
            $haystack .= $needle;
        }

        return $haystack;
    }