| Conditions | 5 |
| Paths | 12 |
| Total Lines | 119 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 240 | public function testsubscribers() |
||
| 241 | { |
||
| 242 | $this->setupTests(); |
||
| 243 | |||
| 244 | |||
| 245 | //create list |
||
| 246 | $result = $this->api->createList( |
||
| 247 | $this->egData["listTitle"], |
||
| 248 | $this->egData["unsubscribePage"], |
||
| 249 | $this->egData["confirmedOptIn"], |
||
| 250 | $this->egData["confirmationSuccessPage"], |
||
| 251 | $this->egData["unsubscribeSetting"] |
||
| 252 | ); |
||
| 253 | $this->egData["tempListID"] = $result; |
||
| 254 | |||
| 255 | $customFieldKey = $this->api->createCustomField( |
||
| 256 | $this->egData["tempListID"], |
||
| 257 | $visible = true, |
||
| 258 | $type = "multi_select_one", |
||
| 259 | $title = "are you happy?", |
||
| 260 | $options = array("YES", "NO") |
||
| 261 | ); |
||
| 262 | |||
| 263 | for ($i = 0; $i < 5; $i++) { |
||
| 264 | $member[$i] = new Member(); |
||
| 265 | $email = "test_".$i."_".$this->egData["oldEmailAddress"]; |
||
| 266 | $member[$i] = Member::get()->filter(array("Email" => $email))->First(); |
||
| 267 | if (!$member[$i]) { |
||
| 268 | $member[$i] = new Member(); |
||
| 269 | $member[$i]->Email = $email; |
||
| 270 | $member[$i]->FirstName = "First Name $i"; |
||
| 271 | $member[$i]->Surname = "Surname $i"; |
||
| 272 | $member[$i]->write(); |
||
| 273 | } |
||
| 274 | $result = $this->api->addSubscriber( |
||
| 275 | $this->egData["tempListID"], |
||
| 276 | $member[$i], |
||
| 277 | $customFields = array($customFieldKey => "NO"), |
||
| 278 | $resubscribe = true, |
||
| 279 | $restartSubscriptionBasedAutoResponders = false |
||
| 280 | ); |
||
| 281 | $result = $this->api->updateSubscriber( |
||
| 282 | $this->egData["tempListID"], |
||
| 283 | $email, |
||
| 284 | $member[$i], |
||
| 285 | $customFields = array($customFieldKey => "YES"), |
||
| 286 | $resubscribe = true, |
||
| 287 | $restartSubscriptionBasedAutoResponders = false |
||
| 288 | ); |
||
| 289 | sleep(1); |
||
| 290 | } |
||
| 291 | |||
| 292 | |||
| 293 | /* |
||
| 294 | $result = $this->api->addSubscribers( |
||
| 295 | $this->egData["tempListID"], |
||
| 296 | $membersSet, |
||
| 297 | $customFields = array(), |
||
| 298 | $resubscribe, |
||
| 299 | $queueSubscriptionBasedAutoResponders = false, |
||
| 300 | $restartSubscriptionBasedAutoResponders = false |
||
| 301 | ); |
||
| 302 | */ |
||
| 303 | |||
| 304 | $result = $this->api->deleteSubscriber( |
||
| 305 | $this->egData["tempListID"], |
||
| 306 | $member[2] |
||
| 307 | ); |
||
| 308 | |||
| 309 | $result = $this->api->unsubscribeSubscriber( |
||
| 310 | $this->egData["tempListID"], |
||
| 311 | $member[3] |
||
| 312 | ); |
||
| 313 | |||
| 314 | |||
| 315 | for ($i = 0; $i < 5; $i++) { |
||
| 316 | $result = $this->api->getSubscriberExistsForThisList( |
||
| 317 | $this->egData["tempListID"], |
||
| 318 | $member[$i] |
||
| 319 | ); |
||
| 320 | |||
| 321 | $result = $this->api->getListsForEmail($member[$i]); |
||
| 322 | |||
| 323 | $result = $this->api->getSubscriberCanReceiveEmailsForThisList( |
||
| 324 | $this->egData["tempListID"], |
||
| 325 | $member[$i] |
||
| 326 | ); |
||
| 327 | |||
| 328 | $result = $this->api->getSubscriberCanNoLongerReceiveEmailsForThisList( |
||
| 329 | $this->egData["tempListID"], |
||
| 330 | $member[$i] |
||
| 331 | ); |
||
| 332 | |||
| 333 | $result = $this->api->getSubscriber( |
||
| 334 | $this->egData["tempListID"], |
||
| 335 | $member[$i] |
||
| 336 | ); |
||
| 337 | |||
| 338 | $result = $this->api->getHistory( |
||
| 339 | $this->egData["tempListID"], |
||
| 340 | $member[$i] |
||
| 341 | ); |
||
| 342 | $result = $this->api->deleteSubscriber( |
||
| 343 | $this->egData["tempListID"], |
||
| 344 | $member[$i] |
||
| 345 | ); |
||
| 346 | $member[$i]->delete(); |
||
| 347 | sleep(1); |
||
| 348 | } |
||
| 349 | |||
| 350 | //delete list |
||
| 351 | if ($this->egData["tempListID"]) { |
||
| 352 | $this->api->deleteCustomField($this->egData["tempListID"], $customFieldKey); |
||
| 353 | $result = $this->api->deleteList($this->egData["tempListID"]); |
||
| 354 | } |
||
| 355 | |||
| 356 | echo "<h2>end of subscriber tests</h2>"; |
||
| 357 | $this->index(); |
||
| 358 | } |
||
| 359 | |||
| 383 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.