Skip to content

Commit

Permalink
allow nullable response init
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Apr 5, 2024
1 parent d7d6083 commit c38cdc8
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions src/Client/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,43 @@ class Response
private ?string $_meta = null;
private ?string $_body = null;

public function __construct(string $data)
public function __construct(?string $data = null)
{
$match = [];
if ($data)
{
$match = [];

preg_match(
'/(?<status>\d{2})\s(?<meta>.*)\r\n(?<body>.*)/su',
$data,
$match
);
preg_match(
'/(?<status>\d{2})\s(?<meta>.*)\r\n(?<body>.*)/su',
$data,
$match
);

if (isset($match['code']))
{
$code = (int) $match['code'];
if (isset($match['code']))
{
$code = (int) $match['code'];

if ($code >= 10 && $code <= 69)
if ($code >= 10 && $code <= 69)
{
$this->setCode(
$code
);
}
}

if (isset($match['meta']) && mb_strlen($match['meta']) <= 1024)
{
$this->setCode(
$code
$this->setMeta(
(string) $match['meta']
);
}
}

if (isset($match['meta']) && mb_strlen($match['meta']) <= 1024)
{
$this->setMeta(
(string) $match['meta']
);
}

if (isset($match['body']))
{
$this->setBody(
(string) (string) $match['body']
);
if (isset($match['body']))
{
$this->setBody(
(string) (string) $match['body']
);
}
}
}

Expand Down

0 comments on commit c38cdc8

Please sign in to comment.