Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Oct 29, 2024
1 parent 4775d99 commit cfcccb2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/EInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,30 @@ public function encode(mixed $object, string $type): string

$object = $serializer->normalize($object, null, [\Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);

$object = $this->removeEmptyValues($object);

$data = $serializer->encode($object, $type, $context);

return $type == 'xml' ? $this->decorateXml($data) : $data;

}

private function removeEmptyValues(array $array): array
{
foreach ($array as $key => $value) {
if (is_array($value)) {
$array[$key] = $this->removeEmptyValues($value);
if (empty($array[$key])) {
unset($array[$key]);
}
} elseif ($value === null || $value === '') {
unset($array[$key]);
}
}

return $array;
}

/**
* DecorateXml
*
Expand Down
7 changes: 2 additions & 5 deletions src/Models/Peppol/AllowanceCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ class AllowanceCharge
#[SerializedName('cbc:ID')]
public $ID;

/** @var bool */
#[NotNull]
#[NotBlank]
#[Valid]
/** @var string */
#[SerializedName('cbc:ChargeIndicator')]
public bool $ChargeIndicator;
public string $ChargeIndicator;

/** @var AllowanceChargeReasonCode */
#[SerializedName('cbc:AllowanceChargeReasonCode')]
Expand Down

0 comments on commit cfcccb2

Please sign in to comment.