protected function assertValidCode($code)
    {
        if ($code instanceof Money) {
            $code = $code->getCurrency();
        }

        if ($code instanceof Currency) {
            return (string) $code;
        }

        if (!is_string($code)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Currency code should be a string; %s given',
                gettype($code)
            ));
        }

        $code = trim(strtoupper($code));
        if (!Currencies::exists($code)) {
            throw new Exception\UnknownCurrencyException(sprintf(
                '%s is not a valid ISO 4217 Currency code',
                $code
            ));
        }

        return $code;
    }