code = $code; $this->message = $message; } public function getCode(): ?int { return $this->code; } public function getMessage(): ?string { return $this->message; } public function isSuccessful(): bool { // Successful responses don't carry codes and messages if (null === $this->getCode() && null === $this->getMessage()) { return true; } // These weird and contradictory looking assertions are required because // of the stupid API implementation that doesn't distinguish between error // and success responses. $responseIsError = 100 <= $this->getCode() || $this->getMessage() === 'Daten konnten nicht gesendet werden.'; $responseIsSuccess = 650 === $this->getCode() && false === stripos($this->getMessage(), 'fehler'); return false === $responseIsError && true === $responseIsSuccess; } }