Faker\Provider\Payment::iban PHP Method

iban() public static method

International Bank Account Number (IBAN)
public static iban ( string $countryCode, string $prefix = '', integer $length = null ) : string
$countryCode string ISO 3166-1 alpha-2 country code
$prefix string for generating bank account number of a specific bank
$length integer total length without country code and 2 check digits
return string
    public static function iban($countryCode, $prefix = '', $length = null)
    {
        $countryCode = is_null($countryCode) ? self::randomKey(self::$ibanFormats) : strtoupper($countryCode);
        $format = !isset(static::$ibanFormats[$countryCode]) ? null : static::$ibanFormats[$countryCode];
        if ($length === null) {
            if ($format === null) {
                $length = 24;
            } else {
                $length = 0;
                foreach ($format as $part) {
                    list($class, $groupCount) = $part;
                    $length += $groupCount;
                }
            }
        }
        if ($format === null) {
            $format = array(array('n', $length));
        }
        $expandedFormat = '';
        foreach ($format as $item) {
            list($class, $length) = $item;
            $expandedFormat .= str_repeat($class, $length);
        }
        $result = $prefix;
        $expandedFormat = substr($expandedFormat, strlen($result));
        foreach (str_split($expandedFormat) as $class) {
            switch ($class) {
                default:
                case 'c':
                    $result .= mt_rand(0, 100) <= 50 ? static::randomDigit() : strtoupper(static::randomLetter());
                    break;
                case 'a':
                    $result .= strtoupper(static::randomLetter());
                    break;
                case 'n':
                    $result .= static::randomDigit();
                    break;
            }
        }
        $result = static::addBankCodeChecksum($result, $countryCode);
        $checksum = Iban::checksum($countryCode . '00' . $result);
        return $countryCode . $checksum . $result;
    }