for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace LibraryCatalog\Transformer\Encoder;
class Json implements EncoderInterface
{
/**
* @param mixed $data
* @throws Exception
* @return string
*/
public function encode($data): string
$res = json_encode($data);
if ($res === false) {
throw new Exception('Can not encode JSON');
}
return $res;
* @param string $value
* @return mixed
public function decode(string $value)
$res = json_decode($value, true);
if ($res === null) {
throw new Exception('Can not decode JSON');