1 | <?php |
||
22 | class Transport implements LoggerAwareInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var \SoapClient |
||
26 | */ |
||
27 | protected $client; |
||
28 | |||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $list; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $campaign; |
||
38 | |||
39 | /** |
||
40 | * @var LoggerInterface |
||
41 | */ |
||
42 | protected $logger = null; |
||
43 | |||
44 | /** |
||
45 | * @param \SoapClient $client |
||
46 | * @param string $list |
||
47 | * @param string $campaign |
||
48 | */ |
||
49 | 11 | public function __construct(\SoapClient $client, $list = null, $campaign = null) |
|
60 | |||
61 | /** |
||
62 | * {@inheritDoc} |
||
63 | */ |
||
64 | 7 | public function setLogger(LoggerInterface $logger) |
|
68 | |||
69 | /** |
||
70 | * |
||
71 | * @param string $list Name of the list |
||
72 | * @throws Exception if the list was not found in the remote server |
||
73 | * @return self |
||
74 | */ |
||
75 | 10 | public function setList($list) |
|
87 | |||
88 | /** |
||
89 | * @return int |
||
90 | */ |
||
91 | 2 | public function getList() |
|
95 | |||
96 | /** |
||
97 | * |
||
98 | * @param string $campaign Gate Name |
||
99 | * @return self |
||
100 | */ |
||
101 | 9 | public function setCampaign($campaign) |
|
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | 2 | public function getCampaign() |
|
115 | |||
116 | /** |
||
117 | * @param GetUserByFilterResponse $response |
||
118 | * @param string $idKey |
||
119 | * |
||
120 | * @return integer |
||
121 | */ |
||
122 | 2 | private function getExistingUserId(GetUserByFilterResponse $response, $idKey) |
|
139 | |||
140 | /** |
||
141 | * @param Properties $user |
||
142 | * @return integer |
||
143 | */ |
||
144 | 2 | private function createUser(Properties $user) |
|
165 | |||
166 | /** |
||
167 | * Subscribe the given user, if not already in list, and returns his identifier |
||
168 | * |
||
169 | * @param Properties $user |
||
170 | * @return int User id |
||
171 | * @throws UnexpectedValueException if $idKey is not an existing Property |
||
172 | * @throws Exception If something happens during the request |
||
173 | */ |
||
174 | 5 | public function subscribe(Properties $user, $idKey = 'ID') |
|
211 | |||
212 | /** |
||
213 | * @param int $userId |
||
214 | * @param Properties $inputData |
||
215 | * @param array $actionProperties |
||
216 | */ |
||
217 | public function TriggerCampaignForUserAndActionListItemWithResult($userId, Properties $inputData, array $actionProperties = []) |
||
225 | 2 | ||
226 | /** |
||
227 | 2 | * @param int $userId |
|
228 | * @param Properties $inputData |
||
229 | */ |
||
230 | 2 | public function TriggerCampaignForUserWithResult($userId, Properties $inputData) |
|
236 | 2 | ||
237 | /** |
||
238 | 2 | * @param int $userId |
|
239 | 1 | * @param string $method |
|
240 | 1 | * @param array $options |
|
241 | 1 | * @return mixed |
|
242 | 1 | * @throws \Exception |
|
243 | 1 | */ |
|
244 | 1 | private function triggerCampaign($userId, $method = 'TriggerCampaignForUserWithResult', array $options) |
|
277 | |||
278 | /** |
||
279 | * @param int $userId |
||
280 | * @return array |
||
281 | */ |
||
282 | private function getOptions($userId) |
||
292 | } |
||
293 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.