Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CustomFieldsBase64EncoderJson | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| encode | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| decode | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Satag\AmicronEntityBundle\Util\CustomFields; |
| 6 | |
| 7 | class CustomFieldsBase64EncoderJson extends AbstractCustomFieldsEncoder |
| 8 | { |
| 9 | /** |
| 10 | * @throws \JsonException |
| 11 | */ |
| 12 | public function encode(string $originalString, array $dataToEmbed): string |
| 13 | { |
| 14 | $jsonstring = json_encode($dataToEmbed, \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR); |
| 15 | |
| 16 | return $this->upsertBlock($jsonstring, $originalString); |
| 17 | } |
| 18 | |
| 19 | public function decode(string $rawString): array |
| 20 | { |
| 21 | $rawString = (string) \base64_decode($rawString, true); |
| 22 | $codeblock = $this->getBlock($rawString); |
| 23 | $return = \json_decode($codeblock, true, 512, \JSON_THROW_ON_ERROR); |
| 24 | |
| 25 | return \is_array($return) ? $return : []; |
| 26 | } |
| 27 | |
| 28 | public function getType(): string |
| 29 | { |
| 30 | return 'json'; |
| 31 | } |
| 32 | } |