Skip to content

Commit

Permalink
Update code style and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
z38 committed Jan 5, 2020
1 parent 00dbcdd commit e54f886
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 3 additions & 7 deletions src/Z38/SwissPayment/IID.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ public function __construct($iid)
*
* @param IBAN $iban
*
* @throws \InvalidArgumentException When the supplied IBAN is not from Switzerland
* @throws \InvalidArgumentException When the supplied IBAN is not from a supported country.
*/
public static function fromIBAN(IBAN $iban)
{
$supportedCountries = ['CH', 'LI'];

if (!in_array($iban->getCountry(), $supportedCountries)) {
throw new InvalidArgumentException(
'IID can only be extracted from IBANs of these countries: ' . implode(', ', $supportedCountries)
);
if (!in_array($iban->getCountry(), ['CH', 'LI'])) {
throw new InvalidArgumentException('IID can only be extracted from Swiss and Lichtenstein IBANs.');
}

return new self(substr($iban->normalize(), 4, 5));
Expand Down
16 changes: 11 additions & 5 deletions tests/Z38/SwissPayment/Tests/IIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,21 @@ public function testFormat()
}

/**
* @dataProvider fromIBANSamples
* @covers ::fromIBAN
*/
public function testFromIBAN()
public function testFromIBAN($iban, $iid)
{
$instance = IID::fromIBAN(new IBAN('CH31 8123 9000 0012 4568 9'));
$this->assertSame('81239', $instance->format());
$instance = IID::fromIBAN(new IBAN($iban));
$this->assertSame($iid, $instance->format());
}

$instance = IID::fromIBAN(new IBAN('LI21 0881 0000 2324 013A A'));
$this->assertSame('08810', $instance->format());
public function fromIBANSamples()
{
return [
['CH31 8123 9000 0012 4568 9', '81239'],
['LI21 0881 0000 2324 013A A', '08810'],
];
}

/**
Expand Down

0 comments on commit e54f886

Please sign in to comment.