1
0
mirror of synced 2024-11-22 11:56:03 +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 class ListResponse implements \Iterator, \ArrayAccess, \Countable
{ {
use CommonFields;
/** /**
* @var array * @var array
*/ */
private $items = []; private $items = [];
/**
* @var array
*/
private $errors = [];
/** /**
* @var int * @var int
*/ */
private $position = 0; private $position = 0;
/**
* @var int $statusCode
*/
private $statusCode;
/** /**
* ListResponse constructor. * ListResponse constructor.
* *
@ -57,10 +49,10 @@ class ListResponse implements \Iterator, \ArrayAccess, \Countable
*/ */
public function __construct($responseType, $data, $statusCode) public function __construct($responseType, $data, $statusCode)
{ {
$this->statusCode = $statusCode; $this->setStatusCode($statusCode);
if (isset($data['errors'])) { if (isset($data['errors'])) {
$this->errors = $data['errors']; $this->setErrors($data['errors']);
} else { } else {
foreach ($data as $item) { foreach ($data as $item) {
$this->items[] = $this->items[] =
@ -77,14 +69,6 @@ class ListResponse implements \Iterator, \ArrayAccess, \Countable
return empty($this->errors); return empty($this->errors);
} }
/**
* @return array
*/
public function getErrors()
{
return $this->errors;
}
/** /**
* \Countable implementation * \Countable implementation
* *
@ -215,20 +199,4 @@ class ListResponse implements \Iterator, \ArrayAccess, \Countable
{ {
return isset($this->items[$this->position]); 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;
}
} }