Skip to content

Commit

Permalink
Added deprecation warnings
Browse files Browse the repository at this point in the history
- Updated Invoice class
- Updated Payment class
- Updated UblReader and UblWriter
  • Loading branch information
josemmo committed Sep 22, 2024
1 parent 26437c2 commit 3e05ecd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
use Einvoicing\Traits\PrecedingInvoiceReferencesTrait;
use InvalidArgumentException;
use OutOfBoundsException;
use const E_USER_DEPRECATED;
use function array_splice;
use function count;
use function trigger_error;
use function is_subclass_of;
use function round;

Expand Down Expand Up @@ -566,6 +568,7 @@ public function clearNotes(): self {
* @see Invoice::getNotes()
*/
public function getNote(): ?string {
trigger_error('Invoice::getNote() is deprecated and will be removed in the next version of josemmo/einvoicing', E_USER_DEPRECATED);
return $this->notes[0] ?? null;
}

Expand All @@ -578,6 +581,7 @@ public function getNote(): ?string {
* @see Invoice::addNote()
*/
public function setNote(?string $note): self {
trigger_error('Invoice::setNote() is deprecated and will be removed in the next version of josemmo/einvoicing', E_USER_DEPRECATED);
$this->notes = ($note === null) ? [] : [$note];
return $this;
}
Expand Down Expand Up @@ -890,11 +894,15 @@ public function clearPayments(): self {

/**
* Get payment information
* @return Payment|null Payment instance
* @param boolean $internal Whether call comes from the library itself
* @return Payment|null Payment instance
* @deprecated 0.2.8
* @see Invoice::getPayments()
*/
public function getPayment(): ?Payment {
public function getPayment(bool $internal = false): ?Payment {
if (!$internal) {
trigger_error('Invoice::getPayment() is deprecated and will be removed in the next version of josemmo/einvoicing', E_USER_DEPRECATED);
}
return $this->payments[0] ?? null;
}

Expand All @@ -907,6 +915,7 @@ public function getPayment(): ?Payment {
* @see Invoice::addPayment()
*/
public function setPayment(?Payment $payment): self {
trigger_error('Invoice::setPayment() is deprecated and will be removed in the next version of josemmo/einvoicing', E_USER_DEPRECATED);
$this->payments = ($payment === null) ? [] : [$payment];
return $this;
}
Expand Down
20 changes: 15 additions & 5 deletions src/Payments/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
namespace Einvoicing\Payments;

use OutOfBoundsException;
use const E_USER_DEPRECATED;
use function array_splice;
use function count;
use function trigger_error;

class Payment {
protected $id = null;
Expand Down Expand Up @@ -76,23 +78,31 @@ public function setMeansText(?string $meansText): self {

/**
* Get payment terms
* @return string|null Payment terms
* @param boolean $internal Whether call comes from the library itself
* @return string|null Payment terms
* @deprecated 0.2.8
* @see Invoice::getPaymentTerms()
*/
public function getTerms(): ?string {
public function getTerms(bool $internal = false): ?string {
if (!$internal) {
trigger_error('Payment::getTerms() is deprecated and will be removed in the next version of josemmo/einvoicing', E_USER_DEPRECATED);
}
return $this->terms;
}


/**
* Set payment terms
* @param string|null $terms Payment terms
* @return self Payment instance
* @param string|null $terms Payment terms
* @param boolean $internal Whether call comes from the library itself
* @return self Payment instance
* @deprecated 0.2.8
* @see Invoice::setPaymentTerms()
*/
public function setTerms(?string $terms): self {
public function setTerms(?string $terms, bool $internal = false): self {
if (!$internal) {
trigger_error('Payment::setTerms() is deprecated and will be removed in the next version of josemmo/einvoicing', E_USER_DEPRECATED);
}
$this->terms = $terms;
return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Readers/UblReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ public function import(string $document): Invoice {
$termsNode = $xml->get("{{$cac}}PaymentTerms/{{$cbc}}Note");
if ($termsNode !== null) {
$invoice->setPaymentTerms($termsNode->asText());
$firstPayment = $invoice->getPayment(); // @phan-suppress-current-line PhanDeprecatedFunction
$firstPayment = $invoice->getPayment(true); // @phan-suppress-current-line PhanDeprecatedFunction
if ($firstPayment !== null) {
$firstPayment->setTerms($termsNode->asText()); // @phan-suppress-current-line PhanDeprecatedFunction
$firstPayment->setTerms($termsNode->asText(), true); // @phan-suppress-current-line PhanDeprecatedFunction
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Writers/UblWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public function export(Invoice $invoice): string {
}

// BT-20: Payment terms
$firstPayment = $invoice->getPayment(); // @phan-suppress-current-line PhanDeprecatedFunction
$paymentTerms = $invoice->getPaymentTerms() ?? ($firstPayment === null ? null : $firstPayment->getTerms()); // @phan-suppress-current-line PhanDeprecatedFunction
$firstPayment = $invoice->getPayment(true); // @phan-suppress-current-line PhanDeprecatedFunction
$paymentTerms = $invoice->getPaymentTerms() ?? ($firstPayment === null ? null : $firstPayment->getTerms(true)); // @phan-suppress-current-line PhanDeprecatedFunction
if ($paymentTerms !== null) {
$xml->add('cac:PaymentTerms')->add('cbc:Note', $paymentTerms);
}
Expand Down

0 comments on commit 3e05ecd

Please sign in to comment.