Conditions | 11 |
Paths | 12 |
Total Lines | 47 |
Code Lines | 34 |
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 |
||
22 | public function run($request) |
||
23 | { |
||
24 | $faultyOnes = CampaignMonitorCampaign::get()->where("(\"CampaignID\" = '' OR \"CampaignID\" IS NULL) AND (\"WebVersionURL\" IS NOT NULL && \"WebVersionURL\" <> '')"); |
||
25 | foreach ($faultyOnes as $faultyOne) { |
||
26 | $faultyOne->delete(); |
||
27 | } |
||
28 | $api = CampaignMonitorAPIConnector::create(); |
||
29 | $api->init(); |
||
30 | $campaigns = $api->getCampaigns(); |
||
31 | if (is_array($campaigns)) { |
||
32 | foreach ($campaigns as $campaign) { |
||
33 | if ($campaign->SentDate) { |
||
34 | $campaignMonitorCampaign = CampaignMonitorCampaign::get()->filter(array("CampaignID" => $campaign->CampaignID))->first(); |
||
35 | if (!$campaignMonitorCampaign) { |
||
36 | if ($this->verbose) { |
||
37 | DB::alteration_message("Adding ".$campaign->Subject." sent ".$campaign->SentDate, "created"); |
||
38 | } |
||
39 | $campaignMonitorCampaign = CampaignMonitorCampaign::create(); |
||
40 | } else { |
||
41 | if ($this->verbose) { |
||
42 | DB::alteration_message("already added ".$campaign->Subject, "edited"); |
||
43 | } |
||
44 | } |
||
45 | $campaignMonitorCampaign->HasBeenSent = true; |
||
46 | $campaignMonitorCampaign->CampaignID = $campaign->CampaignID; |
||
47 | $campaignMonitorCampaign->Subject = $campaign->Subject; |
||
48 | $campaignMonitorCampaign->Name = $campaign->Name; |
||
49 | $campaignMonitorCampaign->SentDate = $campaign->SentDate; |
||
50 | $campaignMonitorCampaign->WebVersionURL = $campaign->WebVersionURL; |
||
51 | $campaignMonitorCampaign->WebVersionTextURL = $campaign->WebVersionTextURL; |
||
52 | //$CampaignMonitorCampaign->ParentID = $this->ID; |
||
53 | $campaignMonitorCampaign->write(); |
||
54 | } else { |
||
55 | if ($this->verbose) { |
||
56 | DB::alteration_message("not adding ".$campaign->Subject." because it has not been sent yet...", "edited"); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | } else { |
||
61 | if ($this->verbose) { |
||
62 | DB::alteration_message("there are no campaigns to be added", "edited"); |
||
63 | } |
||
64 | } |
||
65 | if ($this->verbose) { |
||
66 | DB::alteration_message("<hr /><hr /><hr />Completed", "edited"); |
||
67 | } |
||
68 | } |
||
69 | } |
||
70 |