-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #15616 [API] Finish covering taxation scenarios (NoResponseMate)
This PR was merged into the 1.13 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.13 | | Bug fix? | kinda | | New feature? | no | | BC breaks? | no | | Deprecations? | no | | Related tickets | - | | License | MIT | Commits ------- [API] Finish covering taxation scenarios [API][TaxRate] Treat missing/null amount as default
- Loading branch information
Showing
10 changed files
with
250 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Sylius/Bundle/ApiBundle/Serializer/TaxRateDenormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ApiBundle\Serializer; | ||
|
||
use Sylius\Component\Core\Model\TaxRateInterface; | ||
use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; | ||
|
||
/** @experimental */ | ||
final class TaxRateDenormalizer implements ContextAwareDenormalizerInterface, DenormalizerAwareInterface | ||
{ | ||
use DenormalizerAwareTrait; | ||
|
||
private const ALREADY_CALLED = 'sylius_tax_rate_denormalizer_already_called'; | ||
|
||
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool | ||
{ | ||
return | ||
!isset($context[self::ALREADY_CALLED]) && | ||
is_array($data) && | ||
is_a($type, TaxRateInterface::class, true) | ||
; | ||
} | ||
|
||
public function denormalize(mixed $data, string $type, string $format = null, array $context = []) | ||
{ | ||
$context[self::ALREADY_CALLED] = true; | ||
$data = (array) $data; | ||
|
||
if (null === ($data['amount'] ?? null)) { | ||
unset($data['amount']); | ||
} | ||
|
||
return $this->denormalizer->denormalize($data, $type, $format, $context); | ||
} | ||
} |
Oops, something went wrong.