diff --git a/src/TaxTotal.php b/src/TaxTotal.php index 4f6d1ab..3abf236 100644 --- a/src/TaxTotal.php +++ b/src/TaxTotal.php @@ -4,8 +4,9 @@ use InvalidArgumentException; -use function Sabre\Xml\Deserializer\keyValue; +use function Sabre\Xml\Deserializer\mixedContent; +use Doctrine\Common\Collections\ArrayCollection; use Sabre\Xml\Reader; use Sabre\Xml\Writer; use Sabre\Xml\XmlDeserializable; @@ -101,23 +102,19 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) { - $keyValues = keyValue($reader); + $mixedContent = mixedContent($reader); + $collection = new ArrayCollection($mixedContent); - $taxSubTotals = array_values( - array_filter( - $keyValues, - fn ($value, $key) => $key === Schema::CAC . 'TaxSubtotal', ARRAY_FILTER_USE_BOTH - ) - ); + $taxAmount = ReaderHelper::getTag(Schema::CBC . 'TaxAmount', $collection); + $taxSubTotals = ReaderHelper::getArrayValue(Schema::CAC . 'TaxSubtotal', $collection); return (new static()) - ->setTaxAmount(isset($keyValues[Schema::CBC.'TaxAmount']) ? floatval($keyValues[Schema::CBC.'TaxAmount']) : null) + ->setTaxAmount(isset($taxAmount) ? floatval($taxAmount['value']) : null) ->setTaxSubTotals($taxSubTotals); - ; } } diff --git a/tests/Read/TaxTotalTest.php b/tests/Read/TaxTotalTest.php index 34d0807..1e1fb79 100644 --- a/tests/Read/TaxTotalTest.php +++ b/tests/Read/TaxTotalTest.php @@ -111,11 +111,13 @@ public function testSingleTaxTotalDeserializes() $this->assertInstanceOf(TaxTotal::class, $taxTotal); + $this->assertEquals(20.79, $taxTotal->getTaxAmount()); + $taxSubtotals = $taxTotal->getTaxSubTotals(); $this->assertCount(1, $taxSubtotals); - $firstSubtotal = $taxSubtotals[0]; + $firstSubtotal = reset($taxSubtotals); $this->assertInstanceOf(TaxSubTotal::class, $firstSubtotal);