wc_coupon_id = $wc_coupon_id; $this->target_country = $target_country; $this->google_promotion_id = $google_promotion_id; $this->errors = $errors; } /** * * @return int */ public function get_wc_coupon_id(): int { return $this->wc_coupon_id; } /** * * @return string|null */ public function get_google_promotion_id(): ?string { return $this->google_promotion_id; } /** * * @return string|null */ public function get_target_country(): ?string { return $this->target_country; } /** * * @return string[] */ public function get_errors(): array { return $this->errors; } /** * * @param int $error_code * * @return bool */ public function has_error( int $error_code ): bool { return ! empty( $this->errors[ $error_code ] ); } /** * * @param ConstraintViolationListInterface $violations * * @return InvalidCouponEntry */ public function map_validation_violations( ConstraintViolationListInterface $violations ): InvalidCouponEntry { $validation_errors = []; foreach ( $violations as $violation ) { array_push( $validation_errors, sprintf( '[%s] %s', $violation->getPropertyPath(), $violation->getMessage() ) ); } $this->errors = $validation_errors; return $this; } /** * * @return array */ public function jsonSerialize(): array { $data = [ 'woocommerce_id' => $this->get_wc_coupon_id(), 'errors' => $this->get_errors(), ]; if ( null !== $this->get_google_promotion_id() ) { $data['google_id'] = $this->get_google_promotion_id(); } if ( null !== $this->get_target_country() ) { $data['google_target_country'] = $this->get_target_country(); } return $data; } }