Files
myep-team/src/BusProNet/Model/BaseResponse.php
T
2023-07-08 16:21:05 +02:00

41 lines
1.1 KiB
PHP

<?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;
}
}