GenerocEncoder.java

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; } }
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.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.