Skip to content

Commit

Permalink
Allow strings as symbols, fixes #40 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Nov 22, 2021
1 parent e8f7fc7 commit ad759f1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions phpstan.neon.dist
@@ -1,5 +1,6 @@
parameters:
reportUnmatchedIgnoredErrors: false
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '#expects callable.*?, array.*? given#'
- '#Attribute class JetBrains.+? does not exist#'
52 changes: 43 additions & 9 deletions src/QrPayment.php
Expand Up @@ -16,23 +16,24 @@
use Rikudou\QrPaymentQrCodeProvider\EndroidQrCode3;
use Rikudou\QrPaymentQrCodeProvider\Exception\NoProviderFoundException;
use Rikudou\QrPaymentQrCodeProvider\GetQrCodeTrait;
use TypeError;

final class QrPayment implements QrPaymentInterface
{
use GetQrCodeTrait;

/**
* @var int|null
* @var int|string|null
*/
private $variableSymbol = null;

/**
* @var int|null
* @var int|string|null
*/
private $specificSymbol = null;

/**
* @var int|null
* @var int|string|null
*/
private $constantSymbol = null;

Expand Down Expand Up @@ -181,37 +182,70 @@ public static function fromAccountAndBankCode(string $accountNumber, string $ban
return new self(new CzechIbanAdapter($accountNumber, $bankCode));
}

public function getVariableSymbol(): ?int
/**
* @return int|string|null
*/
public function getVariableSymbol()
{
return $this->variableSymbol;
}

public function setVariableSymbol(?int $variableSymbol): self
/**
* @param int|string|null $variableSymbol
*
* @return $this
*/
public function setVariableSymbol($variableSymbol): self
{
if (!is_string($variableSymbol) && !is_int($variableSymbol) && $variableSymbol !== null) {
throw new TypeError(sprintf('Variable symbol must be an integer, string or null, %s given', gettype($variableSymbol)));
}
$this->variableSymbol = $variableSymbol;

return $this;
}

public function getSpecificSymbol(): ?int
/**
* @return int|string|null
*/
public function getSpecificSymbol()
{
return $this->specificSymbol;
}

public function setSpecificSymbol(?int $specificSymbol): self
/**
* @param int|string|null $specificSymbol
*
* @return $this
*/
public function setSpecificSymbol($specificSymbol): self
{
if (!is_string($specificSymbol) && !is_int($specificSymbol) && $specificSymbol !== null) {
throw new TypeError(sprintf('Specific symbol must be an integer, string or null, %s given', gettype($specificSymbol)));
}
$this->specificSymbol = $specificSymbol;

return $this;
}

public function getConstantSymbol(): ?int
/**
* @return int|string|null
*/
public function getConstantSymbol()
{
return $this->constantSymbol;
}

public function setConstantSymbol(?int $constantSymbol): self
/**
* @param int|string|null $constantSymbol
*
* @return $this
*/
public function setConstantSymbol($constantSymbol): self
{
if (!is_string($constantSymbol) && !is_int($constantSymbol) && $constantSymbol !== null) {
throw new TypeError(sprintf('Constant symbol must be an integer, string or null, %s given', gettype($constantSymbol)));
}
$this->constantSymbol = $constantSymbol;

return $this;
Expand Down
22 changes: 22 additions & 0 deletions tests/QrPaymentTest.php
Expand Up @@ -19,6 +19,7 @@
use Rikudou\QrPaymentQrCodeProvider\EndroidQrCode4Provider;
use Rikudou\QrPaymentQrCodeProvider\Exception\NoProviderFoundException;
use Rikudou\QrPaymentQrCodeProvider\QrCodeProviderLocator;
use TypeError;

final class QrPaymentTest extends TestCase
{
Expand Down Expand Up @@ -122,6 +123,13 @@ public function testVariableSymbol()

$this->instance->setVariableSymbol(null);
self::assertEquals($this->getDefaultEmptyString(), $this->instance->getQrString());

$this->instance->setVariableSymbol('789');
self::assertEquals('789', $this->instance->getVariableSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-VS:789", $this->instance->getQrString());

$this->expectException(TypeError::class);
$this->instance->setVariableSymbol([]);
}

public function testSpecificSymbol()
Expand All @@ -132,6 +140,13 @@ public function testSpecificSymbol()

$this->instance->setSpecificSymbol(null);
self::assertEquals($this->getDefaultEmptyString(), $this->instance->getQrString());

$this->instance->setSpecificSymbol('7890');
self::assertEquals('7890', $this->instance->getSpecificSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-SS:7890", $this->instance->getQrString());

$this->expectException(TypeError::class);
$this->instance->setSpecificSymbol([]);
}

public function testConstantSymbol()
Expand All @@ -142,6 +157,13 @@ public function testConstantSymbol()

$this->instance->setConstantSymbol(null);
self::assertEquals($this->getDefaultEmptyString(), $this->instance->getQrString());

$this->instance->setConstantSymbol('741');
self::assertEquals('741', $this->instance->getConstantSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-KS:741", $this->instance->getQrString());

$this->expectException(TypeError::class);
$this->instance->setConstantSymbol([]);
}

public function testCurrency()
Expand Down

0 comments on commit ad759f1

Please sign in to comment.