-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate iban code and make a initial test
- Loading branch information
0 parents
commit ed4d47f
Showing
5 changed files
with
142 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
composer.lock | ||
*.swp | ||
*.swo |
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,22 @@ | ||
{ | ||
"name": "xafardero/generate-iban", | ||
"description": "Generate the IBAN letter with a CCC", | ||
"type": "library", | ||
"require": { | ||
"php": ">=5.5.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"IbanGenerator\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "xaf", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false"> | ||
<testsuites> | ||
<testsuite name="Demo Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,72 @@ | ||
<?php | ||
|
||
namespace IbanGenerator; | ||
|
||
/** | ||
* Class Iban | ||
* | ||
* Description | ||
* | ||
* @link | ||
*/ | ||
class Iban | ||
{ | ||
/** | ||
* Iban validation. | ||
* | ||
* @param string $paisCode | ||
* @param mixed $control | ||
* | ||
* @return bool | ||
*/ | ||
public function generate($countryCode, $ccc) | ||
{ | ||
|
||
$number = $ccc | ||
. $this->code(substr($countryCode, 0, 1)) | ||
. $this->code(substr($countryCode, 1, 1)) | ||
. '00'; | ||
|
||
$checksum = 98 - bcmod($number, '97'); | ||
|
||
if (strlen($checksum) === 1) { | ||
$checksum = '0' . $checksum; | ||
} | ||
|
||
return $countryCode . $checksum; | ||
} | ||
|
||
private function code($letter) | ||
{ | ||
$tabla = [ | ||
'A' => '10', | ||
'B' => '11', | ||
'C' => '12', | ||
'D' => '13', | ||
'E' => '14', | ||
'F' => '15', | ||
'G' => '16', | ||
'H' => '17', | ||
'I' => '18', | ||
'J' => '19', | ||
'K' => '20', | ||
'L' => '21', | ||
'M' => '22', | ||
'N' => '23', | ||
'O' => '24', | ||
'P' => '25', | ||
'Q' => '26', | ||
'R' => '27', | ||
'S' => '28', | ||
'T' => '29', | ||
'U' => '30', | ||
'V' => '31', | ||
'W' => '32', | ||
'X' => '33', | ||
'Y' => '34', | ||
'Z' => '35' | ||
]; | ||
|
||
return $tabla[$letter]; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
use IbanGenerator\Iban; | ||
|
||
/** | ||
* Ccc validator test. | ||
* | ||
* @link | ||
* | ||
* Pattern: | ||
* EEEE OOOO DC CCCCCCCCCC | ||
*/ | ||
class IbanTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testCorrectCcc() | ||
{ | ||
$entidad = '0000'; | ||
$oficina = '0000'; | ||
$cuenta = '0000000000'; | ||
$dc = '00'; | ||
|
||
$ibanGenerator = new Iban(); | ||
|
||
$code = $ibanGenerator->generate('ES', $entidad . $oficina . $dc . $cuenta); | ||
$this->assertEquals($code, 'ES82'); | ||
} | ||
} |