for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace RichToms\LaravelJsend\Responses;
use JsonSerializable;
class Response implements JsonSerializable
{
/**
* @var int
*/
protected $statusCode = 200;
* @var array|null
protected $data = false;
* @var string
protected $statusText = 'success';
* @param int $statusCode
* @return $this
public function withStatusCode($statusCode)
$this->statusCode = $statusCode;
return $this;
}
* @param mixed $data
public function withData($data)
$this->data = $this->toJSendData($data);
* @return bool
public function hasData()
return $this->data !== false;
* @return int
public function getStatusCode()
return $this->statusCode;
* @return string
public function getStatusText()
return $this->statusText;
* @return array
protected function getResponseData()
return $this->data;
public function toArray()
$response = [
'status' => $this->getStatusText(),
];
if ($this->hasData()) {
$response['data'] = $this->getResponseData();
return $response;
public function jsonSerialize()
return $this->toArray();
* @return mixed
public function toJSendData($data)
return $data;