Skip to content

Commit

Permalink
Merge pull request #272 from sprain/code-improvements
Browse files Browse the repository at this point in the history
Minor code improvements
  • Loading branch information
sprain authored Dec 7, 2024
2 parents 5881f1c + 63ea4dd commit bf317d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/PaymentPart/Output/AbstractOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getLanguage(): ?string
}

/**
* @deprecated Will be removed in next major release. Use setDisplayOptions() instead.
* @deprecated Will be removed in v5. Use setDisplayOptions() instead.
*/
public function setPrintable(bool $printable): static
{
Expand All @@ -42,7 +42,7 @@ public function setPrintable(bool $printable): static
}

/**
* @deprecated Will be removed in next major release. Use getDisplayOptions() instead.
* @deprecated Will be removed in v5. Use getDisplayOptions() instead.
*/
public function isPrintable(): bool
{
Expand Down
25 changes: 18 additions & 7 deletions src/Reference/QrPaymentReferenceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,45 @@ final class QrPaymentReferenceGenerator implements SelfValidatableInterface
{
use SelfValidatableTrait;

private ?string $customerIdentificationNumber = null;
private string $referenceNumber;

public static function generate(?string $customerIdentificationNumber, string $referenceNumber): string
{
$qrPaymentReferenceGenerator = new self($customerIdentificationNumber, $referenceNumber);

return $qrPaymentReferenceGenerator->doGenerate();
}

public function __construct(?string $customerIdentificationNumber, string $referenceNumber)
{
/**
* @internal Will be made private in v5. Use QrPaymentReferenceGenerator::generate() instead.
*/
public function __construct(
private ?string $customerIdentificationNumber,
private string $referenceNumber
) {
if (null !== $customerIdentificationNumber) {
$this->customerIdentificationNumber = StringModifier::stripWhitespace($customerIdentificationNumber);
}
$this->referenceNumber = StringModifier::stripWhitespace($referenceNumber);
}

/**
* @deprecated Will be removed in v5.
*/
public function getCustomerIdentificationNumber(): ?string
{
return $this->customerIdentificationNumber;
}

public function getReferenceNumber(): ?string
/**
* @deprecated Will be removed in v5.
*/
public function getReferenceNumber(): string
{
return $this->referenceNumber;
}

/**
* @internal Will be made private in v5. Use QrPaymentReferenceGenerator::generate() instead.
*/
public function doGenerate(): string
{
if (!$this->isValid()) {
Expand All @@ -53,7 +64,7 @@ public function doGenerate(): string
$completeReferenceNumber = $this->getCustomerIdentificationNumber();

$strlen = $completeReferenceNumber ? strlen($completeReferenceNumber) : 0;
$completeReferenceNumber .= str_pad((string) $this->getReferenceNumber(), 26 - $strlen, '0', STR_PAD_LEFT);
$completeReferenceNumber .= str_pad($this->getReferenceNumber(), 26 - $strlen, '0', STR_PAD_LEFT);
$completeReferenceNumber .= $this->modulo10($completeReferenceNumber);

return $completeReferenceNumber;
Expand Down
7 changes: 4 additions & 3 deletions src/Reference/RfCreditorReferenceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ final class RfCreditorReferenceGenerator implements SelfValidatableInterface
{
use SelfValidatableTrait;

private string $reference;

public static function generate(string $reference): string
{
$generator = new self($reference);

return $generator->doGenerate();
}

public function __construct(string $reference)
/**
* @internal Will be made private in v5. Use RfCreditorReferenceGenerator::generate() instead.
*/
public function __construct(private string $reference)
{
$this->reference = StringModifier::stripWhitespace($reference);
}
Expand Down

0 comments on commit bf317d5

Please sign in to comment.