Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit ddccd5e

Browse files
committed
Refactor to fluent interface
1 parent db10779 commit ddccd5e

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

src/LooplineSystems/CloseIoApiWrapper/Api/LeadStatusApi.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public function addStatus(LeadStatus $status)
4747
*/
4848
public function updateStatus(LeadStatus $status)
4949
{
50-
if ($status->getStatusId() == null) {
50+
if ($status->getId() == null) {
5151
throw new InvalidParamException('When updating a status you must provide the statuses ID');
5252
}
5353

54-
$id = $status->getStatusId();
55-
$status->setStatusId(null);
54+
$id = $status->getId();
55+
$status->setId(null);
5656

5757
$status = json_encode($status);
5858
$apiRequest = $this->prepareRequest('update-status', $status, ['id' => $id]);
@@ -68,7 +68,7 @@ public function updateStatus(LeadStatus $status)
6868
}
6969

7070
/**
71-
* @return \LooplineSystems\CloseIoApiWrapper\Model\LeadStatus[]
71+
* @return LeadStatus[]
7272
*/
7373
public function getAllStatus()
7474
{
@@ -82,7 +82,6 @@ public function getAllStatus()
8282

8383
if ($result->getReturnCode() == 200) {
8484
$rawData = $result->getData()[CloseIoResponse::GET_ALL_RESPONSE_LEADS_KEY];
85-
8685
foreach ($rawData as $status) {
8786
$statuses[] = new LeadStatus($status);
8887
}

src/LooplineSystems/CloseIoApiWrapper/Model/LeadStatus.php

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,83 @@ class LeadStatus implements \JsonSerializable
1111
use ObjectHydrateHelperTrait;
1212
use JsonSerializableHelperTrait;
1313

14+
/**
15+
* @var string
16+
*/
1417
private $label;
1518

19+
/**
20+
* @var string
21+
*/
1622
private $id;
1723

18-
public function __construct(array $fields)
24+
/**
25+
* @var string
26+
*/
27+
private $organizationId;
28+
29+
/**
30+
* LeadStatus constructor.
31+
* @param array $data
32+
*/
33+
public function __construct(array $data)
1934
{
20-
foreach($fields as $field=>$value)
21-
{
22-
if (property_exists($this, $field)) {
23-
$this->$field = $value;
24-
}
35+
if ($data) {
36+
$this->hydrate($data);
2537
}
2638
}
2739

2840
/**
2941
* @param $label
42+
* @return LeadStatus
3043
*/
31-
public function setStatusLabel($label)
44+
public function setLabel($label)
3245
{
3346
$this->label = $label;
47+
return $this;
3448
}
3549

36-
public function getStatusLabel()
50+
/**
51+
* @return string
52+
*/
53+
public function getLabel()
3754
{
3855
return $this->label;
3956
}
4057

41-
public function setStatusId($id)
58+
/**
59+
* @param $id
60+
* @return LeadStatus
61+
*/
62+
public function setId($id)
4263
{
4364
$this->id = $id;
65+
return $this;
4466
}
4567

46-
public function getStatusId()
68+
/**
69+
* @return string
70+
*/
71+
public function getId()
4772
{
4873
return $this->id;
4974
}
75+
76+
/**
77+
* @param string $organizationId
78+
* @return LeadStatus
79+
*/
80+
public function setOrganizationId($organizationId)
81+
{
82+
$this->organizationId = $organizationId;
83+
return $this;
84+
}
85+
86+
/**
87+
* @return string
88+
*/
89+
public function getOrganizationId()
90+
{
91+
return $this->organizationId;
92+
}
5093
}

0 commit comments

Comments
 (0)