code = $code; return $this; } /** * @param mixed $message * @return $this */ public function setMessage( $message ): OutputSchemaForResponseHelper { $this->message = $message; return $this; } /** * @param mixed $data * @return $this */ public function setData( $data = null ): OutputSchemaForResponseHelper { $this->data = $data; return $this; } /** * @return array */ public function toArray(): array { if ( ! $this->code ) { throw new \InvalidArgumentException( 'The "code" must be provided.' ); } if ( \is_null( $this->message ) ) { throw new \InvalidArgumentException( 'The "message" must be provided.' ); } $code = $this->code; $message = $this->message; $data = $this->data; unset( $this->code, $this->message, $this->data ); $output = [ self::CODE => $code, self::MESSAGE => $message, self::DATA => $data, ]; return \array_filter( $output ); } /** * @param int|string $code * @param mixed $message * @param mixed $data * @return array */ public function __invoke( $code, $message, $data = null ): array { $this->setCode($code); $this->setMessage($message); $this->setData($data); return $this->toArray(); } }