1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-03-20 07:19:50 +01:00

copied Company.bankAccountNumber method to base Company class; updated readme with an example

This commit is contained in:
John Was 2013-09-18 22:00:35 +02:00
parent bb7bd3355a
commit 645956dbc9
2 changed files with 30 additions and 0 deletions
readme.md
src/Faker/Provider

@ -96,6 +96,7 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle
bs // 'e-enable robust architectures'
company // 'Bogan-Treutel'
companySuffix // 'and Sons'
bankAccountNumber($prefix = '', $digitsNumber = 24, $countryCode = 'PL') // 'PL08032566519460083829368443'
### `Faker\Provider\Lorem`

@ -27,4 +27,33 @@ class Company extends \Faker\Provider\Base
{
return static::randomElement(static::$companySuffix);
}
/**
* International Bank Account Number (IBAN)
* @link http://en.wikipedia.org/wiki/International_Bank_Account_Number
* @param string $prefix for generating bank account number of a specific bank
* @param integer $digitsNumber total length without country code and 2 check digits
* @param string $countryCode ISO 3166-1 alpha-2 country code
* @return string
*/
public static function bankAccountNumber($prefix = '', $digitsNumber = 24, $countryCode = 'PL')
{
$countryCode = strtoupper($countryCode);
$result = $prefix;
$digitsNumber -= strlen($prefix);
for ($i = 0; $i < $digitsNumber; $i++) {
$result .= static::randomDigit();
}
$countryNumber = 100 * (ord($countryCode[0])-55) + (ord($countryCode[1])-55);
$tempResult = $result . $countryNumber . '00';
// perform MOD97-10 checksum calculation
$checksum = (int)$tempResult[0];
for ($i = 1; $i < strlen($tempResult); $i++) {
$checksum = (10 * $checksum + (int)$tempResult[$i]) % 97;
}
$checksum = 98 - $checksum;
if ($checksum < 10)
$checksum = '0'.$checksum;
return $countryCode . $checksum . $result;
}
}