WIP
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user