Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/TaxTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
;
}
}
4 changes: 3 additions & 1 deletion tests/Read/TaxTotalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down