11<?php
22/**
3- * Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
4- *
5- * @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
6- * @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
7- * @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
8- */
3+ * Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
4+ *
5+ * @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
6+ * @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
7+ * @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
8+ */
99
1010namespace LooplineSystems \CloseIoApiWrapper \Api ;
1111
1212use LooplineSystems \CloseIoApiWrapper \CloseIoResponse ;
1313use LooplineSystems \CloseIoApiWrapper \Library \Api \AbstractApi ;
14+ use LooplineSystems \CloseIoApiWrapper \Library \Curl \Curl ;
1415use LooplineSystems \CloseIoApiWrapper \Library \Exception \InvalidNewLeadPropertyException ;
1516use LooplineSystems \CloseIoApiWrapper \Library \Exception \InvalidParamException ;
16- use LooplineSystems \CloseIoApiWrapper \Model \Lead ;
1717use LooplineSystems \CloseIoApiWrapper \Library \Exception \ResourceNotFoundException ;
18+ use LooplineSystems \CloseIoApiWrapper \Model \Lead ;
1819
1920class LeadApi extends AbstractApi
2021{
@@ -30,7 +31,7 @@ protected function initUrls()
3031 'add-lead ' => '/lead/ ' ,
3132 'get-lead ' => '/lead/[:id]/ ' ,
3233 'update-lead ' => '/lead/[:id]/ ' ,
33- 'delete-lead ' => '/lead/[:id]/ '
34+ 'delete-lead ' => '/lead/[:id]/ ' ,
3435 ];
3536 }
3637
@@ -40,7 +41,7 @@ protected function initUrls()
4041 public function getAllLeads ()
4142 {
4243 /** @var Lead[] $leads */
43- $ leads = array () ;
44+ $ leads = [] ;
4445
4546 $ apiRequest = $ this ->prepareRequest ('get-leads ' );
4647
@@ -54,6 +55,7 @@ public function getAllLeads()
5455 $ leads [] = new Lead ($ lead );
5556 }
5657 }
58+
5759 return $ leads ;
5860 }
5961
@@ -65,7 +67,7 @@ public function getAllLeads()
6567 public function findLeads (array $ queryParams )
6668 {
6769 /** @var Lead[] $leads */
68- $ leads = array () ;
70+ $ leads = [] ;
6971 if (count ($ queryParams ) > 0 ) {
7072 $ queryParams = ['query ' => $ this ->buildQueryString ($ queryParams )];
7173 }
@@ -94,6 +96,7 @@ private function buildQueryString(array $params)
9496 $ flattened [] = $ key . '= ' . $ value ;
9597 }
9698 $ queryString = implode ('& ' , $ flattened );
99+
97100 return $ queryString ;
98101 }
99102
@@ -114,6 +117,7 @@ public function getLead($id)
114117 } else {
115118 throw new ResourceNotFoundException ();
116119 }
120+
117121 return $ lead ;
118122 }
119123
@@ -127,6 +131,7 @@ public function addLead(Lead $lead)
127131
128132 $ lead = json_encode ($ lead );
129133 $ apiRequest = $ this ->prepareRequest ('add-lead ' , $ lead );
134+
130135 return $ this ->triggerPost ($ apiRequest );
131136 }
132137
@@ -156,6 +161,7 @@ public function updateLead(Lead $lead)
156161 } else {
157162 throw new ResourceNotFoundException ();
158163 }
164+
159165 return $ lead ;
160166 }
161167
@@ -164,7 +170,8 @@ public function updateLead(Lead $lead)
164170 * @return CloseIoResponse
165171 * @throws ResourceNotFoundException
166172 */
167- public function deleteLead ($ id ){
173+ public function deleteLead ($ id )
174+ {
168175 $ apiRequest = $ this ->prepareRequest ('delete-lead ' , null , ['id ' => $ id ]);
169176
170177 /** @var CloseIoResponse $result */
@@ -193,9 +200,9 @@ public function setCurl($curl)
193200 public function validateLeadForPost (Lead $ lead )
194201 {
195202 $ invalidProperties = ['id ' , 'organization ' , 'tasks ' , 'opportunities ' ];
196- foreach ($ invalidProperties as $ invalidProperty ){
203+ foreach ($ invalidProperties as $ invalidProperty ) {
197204 $ getter = 'get ' . ucfirst ($ invalidProperty );
198- if ($ lead ->$ getter ()){
205+ if ($ lead ->$ getter ()) {
199206 throw new InvalidNewLeadPropertyException ('Cannot post ' . $ invalidProperty . ' to new lead. ' );
200207 }
201208 }
0 commit comments