| Conditions | 35 |
| Paths | 12328 |
| Total Lines | 179 |
| Code Lines | 146 |
| 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 |
||
| 107 | private function makeModules($rows) |
||
| 108 | { |
||
| 109 | increase_time_limit_to(600); |
||
| 110 | DB::query("DELETE FROM \"EcommerceProductTag\" WHERE TRIM(Title) = '';"); |
||
| 111 | $parent = ModuleProductGroup::get() |
||
| 112 | ->filter(array("URLSegment" => self::$parent_url_segment)) |
||
| 113 | ->first(); |
||
| 114 | if ($parent) { |
||
| 115 | $parentID = $parent->ID; |
||
| 116 | unset($parent); |
||
| 117 | } else { |
||
| 118 | $parentID = 0; |
||
| 119 | } |
||
| 120 | $group = Group::get() |
||
| 121 | ->filter(array("Code" => SoftwareAuthorMemberDOD::get_register_group_code())) |
||
| 122 | ->first(); |
||
| 123 | if (!$group) { |
||
| 124 | user_error("Group for authors could not be found!"); |
||
| 125 | } |
||
| 126 | if ($parentID) { |
||
| 127 | if ($rows) { |
||
| 128 | foreach ($rows as $row) { |
||
| 129 | $new = null; |
||
| 130 | $ImportID = intval($row["ImportID"]); |
||
| 131 | if ($ImportID) { |
||
| 132 | $ScreenName = Convert::raw2sql($row["ScreenName"]); |
||
| 133 | $Email = Convert::raw2sql($row["Email"]); |
||
| 134 | $GithubURL = Convert::raw2sql($row["GithubURL"]); |
||
| 135 | $SilverstripeDotOrgURL = Convert::raw2sql($row["SilverstripeDotOrgURL"]); |
||
| 136 | $CompanyName = Convert::raw2sql($row["CompanyName"]); |
||
| 137 | $CompanyURL = Convert::raw2sql($row["CompanyURL"]); |
||
| 138 | $Code = Convert::raw2sql($row["Code"]); |
||
| 139 | $Title = Convert::raw2sql($row["Title"]); |
||
| 140 | $MainURL = Convert::raw2sql($row["MainURL"]); |
||
| 141 | $ReadMeURL = Convert::raw2sql($row["ReadMeURL"]); |
||
| 142 | $DemoURL = Convert::raw2sql($row["DemoURL"]); |
||
| 143 | $SvnURL = Convert::raw2sql($row["SvnURL"]); |
||
| 144 | $GitURL = Convert::raw2sql($row["GitURL"]); |
||
| 145 | $OtherURL = Convert::raw2sql($row["OtherURL"]); |
||
| 146 | $Tags = Convert::raw2sql($row["Tags"]); |
||
| 147 | $Description = Convert::raw2sql($row["Description"]); |
||
| 148 | $page = ModuleProduct::get() |
||
| 149 | ->filter(array("ImportID" => $ImportID)) |
||
| 150 | ->first(); |
||
| 151 | if (!$page) { |
||
| 152 | $new = true; |
||
| 153 | $page = new ModuleProduct(); |
||
| 154 | } else { |
||
| 155 | $new = false; |
||
| 156 | } |
||
| 157 | if ($new == false && isset($page->ParentID) && $page->ParentID && $page->ParentID > 0 && $page->ParentID != $parentID) { |
||
| 158 | //do nothing |
||
| 159 | } else { |
||
| 160 | if (!$new) { |
||
| 161 | DB::query("DELETE FROM \"EcommerceProductTag_Products\" WHERE ProductID = ".$page->ID); |
||
| 162 | } |
||
| 163 | if ($Title && $Code) { |
||
| 164 | $member = null; |
||
| 165 | //member |
||
| 166 | if ($ScreenName) { |
||
| 167 | $member = Member::get() |
||
| 168 | ->filter(array("ScreenName" => $ScreenName)) |
||
| 169 | ->first(); |
||
| 170 | } |
||
| 171 | $identifierField = Member::get_unique_identifier_field(); |
||
| 172 | if (!$member) { |
||
| 173 | $member = Member::get() |
||
| 174 | ->filter(array($identifierField, $Email)); |
||
| 175 | } |
||
| 176 | if ($member) { |
||
| 177 | $i = 0; |
||
| 178 | while ($replaceMember = Member::get() |
||
| 179 | ->filter(array($identifierField => $Email)) |
||
| 180 | ->exclude("ID", $member->ID) |
||
| 181 | ->first() |
||
| 182 | && $i < 100000 |
||
| 183 | ) { |
||
| 184 | if ($replaceMember) { |
||
| 185 | $i++; |
||
| 186 | $member = $replaceMember; |
||
| 187 | $Email = $Email."_DOUBLE_$i"; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | } |
||
| 191 | if (!$member) { |
||
| 192 | $member = new Member(); |
||
| 193 | } |
||
| 194 | if ($ScreenName) { |
||
| 195 | $member->ScreenName = $ScreenName; |
||
| 196 | $member->Email = $Email; |
||
| 197 | $member->GithubURL = $GithubURL; |
||
| 198 | $member->SilverstripeDotOrgURL = $SilverstripeDotOrgURL; |
||
| 199 | $member->CompanyName = $CompanyName; |
||
| 200 | $member->CompanyURL = $CompanyURL; |
||
| 201 | if (!$member->Password) { |
||
| 202 | $member->Password = Member::create_new_password(); |
||
| 203 | } |
||
| 204 | $member->write(); |
||
| 205 | $member->Groups()->add($group); |
||
| 206 | } else { |
||
| 207 | DB::alteration_message("no screen name provided for <b>$Title</b>", "deleted"); |
||
| 208 | } |
||
| 209 | //page |
||
| 210 | $page->ImportID = $ImportID; |
||
| 211 | $page->ParentID = $parentID; |
||
| 212 | $page->ShowInSearch = 1; |
||
| 213 | $page->ShowInMenus = 1; |
||
| 214 | $page->Title = $Title; |
||
| 215 | $page->MenuTitle = $Title; |
||
| 216 | $page->MetaDescription = strip_tags($Description); |
||
| 217 | $page->Code = $Code; |
||
| 218 | $page->InternalItemID = $Code; |
||
| 219 | $page->URLSegment = $Code; |
||
| 220 | $page->ProvideComments = true; |
||
| 221 | |||
| 222 | $page->MainURL = $MainURL; |
||
| 223 | $page->ReadMeURL = $ReadMeURL; |
||
| 224 | $page->DemoURL= $DemoURL; |
||
| 225 | $page->SvnURL = $SvnURL; |
||
| 226 | $page->GitURL = $GitURL; |
||
| 227 | $page->OtherURL = $OtherURL; |
||
| 228 | |||
| 229 | $page->writeToStage('Stage'); |
||
| 230 | $page->Publish('Stage', 'Live'); |
||
| 231 | $page->Status = "Published"; |
||
| 232 | $tagsArray = explode(",", $Tags); |
||
| 233 | if ($tagsArray && count($tagsArray)) { |
||
| 234 | foreach ($tagsArray as $tag) { |
||
| 235 | $tag = Convert::raw2sql(trim($tag)); |
||
| 236 | if ($tag) { |
||
| 237 | $tagObject = EcommerceProductTag::get() |
||
| 238 | ->filter(array("Title" => $tag)) |
||
| 239 | ->First(); |
||
| 240 | if (!$tagObject) { |
||
| 241 | $tagObject = EcommerceProductTag::get() |
||
| 242 | ->filter(array("Synonyms:PartialMatch" => $tag)) |
||
| 243 | ->first(); |
||
| 244 | } |
||
| 245 | if (!$tagObject) { |
||
| 246 | $tagObject = new EcommerceProductTag(); |
||
| 247 | $tagObject->Title = $tag; |
||
| 248 | $tagObject->write(); |
||
| 249 | } |
||
| 250 | $existingTags = $page->EcommerceProductTags(); |
||
| 251 | $existingTags->add($tagObject); |
||
| 252 | } |
||
| 253 | } |
||
| 254 | } |
||
| 255 | if ($member) { |
||
| 256 | DB::query("DELETE FROM \"ModuleProduct_Authors\" WHERE \"ModuleProductID\" = ".$page->ID." AND MemberID <> ".$member->ID); |
||
| 257 | $existingAuthors = $page->Authors(); |
||
| 258 | $existingAuthors->add($member); |
||
| 259 | } else { |
||
| 260 | DB::alteration_message("no member for <b>$Title</b>", "deleted"); |
||
| 261 | } |
||
| 262 | if ($new === true) { |
||
| 263 | DB::alteration_message("added <b>$Title</b>", "created"); |
||
| 264 | } elseif ($new === false) { |
||
| 265 | DB::alteration_message("updated <b>$Title</b>", "edited"); |
||
| 266 | } elseif ($new === null) { |
||
| 267 | DB::alteration_message("error updating <b>$Title</b>", "deleted"); |
||
| 268 | } else { |
||
| 269 | DB::alteration_message("BIG error updating <b>$Title</b>", "deleted"); |
||
| 270 | } |
||
| 271 | } else { |
||
| 272 | DB::alteration_message("row found without title or code", "deleted"); |
||
| 273 | } |
||
| 274 | } |
||
| 275 | } else { |
||
| 276 | DB::alteration_message("row found without import id", "deleted"); |
||
| 277 | } |
||
| 278 | } |
||
| 279 | } else { |
||
| 280 | DB::alteration_message("no data found", "deleted"); |
||
| 281 | } |
||
| 282 | } else { |
||
| 283 | DB::alteration_message("no parent group page found (a ModuleProductGroup with new-modules as URL Segment", "deleted"); |
||
| 284 | } |
||
| 285 | } |
||
| 286 | |||
| 372 |
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.