assertIsInput($value); /** @var \App\Lib\Discount $value */ return $value->toJson(); } /** * Assert is instance of \App\Lib\Discount * * @param mixed $value * @return void * @throws \RuntimeException If the value is not an input. */ private function assertIsInput(mixed $value): void { if (!\is_object($value) or !($value instanceof Discount)) { $value = \json_encode($value); throw new \RuntimeException( __CLASS__ . ' needs value to be array of \'' . Discount::class . "' given is {$value}" ); } } }