public static function decode($data)
    {
        if (!is_string($data)) {
            throw new InvalidArgumentException('data must be string');
        }

        // undo the URL safe replacement
        $convertedData = strtr($data, '-_', '+/');

        // restore the padding
        switch (strlen($convertedData) % 4) {
            case 0:
                break;
            case 2:
                $convertedData .= '==';
                break;
            case 3:
                $convertedData .= '=';
                break;
            default:
                throw new InvalidArgumentException('invalid base64url string length');
        }

        return parent::decode($convertedData);
    }