| Conditions | 13 | 
| Paths | 384 | 
| Total Lines | 236 | 
| Code Lines | 168 | 
| 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  | 
            ||
| 249 | public function getCMSFields()  | 
            ||
| 250 |     { | 
            ||
| 251 | $fields = parent::getCMSFields();  | 
            ||
| 252 | //remove all unneccessary fields and tabs  | 
            ||
| 253 |         $fields->removeByName("AlsoShowHere"); | 
            ||
| 254 |         $fields->removeByName("Tax"); | 
            ||
| 255 |         $fields->removeByName("Links"); | 
            ||
| 256 |         $fields->removeByName("Details"); | 
            ||
| 257 |         $fields->removeByName("Images"); | 
            ||
| 258 |         $fields->removeFieldFromTab('Root', 'Title'); | 
            ||
| 259 |         $fields->removeFieldFromTab('Root', 'URLSegment'); | 
            ||
| 260 |         $fields->removeFieldFromTab('Root', 'MenuTitle'); | 
            ||
| 261 |         $fields->removeFieldFromTab('Root', 'ShortDescription'); | 
            ||
| 262 |         $fields->removeFieldFromTab('Root', 'Content'); | 
            ||
| 263 |         $fields->removeFieldFromTab('Root', 'Metadata'); | 
            ||
| 264 |         $fields->removeFieldFromTab('Root', 'AddToCartLink'); | 
            ||
| 265 | |||
| 266 | |||
| 267 | $fields->addFieldsToTab(  | 
            ||
| 268 | 'Root.Main',  | 
            ||
| 269 | array(  | 
            ||
| 270 |                 $allowPurchaseField = CheckboxField::create("AllowPurchase", "<strong>Allow product to be purchased</strong>"), | 
            ||
| 271 |                 $sellinOnBehalf = CheckboxField::create("SellingOnBehalf", "<strong>Selling on behalf</strong>"), | 
            ||
| 272 |                 $featuredProductField = CheckboxField::create('FeaturedProduct', _t('Product.FEATURED', '<strong>Featured Product</strong>')), | 
            ||
| 273 |                 TextField::create('Title', 'Product Title'), | 
            ||
| 274 | )  | 
            ||
| 275 | );  | 
            ||
| 276 | $secondhandProductCategories = SecondHandProductGroup::get();  | 
            ||
| 277 |         if ($secondhandProductCategories->count()) { | 
            ||
| 278 | $fields->addFieldToTab(  | 
            ||
| 279 | 'Root.Main',  | 
            ||
| 280 | $categoryField = DropdownField::create(  | 
            ||
| 281 | 'ParentID',  | 
            ||
| 282 | 'Product Category',  | 
            ||
| 283 | $secondhandProductCategories->map()  | 
            ||
| 284 | )  | 
            ||
| 285 | );  | 
            ||
| 286 | }  | 
            ||
| 287 | $fields->addFieldsToTab(  | 
            ||
| 288 | 'Root.Main',  | 
            ||
| 289 | array(  | 
            ||
| 290 |                 ReadonlyField::create('CanBeSold', "For Sale", DBField::create_field('Boolean', $this->canPurchase())->Nice()), | 
            ||
| 291 |                 ReadonlyField::create('CreatedNice', "First Entered", $this->getCreatedNice()), | 
            ||
| 292 |                 TextField::create('InternalItemID', "Product Code"), | 
            ||
| 293 |                 $purchasePriceField = NumericField::create('PurchasePrice', 'Purchase Price'), | 
            ||
| 294 |                 $salePriceField = NumericField::create('Price', 'Sale Price'), | 
            ||
| 295 |                 $soldPriceField = NumericField::create('SoldPrice', 'Sold Price'), | 
            ||
| 296 |                 $serialNumberField = TextField::create('SerialNumber', 'Serial Number'), | 
            ||
| 297 | $productQualityField = DropdownField::create(  | 
            ||
| 298 | "ProductQuality",  | 
            ||
| 299 | "Product Condition/Quality",  | 
            ||
| 300 |                     $this->dbObject('ProductQuality')->enumValues() | 
            ||
| 301 | ),  | 
            ||
| 302 | $boxOrCaseField = DropdownField::create(  | 
            ||
| 303 | "IncludesBoxOrCase",  | 
            ||
| 304 | "Includes Box/Case",  | 
            ||
| 305 |                     $this->dbObject('IncludesBoxOrCase')->enumValues() | 
            ||
| 306 | ),  | 
            ||
| 307 |                 $originalManualField = CheckboxField::create("OriginalManual", "Includes Original Manual"), | 
            ||
| 308 |                 $contentField = TextField::create("ShortDescription", "Description"), | 
            ||
| 309 |                 $boughtDate = DateField::create('DateItemWasBought', 'Date this item was bought'), | 
            ||
| 310 |                 $soldDate = DateField::create('DateItemWasSold', 'Date this item was sold'), | 
            ||
| 311 |                 $mainImageField = UploadField::create("Image", "Main Product Image"), | 
            ||
| 312 |                 $additionalImagesField = UploadField::create("AdditionalImages", "More Images"), | 
            ||
| 313 |                 $metaFieldDesc = TextareaField::create("MetaDescription", 'Meta Description') | 
            ||
| 314 | )  | 
            ||
| 315 | );  | 
            ||
| 316 | $soldDate->setDisabled(true);  | 
            ||
| 317 | |||
| 318 | //set right titles and descriptions  | 
            ||
| 319 |         $featuredProductField->setDescription('If this box is ticked then this product will appear in the "Featured Products" box on the home page'); | 
            ||
| 320 |         $allowPurchaseField->setDescription("This box must be ticked to allow a customer to purchase it"); | 
            ||
| 321 |         $sellinOnBehalf->setDescription('This box must be ticked if this product is being sold on behalf'); | 
            ||
| 322 |         $purchasePriceField->setRightTitle("Price paid for the product"); | 
            ||
| 323 |         $salePriceField->setRightTitle("Selling price"); | 
            ||
| 324 |         $soldPriceField->setRightTitle("The price that the product actually sold for"); | 
            ||
| 325 |         $serialNumberField->setRightTitle("Enter the serial number of the product here"); | 
            ||
| 326 |         $originalManualField->setDescription("Tick this box if the product includes the original manual, otherwise leave it empty"); | 
            ||
| 327 |         $boxOrCaseField->setRightTitle("Does this product come with a box, case or both?"); | 
            ||
| 328 |         $contentField->setRightTitle("Optional text only description, the maximum length of this description is 255 characters."); | 
            ||
| 329 | $contentField->setMaxLength(255);  | 
            ||
| 330 | $qualityFieldDescription = "A <strong>Condition Rating Page</strong> has yet to be setup";  | 
            ||
| 331 | $obj = $this->EcomConfig()->SecondHandExplanationPage();  | 
            ||
| 332 |         if ($obj->exists()) { | 
            ||
| 333 | $qualityFieldDescription = 'An explanation of the ratings scale can be found by clicking this <a href="' . $obj->Link() . '">link</a>';  | 
            ||
| 334 | }  | 
            ||
| 335 | $productQualityField->setRightTitle($qualityFieldDescription);  | 
            ||
| 336 |         $boughtDate->setRightTitle('Date Format (dd-mm-YYYY). Example: 3rd of May 1992 should be entered as 03-05-1992'); | 
            ||
| 337 | $mainImageField->setRightTitle(  | 
            ||
| 338 | "<strong>Upload the main image for the product here.</strong><br>  | 
            ||
| 339 | Recommended size: 810px wide x 418px high - but you can choose any width up to 810px, height must  | 
            ||
| 340 | ALWAYS BE 418px. Should be provided to FTP data upload as productcode.jpg - e.g. 1003040.jpg.  | 
            ||
| 341 | Images should be compressed up to 50%."  | 
            ||
| 342 | );  | 
            ||
| 343 | $additionalImagesField->setRightTitle(  | 
            ||
| 344 | "<strong>Upload additional images here, you can upload as many as you want.</strong><br>  | 
            ||
| 345 | Recommended size: 810px wide x 418px high - but you can choose any width up to 810px, height must  | 
            ||
| 346 | ALWAYS BE 418px. Should be provided to FTP data upload as productcode.jpg - e.g. 1003040.jpg.  | 
            ||
| 347 | Images should be compressed up to 50%."  | 
            ||
| 348 | );  | 
            ||
| 349 | //replace InternalItemID field with a read only field  | 
            ||
| 350 | $fields->replaceField(  | 
            ||
| 351 | 'InternalItemID',  | 
            ||
| 352 |             $fields->dataFieldByName('InternalItemID')->performReadonlyTransformation() | 
            ||
| 353 | );  | 
            ||
| 354 | |||
| 355 |         $lastEditedItems = SecondHandProduct::get()->sort('Created', 'DESC')->limit(100); | 
            ||
| 356 | |||
| 357 | $lastItems = array(  | 
            ||
| 358 | 0 => '--- not based on previous sale ---'  | 
            ||
| 359 | );  | 
            ||
| 360 | |||
| 361 |         foreach ($lastEditedItems as $lastEditedItem) { | 
            ||
| 362 | $details = $lastEditedItem->getSellerSummary();  | 
            ||
| 363 |             if ($details) { | 
            ||
| 364 | $lastItems[$lastEditedItem->ID] = $details;  | 
            ||
| 365 | }  | 
            ||
| 366 | }  | 
            ||
| 367 | |||
| 368 | $fields->addFieldsToTab(  | 
            ||
| 369 | 'Root.SellersDetails',  | 
            ||
| 370 | array(  | 
            ||
| 371 |                 HeaderField::create('SellersDetails', 'Enter the details of the person who the product was purchased from'), | 
            ||
| 372 | DropdownField::create(  | 
            ||
| 373 | 'BasedOnID',  | 
            ||
| 374 | 'Autocomplete from saved items',  | 
            ||
| 375 | $lastItems  | 
            ||
| 376 | ),  | 
            ||
| 377 |                 TextField::create('SellersName', 'Name'), | 
            ||
| 378 |                 TextField::create('SellersPhone', 'Phone'), | 
            ||
| 379 |                 TextField::create('SellersEmail', 'Email Address'), | 
            ||
| 380 | DropdownField::create(  | 
            ||
| 381 | 'SellersIDType',  | 
            ||
| 382 | 'ID Type',  | 
            ||
| 383 |                     $this->dbObject('SellersIDType')->enumValues() | 
            ||
| 384 | ),  | 
            ||
| 385 |                 TextField::create('SellersIDNumber', 'ID Number'), | 
            ||
| 386 |                 DateField::create('SellersDateOfBirth', 'Date of Birth'), | 
            ||
| 387 |                 DateField::create('SellersIDExpiryDate', 'ID Expiry Date'), | 
            ||
| 388 |                 CheckboxField::create('SellersIDPhotocopy', 'ID Photocopy') | 
            ||
| 389 | )  | 
            ||
| 390 | );  | 
            ||
| 391 | |||
| 392 |         if (class_exists('GoogleAddressField')) { | 
            ||
| 393 |             $mappingArray = $this->Config()->get('fields_to_google_geocode_conversion'); | 
            ||
| 394 |             if (is_array($mappingArray) && count($mappingArray)) { | 
            ||
| 395 | $fields->addFieldToTab(  | 
            ||
| 396 | 'Root.SellersDetails',  | 
            ||
| 397 | $geocodingField = new GoogleAddressField(  | 
            ||
| 398 | 'SellersAddressGeocodingField',  | 
            ||
| 399 |                         _t('OrderAddress.FIND_ADDRESS', 'Find address'), | 
            ||
| 400 |                         Session::get('SellersAddressGeocodingFieldValue') | 
            ||
| 401 | )  | 
            ||
| 402 | );  | 
            ||
| 403 | $geocodingField->setFieldMap($mappingArray);  | 
            ||
| 404 | |||
| 405 |                 $country_code = Config::inst()->get('SecondHandProduct', 'country_code'); | 
            ||
| 406 |                 if ($country_code) { | 
            ||
| 407 | $geocodingField->setRestrictToCountryCode($country_code);  | 
            ||
| 408 | }  | 
            ||
| 409 | //$geocodingField->setAlwaysShowFields(true);  | 
            ||
| 410 | }  | 
            ||
| 411 | }  | 
            ||
| 412 | |||
| 413 | $fields->addFieldsToTab(  | 
            ||
| 414 | 'Root.SellersDetails',  | 
            ||
| 415 | array(  | 
            ||
| 416 |                 TextField::create('SellersAddress', 'Address'), | 
            ||
| 417 |                 TextField::create('SellersAddress2', 'Suburb'), | 
            ||
| 418 |                 TextField::create('SellersCity', 'City/Town'), | 
            ||
| 419 |                 TextField::create('SellersPostalCode', 'Postal Code'), | 
            ||
| 420 |                 TextField::create('SellersRegionCode', 'Region Code'), | 
            ||
| 421 |                 TextField::create('SellersCountry', 'Country'), | 
            ||
| 422 | )  | 
            ||
| 423 | );  | 
            ||
| 424 | //add all fields to the main tab  | 
            ||
| 425 | $fields->addFieldToTab(  | 
            ||
| 426 | 'Root.SellersDetails',  | 
            ||
| 427 | EcommerceCMSButtonField::create(  | 
            ||
| 428 | 'PrintView',  | 
            ||
| 429 | $this->getPrintLink(),  | 
            ||
| 430 | 'Print Details',  | 
            ||
| 431 | $newWindow = true  | 
            ||
| 432 | )  | 
            ||
| 433 | );  | 
            ||
| 434 |         if ($this->BasedOnID) { | 
            ||
| 435 |             $list = Config::inst()->get('SecondHandProduct', 'seller_summary_detail_fields'); | 
            ||
| 436 | $labels = $this->FieldLabels();  | 
            ||
| 437 |             foreach ($list as $listField) { | 
            ||
| 438 | $fields->replaceField(  | 
            ||
| 439 | $listField,  | 
            ||
| 440 | ReadonlyField::create(  | 
            ||
| 441 | $listField,  | 
            ||
| 442 | $fields->dataFieldByName($listField)->Title()  | 
            ||
| 443 | )  | 
            ||
| 444 | );  | 
            ||
| 445 | }  | 
            ||
| 446 |             $fields->removeByName('SellersAddressGeocodingField'); | 
            ||
| 447 | }  | 
            ||
| 448 | $fields->addFieldToTab(  | 
            ||
| 449 | 'Root.Categorisation',  | 
            ||
| 450 | $categoriesTable = $this->getProductGroupsTableField()  | 
            ||
| 451 | );  | 
            ||
| 452 | |||
| 453 | // If the product has been sold all fields should be disabled  | 
            ||
| 454 | // Only the shop administrator is allowed to undo this.  | 
            ||
| 455 |         if ($this->HasBeenSold()) { | 
            ||
| 456 | $fields->insertAfter(  | 
            ||
| 457 | 'AllowPurchase',  | 
            ||
| 458 | EcommerceCMSButtonField::create(  | 
            ||
| 459 | 'ArchiveButton',  | 
            ||
| 460 | '/admin/secondhandproducts/SecondHandProduct/archive/?productid=' . $this->ID,  | 
            ||
| 461 |                     _t('SecondHandProduct.ARCHIVE_BUTTON', 'Archive Product') | 
            ||
| 462 | )  | 
            ||
| 463 | );  | 
            ||
| 464 | $fields = $fields->makeReadonly();  | 
            ||
| 465 | $fields->replaceField($categoriesTable->Name, $categoriesTable);  | 
            ||
| 466 | $categoriesTable->setConfig(GridFieldConfig_RecordViewer::create());  | 
            ||
| 467 | $fields->replaceField(  | 
            ||
| 468 | 'EnquiresList',  | 
            ||
| 469 | GridField::create(  | 
            ||
| 470 | 'EnquiresList',  | 
            ||
| 471 | 'Enquiries List',  | 
            ||
| 472 | $this->PageEnquiries(),  | 
            ||
| 473 | GridFieldConfig_RecordViewer::create()  | 
            ||
| 474 | )  | 
            ||
| 475 | );  | 
            ||
| 476 | }  | 
            ||
| 477 | |||
| 478 |         if ($this->canEdit()) { | 
            ||
| 479 |             $fields->replaceField('AllowPurchase', CheckboxField::create('AllowPurchase', '<strong>Allow product to be purchased</strong>')); | 
            ||
| 480 |             $fields->replaceField('DateItemWasSold', DateField::create('DateItemWasSold', 'Date this item was sold')); | 
            ||
| 481 | }  | 
            ||
| 482 | |||
| 483 | return $fields;  | 
            ||
| 484 | }  | 
            ||
| 485 | |||
| 722 | 
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.