public function filterPath($path, $trim = null)
    {
        if (!is_string($path)) {
            throw new InvalidArgumentException('The path must be a string.');
        }

        if ($trim === null && defined(get_called_class().'::DIRECTORY_SEPARATORS')) {
            $trim = static::DIRECTORY_SEPARATORS;
        }

        if ($trim) {
            if (!is_string($trim)) {
                throw new InvalidArgumentException(
                    'The characters to strip must be a string or use static::DIRECTORY_SEPARATORS.'
                );
            }

            $path = trim($path, $trim);
        }

        return trim($path);
    }