Skip to content

Commit

Permalink
Merge pull request #17 from RikudouSage/feature/rename-get-iban
Browse files Browse the repository at this point in the history
rename getIban to asString in IbanInterface
  • Loading branch information
RikudouSage committed Dec 21, 2018
2 parents c9ede5f + c96a22e commit 03a82f2
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 14 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ $payment = new QrPayment("CZ5530300000001325090010");
### getIban()

Returns instance of `IbanInterface`, you can get the string
representation of IBAN via method `getIban()` of `IbanInterface`.
representation of IBAN via method `asString()` of `IbanInterface` or by casting
the object to string.

**Returns**

Expand All @@ -144,7 +145,8 @@ use rikudou\EuQrPayment\QrPayment;

$payment = new QrPayment("CZ5530300000001325090010");
$iban = $payment->getIban(); // holds instance of rikudou\EuQrPayment\Iban\IBAN
$ibanAsString = $payment->getIban()->getIban();
$ibanAsString = $payment->getIban()->asString();
$ibanAsString = (string) $payment->getIban();

```

Expand Down
4 changes: 2 additions & 2 deletions src/Helper/ToStringIban.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ trait ToStringIban
{
public function __toString()
{
if (!method_exists($this, 'getIban')) {
if (!method_exists($this, 'asString')) {
return '';
}
try {
return $this->getIban();
return $this->asString();
} catch (\Throwable $exception) {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Iban/CzechIbanAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(string $accountNumber, string $bankCode)
*
* @return string
*/
public function getIban(): string
public function asString(): string
{
if (is_null($this->iban)) {
$part1 = ord('C') - ord('A') + 10;
Expand Down
2 changes: 1 addition & 1 deletion src/Iban/IBAN.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(string $iban)
*
* @return string
*/
public function getIban(): string
public function asString(): string
{
return $this->iban;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Iban/IbanInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface IbanInterface
*
* @return string
*/
public function getIban(): string;
public function asString(): string;

/**
* Returns the validator that checks whether the IBAN is valid.
Expand Down
2 changes: 1 addition & 1 deletion src/Iban/Validator/GenericIbanValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(IbanInterface $iban)

public function isValid(): bool
{
$stringIban = strtoupper($this->iban->getIban());
$stringIban = strtoupper($this->iban->asString());

$country = substr($stringIban, 0, 2);
$checksum = substr($stringIban, 2, 2);
Expand Down
2 changes: 1 addition & 1 deletion src/QrPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function getQrString(): string
$result[] = 'SCT'; // identification
$result[] = $this->getBic();
$result[] = $this->getBeneficiaryName();
$result[] = $this->getIban()->getIban();
$result[] = $this->getIban()->asString();
$result[] = $this->getAmount() ? $this->getCurrency() . $this->getAmount() : '';
$result[] = $this->getPurpose();
$result[] = $this->getRemittanceText();
Expand Down
4 changes: 2 additions & 2 deletions tests/CzechIbanAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testAccountsWithoutPrefix()

foreach ($accounts as $iban => $accountData) {
$iban = str_replace(" ", "", $iban);
$this->assertEquals($iban, $this->getIban($accountData["acc"], $accountData["bank"])->getIban());
$this->assertEquals($iban, $this->getIban($accountData["acc"], $accountData["bank"])->asString());
$this->assertEquals($iban, strval($this->getIban($accountData["acc"], $accountData["bank"])));
}
}
Expand All @@ -57,7 +57,7 @@ public function testAccountsWithPrefix()

foreach ($accounts as $iban => $accountData) {
$iban = str_replace(" ", "", $iban);
$this->assertEquals($iban, $this->getIban($accountData["acc"], $accountData["bank"], $accountData["prefix"])->getIban());
$this->assertEquals($iban, $this->getIban($accountData["acc"], $accountData["bank"], $accountData["prefix"])->asString());
$this->assertEquals($iban, strval($this->getIban($accountData["acc"], $accountData["bank"], $accountData["prefix"])));
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/IBANTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class IBANTest extends TestCase
public function testGetIban()
{
$iban = new IBAN($this->getIbanString());
$this->assertEquals($this->getIbanString(), $iban->getIban());
$this->assertEquals($this->getIbanString(), $iban->asString());
}

public function testToString()
Expand Down
2 changes: 1 addition & 1 deletion tests/QrPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testGetQrStringNoValidator()

use ToStringIban;

public function getIban(): string
public function asString(): string
{
return "123";
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ToStringIbanTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testValid()

use ToStringIban;

public function getIban(): string
public function asString(): string
{
return "testString";
}
Expand Down

0 comments on commit 03a82f2

Please sign in to comment.