This commit is contained in:
Björn Fromme
2023-07-08 16:21:05 +02:00
parent 305699b1ac
commit dc5b9a9238
17 changed files with 297 additions and 176 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\BusProNet\Model;
class BaseResponse
{
private ?int $code;
private ?string $message;
public function __construct(int $code = null, string $message = null)
{
$this->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;
}
}