Created
June 15, 2019 20:58
-
-
Save luisenriquecorona/b39ad357c23a1cd93e10895b0410acc4 to your computer and use it in GitHub Desktop.
We have put some effort into implementing a nice abstract factory for encoders, but the GenericEncoder class still has this ugly switch statement for preparing the data before it is encoded.
This file contains hidden or 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
| class GenericEncoder | |
| { | |
| private function prepareData($data, string $format) | |
| { | |
| switch ($format) { | |
| case 'json': | |
| $data = $this->forceArray($data); | |
| $data = $this->fixKeys($data); | |
| // fall through | |
| case 'xml': | |
| $data = $this->fixAttributes($data); | |
| break; | |
| default: | |
| throw new InvalidArgumentException( | |
| 'Format not supported' | |
| ); | |
| } | |
| return $data; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment