-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* readme updated * cbu generator done
- Loading branch information
Showing
5 changed files
with
72 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 1997-2018 Reyesoft <[email protected]>. | ||
* | ||
* This file is part of JsonApiPlayground. JsonApiPlayground can not be copied and/or | ||
* distributed without the express permission of Reyesoft | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ArgentinaDataGenerator; | ||
|
||
use Faker\Provider\Base; | ||
|
||
class CbuFakerProvider extends Base | ||
{ | ||
public static function cbu(): string | ||
{ | ||
$A = random_int(1000000, 9999999); // 7 | ||
$Ax = self::getChecksum($A); | ||
$B = random_int(1000000000000, 9999999999999); // 13 | ||
$Bx = self::getChecksum($B); | ||
|
||
return $A . $Ax . $B . $Bx; | ||
} | ||
|
||
private static function getChecksum(int $number): int | ||
{ | ||
$value = (string) $number; | ||
$ponderador = [3, 1, 7, 9]; | ||
$sum = 0; | ||
$j = 0; | ||
for ($i = strlen($value) - 1; $i >= 0; --$i) { | ||
$sum += ($value[$i] * $ponderador[$j % 4]); | ||
++$j; | ||
} | ||
|
||
return (10 - $sum % 10) % 10; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 1997-2018 Reyesoft <[email protected]>. | ||
* | ||
* This file is part of JsonApiPlayground. JsonApiPlayground can not be copied and/or | ||
* distributed without the express permission of Reyesoft | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests; | ||
|
||
use ArgentinaDataGenerator\CbuFakerProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CbuFakerProviderTest extends TestCase | ||
{ | ||
public function testCbu(): void | ||
{ | ||
$generator = new CbuFakerProvider(\Faker\Factory::create()); | ||
for ($i = 0; $i < 100; ++$i) { | ||
$cbu = $generator::cbu(); | ||
$this->assertTrue(\Cbu::isValid($cbu), $cbu . ' not valid.'); | ||
} | ||
} | ||
} |