1
0
mirror of synced 2024-11-22 03:46:02 +03:00

Remove duplicated code from ListResponse

This commit is contained in:
Pavel 2019-06-24 12:18:39 +03:00
parent 70d9d31a02
commit a0f7b65275

View File

@ -28,26 +28,18 @@ use RetailCrm\Common\Serializer;
*/
class ListResponse implements \Iterator, \ArrayAccess, \Countable
{
use CommonFields;
/**
* @var array
*/
private $items = [];
/**
* @var array
*/
private $errors = [];
/**
* @var int
*/
private $position = 0;
/**
* @var int $statusCode
*/
private $statusCode;
/**
* ListResponse constructor.
*
@ -57,10 +49,10 @@ class ListResponse implements \Iterator, \ArrayAccess, \Countable
*/
public function __construct($responseType, $data, $statusCode)
{
$this->statusCode = $statusCode;
$this->setStatusCode($statusCode);
if (isset($data['errors'])) {
$this->errors = $data['errors'];
$this->setErrors($data['errors']);
} else {
foreach ($data as $item) {
$this->items[] =
@ -77,14 +69,6 @@ class ListResponse implements \Iterator, \ArrayAccess, \Countable
return empty($this->errors);
}
/**
* @return array
*/
public function getErrors()
{
return $this->errors;
}
/**
* \Countable implementation
*
@ -215,20 +199,4 @@ class ListResponse implements \Iterator, \ArrayAccess, \Countable
{
return isset($this->items[$this->position]);
}
/**
* @return int
*/
public function getStatusCode(): int
{
return $this->statusCode;
}
/**
* @param int $statusCode
*/
public function setStatusCode(int $statusCode): void
{
$this->statusCode = $statusCode;
}
}