| Conditions | 21 |
| Paths | 206 |
| Total Lines | 83 |
| Code Lines | 63 |
| Lines | 6 |
| Ratio | 7.23 % |
| 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 |
||
| 255 | private function exportNow($memberArray, $customFields, $unsubscribeArray) |
||
| 256 | { |
||
| 257 | $api = $this->getAPI(); |
||
| 258 | PWUpdateGetData::flush("<hr />", "deleted"); |
||
| 259 | if (count($memberArray)) { |
||
| 260 | if (count($memberArray) == count($customFields)) { |
||
| 261 | $finalCustomFields = array(); |
||
| 262 | foreach ($customFields as $email => $valuesArray) { |
||
| 263 | $updateDetails = false; |
||
| 264 | $alreadyListed = false; |
||
| 265 | if (isset($this->previouslyExported[$email])) { |
||
| 266 | $alreadyListed = true; |
||
| 267 | DB::alteration_message("".$email." is already listed"); |
||
| 268 | foreach ($valuesArray as $key => $value) { |
||
| 269 | if ($key != "Email") { |
||
| 270 | if (!isset($this->previouslyExported[$email][$key])) { |
||
| 271 | if ($value == "tba" || $value == "No" || strlen(trim($value)) < 1) { |
||
| 272 | //do nothing |
||
| 273 | } else { |
||
| 274 | $updateDetails = true; |
||
| 275 | DB::alteration_message(" - - - Missing value for $key - current value $value", "created"); |
||
| 276 | } |
||
| 277 | } elseif ($this->previouslyExported[$email][$key] != $value) { |
||
| 278 | DB::alteration_message(" - - - Update for ".$email." for $key $value that is not the same as previous value: ".$this->previouslyExported[$email][$key], "created"); |
||
| 279 | $updateDetails = true; |
||
| 280 | } |
||
| 281 | } |
||
| 282 | } |
||
| 283 | } else { |
||
| 284 | DB::alteration_message("Adding entry: ".implode("; ", $customFields[$email]).".", "created"); |
||
| 285 | } |
||
| 286 | $finalCustomFields[$email] = array(); |
||
| 287 | $k = 0; |
||
| 288 | foreach ($valuesArray as $key => $value) { |
||
| 289 | $finalCustomFields[$email][$k]["Key"] = $key; |
||
| 290 | $finalCustomFields[$email][$k]["Value"] = $value; |
||
| 291 | $k++; |
||
| 292 | } |
||
| 293 | if ($updateDetails) { |
||
| 294 | if (!$this->debug) { |
||
| 295 | $api->updateSubscriber( |
||
| 296 | $listID = Config::inst()->get("CampaignMonitorSyncAllMembers", "mailing_list_id"), |
||
| 297 | $oldEmailAddress = $email, |
||
| 298 | $memberArray[$email], |
||
| 299 | $finalCustomFields[$email], |
||
| 300 | $resubscribe = true, |
||
| 301 | $restartSubscriptionBasedAutoResponders = false |
||
| 302 | ); |
||
| 303 | } |
||
| 304 | unset($finalCustomFields[$email]); |
||
| 305 | unset($customFields[$email]); |
||
| 306 | unset($memberArray[$email]); |
||
| 307 | } elseif ($alreadyListed) { |
||
| 308 | unset($finalCustomFields[$email]); |
||
| 309 | unset($customFields[$email]); |
||
| 310 | unset($memberArray[$email]); |
||
| 311 | } |
||
| 312 | } |
||
| 313 | if (count($memberArray)) { |
||
| 314 | if (count($memberArray) == count($finalCustomFields)) { |
||
| 315 | DB::alteration_message("<h3>adding: ".count($memberArray)." subscribers</h3>", "created"); |
||
| 316 | if (!$this->debug) { |
||
| 317 | $api->addSubscribers(Config::inst()->get("CampaignMonitorSyncAllMembers", "mailing_list_id"), $memberArray, $finalCustomFields, true, false, false); |
||
| 318 | } |
||
| 319 | View Code Duplication | } else { |
|
| 320 | DB::alteration_message("Error, memberArray (".count($memberArray).") count is not the same as finalCustomFields (".count($finalCustomFields).") count.", "deleted"); |
||
| 321 | } |
||
| 322 | } else { |
||
| 323 | DB::alteration_message("adding: ".count($memberArray)." subscribers"); |
||
| 324 | } |
||
| 325 | foreach ($unsubscribeArray as $email => $member) { |
||
| 326 | DB::alteration_message("Now doing Blacklisting: ".$member->Email, "deleted"); |
||
| 327 | if (!$this->debug) { |
||
| 328 | $api->unsubscribeSubscriber(Config::inst()->get("CampaignMonitorSyncAllMembers", "mailing_list_id"), $member); |
||
| 329 | } |
||
| 330 | } |
||
| 331 | View Code Duplication | } else { |
|
| 332 | DB::alteration_message("Error, memberArray (".count($memberArray).") count is not the same as customFields (".count($customFields).") count.", "deleted"); |
||
| 333 | } |
||
| 334 | } else { |
||
| 335 | DB::alteration_message("adding: ".count($memberArray)." subscribers"); |
||
| 336 | } |
||
| 337 | } |
||
| 338 | } |
||
| 339 |
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.