From ddccd5ea99a94651ffa8debdd1f473c54be5f99a Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 8 Mar 2016 09:46:27 -0300 Subject: [PATCH] Refactor to fluent interface --- .../CloseIoApiWrapper/Api/LeadStatusApi.php | 9 ++- .../CloseIoApiWrapper/Model/LeadStatus.php | 63 ++++++++++++++++--- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php b/src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php index c1e1c79..e5bf9c0 100644 --- a/src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php +++ b/src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php @@ -47,12 +47,12 @@ public function addStatus(LeadStatus $status) */ public function updateStatus(LeadStatus $status) { - if ($status->getStatusId() == null) { + if ($status->getId() == null) { throw new InvalidParamException('When updating a status you must provide the statuses ID'); } - $id = $status->getStatusId(); - $status->setStatusId(null); + $id = $status->getId(); + $status->setId(null); $status = json_encode($status); $apiRequest = $this->prepareRequest('update-status', $status, ['id' => $id]); @@ -68,7 +68,7 @@ public function updateStatus(LeadStatus $status) } /** - * @return \LooplineSystems\CloseIoApiWrapper\Model\LeadStatus[] + * @return LeadStatus[] */ public function getAllStatus() { @@ -82,7 +82,6 @@ public function getAllStatus() if ($result->getReturnCode() == 200) { $rawData = $result->getData()[CloseIoResponse::GET_ALL_RESPONSE_LEADS_KEY]; - foreach ($rawData as $status) { $statuses[] = new LeadStatus($status); } diff --git a/src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php b/src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php index 078c943..3f7783b 100644 --- a/src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php +++ b/src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php @@ -11,40 +11,83 @@ class LeadStatus implements \JsonSerializable use ObjectHydrateHelperTrait; use JsonSerializableHelperTrait; + /** + * @var string + */ private $label; + /** + * @var string + */ private $id; - public function __construct(array $fields) + /** + * @var string + */ + private $organizationId; + + /** + * LeadStatus constructor. + * @param array $data + */ + public function __construct(array $data) { - foreach($fields as $field=>$value) - { - if (property_exists($this, $field)) { - $this->$field = $value; - } + if ($data) { + $this->hydrate($data); } } /** * @param $label + * @return LeadStatus */ - public function setStatusLabel($label) + public function setLabel($label) { $this->label = $label; + return $this; } - public function getStatusLabel() + /** + * @return string + */ + public function getLabel() { return $this->label; } - public function setStatusId($id) + /** + * @param $id + * @return LeadStatus + */ + public function setId($id) { $this->id = $id; + return $this; } - public function getStatusId() + /** + * @return string + */ + public function getId() { return $this->id; } + + /** + * @param string $organizationId + * @return LeadStatus + */ + public function setOrganizationId($organizationId) + { + $this->organizationId = $organizationId; + return $this; + } + + /** + * @return string + */ + public function getOrganizationId() + { + return $this->organizationId; + } }