diff --git a/src/Invoice.php b/src/Invoice.php index cf46f83..7684207 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/src/Payments/Payment.php b/src/Payments/Payment.php index 09d4ff1..16cc2e0 100644 --- a/src/Payments/Payment.php +++ b/src/Payments/Payment.php @@ -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; @@ -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; } diff --git a/src/Readers/UblReader.php b/src/Readers/UblReader.php index 6d70be4..ec5d7df 100644 --- a/src/Readers/UblReader.php +++ b/src/Readers/UblReader.php @@ -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 } } diff --git a/src/Writers/UblWriter.php b/src/Writers/UblWriter.php index e22c79a..1d45923 100644 --- a/src/Writers/UblWriter.php +++ b/src/Writers/UblWriter.php @@ -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); }