Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CustomFieldsEncoderYaml | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| encode | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| decode | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Satag\AmicronEntityBundle\Util\CustomFields; |
| 4 | |
| 5 | use Symfony\Component\Yaml\Exception\ParseException; |
| 6 | use Symfony\Component\Yaml\Yaml; |
| 7 | |
| 8 | class CustomFieldsEncoderYaml extends AbstractCustomFieldsEncoder |
| 9 | { |
| 10 | public function encode(string $originalString, array $dataToEmbed): string |
| 11 | { |
| 12 | $yamlstring = Yaml::dump($dataToEmbed, 3); |
| 13 | |
| 14 | return $this->upsertBlock($yamlstring, $originalString); |
| 15 | } |
| 16 | |
| 17 | public function decode(string $rawString): array |
| 18 | { |
| 19 | $codeblock = $this->getBlock($rawString); |
| 20 | $data = []; |
| 21 | |
| 22 | try { |
| 23 | $yaml = Yaml::parse($codeblock); |
| 24 | if (\is_array($yaml)) { |
| 25 | $data = $yaml; |
| 26 | } |
| 27 | } catch (ParseException) { |
| 28 | } |
| 29 | |
| 30 | return $data; |
| 31 | } |
| 32 | |
| 33 | public function getType(): string |
| 34 | { |
| 35 | return 'yaml'; |
| 36 | } |
| 37 | } |