| Conditions | 3 |
| Paths | 3 |
| Total Lines | 115 |
| Code Lines | 55 |
| 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 |
||
| 78 | public function getCMSFields() |
||
| 79 | { |
||
| 80 | $fields = parent::getCMSFields(); |
||
| 81 | |||
| 82 | if ($this->ID) { |
||
| 83 | if ($this->Title == 'Default') { |
||
| 84 | $fields->replaceField( |
||
| 85 | 'Title', |
||
| 86 | ReadonlyField::create('Title') |
||
| 87 | ); |
||
| 88 | } |
||
| 89 | |||
| 90 | $fields->replaceField( |
||
| 91 | 'Code', |
||
| 92 | ReadonlyField::create('Code') |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | $fields->insertBefore(HeaderField::create('DeliveryHD', 'Delivery Options', 3), 'DeliveryType'); |
||
| 97 | |||
| 98 | $fields->replaceField( |
||
| 99 | 'DeliveryType', |
||
| 100 | OptionsetField::create('DeliveryType', 'Delivery Type', $this->getShippingOptions()) |
||
| 101 | ); |
||
| 102 | |||
| 103 | $fields->dataFieldByName('MaxDownloads') |
||
| 104 | ->displayIf('DeliveryType')->isEqualTo('downloaded'); |
||
| 105 | |||
| 106 | $fields->dataFieldByName('MaxDownloadsTime') |
||
| 107 | ->displayIf('DeliveryType')->isEqualTo('downloaded'); |
||
| 108 | |||
| 109 | $fields->dataFieldByName('DefaultWeight') |
||
| 110 | ->displayIf('DeliveryType')->isEqualTo('shipped'); |
||
| 111 | |||
| 112 | $fields->dataFieldByName('DefaultWeightUnit') |
||
| 113 | ->displayIf('DeliveryType')->isEqualTo('shipped'); |
||
| 114 | |||
| 115 | $fields->dataFieldByName('DefaultLengthUnit') |
||
| 116 | ->displayIf('DeliveryType')->isEqualTo('shipped'); |
||
| 117 | |||
| 118 | $fields->dataFieldByName('ShippingFlatRate') |
||
| 119 | ->displayIf('DeliveryType')->isEqualTo('flat_rate'); |
||
| 120 | |||
| 121 | $fields->replaceField( |
||
| 122 | 'ShippingFlatRateType', |
||
| 123 | DropdownField::create('ShippingFlatRateType', 'Flat Rate Type', $this->getShippingFlatRateTypes()) |
||
| 124 | ->setEmptyString('') |
||
| 125 | ->displayIf('DeliveryType')->isEqualTo('flat_rate')->end() |
||
| 126 | ); |
||
| 127 | |||
| 128 | $fields->insertBefore(HeaderField::create('HandlingHD', 'Handling Fees and Discounts', 3), 'HandlingFeeType'); |
||
| 129 | |||
| 130 | $fields->replaceField( |
||
| 131 | 'HandlingFeeType', |
||
| 132 | DropdownField::create('HandlingFeeType', 'Handling Fee Type', $this->getHandlingFeeTypes()) |
||
| 133 | ->setEmptyString('') |
||
| 134 | ->setDescription('This determines what type of Handling Fee you would like to use.') |
||
| 135 | ); |
||
| 136 | |||
| 137 | $fields->dataFieldByName('HandlingFee') |
||
| 138 | ->displayIf('HandlingFeeType')->isNotEqualTo(''); |
||
| 139 | |||
| 140 | $fields->dataFieldByName('HandlingFeeMinimum') |
||
| 141 | ->displayIf('HandlingFeeType')->isEqualTo('flat_percent_with_minimum'); |
||
| 142 | |||
| 143 | $fields->dataFieldByName('HandlingFeePercentage') |
||
| 144 | ->displayIf('HandlingFeeType')->isEqualTo('flat_percent_with_minimum') |
||
| 145 | ->orIf('HandlingFeeType')->isEqualTo('flat_percent'); |
||
| 146 | |||
| 147 | $fields->replaceField( |
||
| 148 | 'DiscountType', |
||
| 149 | DropdownField::create('DiscountType', 'Discount Type', $this->getDiscountTypes()) |
||
| 150 | ->setEmptyString('') |
||
| 151 | ->setDescription('This determines what type of per category discount you would like to use, if any.') |
||
| 152 | ); |
||
| 153 | |||
| 154 | $fields->dataFieldByName('DiscountName') |
||
| 155 | ->displayIf('DiscountType')->isNotEqualTo(''); |
||
| 156 | |||
| 157 | $fields->dataFieldByName('DiscountDetails') |
||
| 158 | ->displayIf('DiscountType')->isNotEqualTo(''); |
||
| 159 | |||
| 160 | $fields->dataFieldByName('CustomsValue') |
||
| 161 | ->setDescription('Enter a dollar amount here for the declared customs value for international shipments. If you leave this blank, the sale price of the item will be used.'); |
||
| 162 | |||
| 163 | /* |
||
| 164 | $fields = FieldList::create( |
||
| 165 | LiteralField::create( |
||
| 166 | 'PCIntro', |
||
| 167 | _t( |
||
| 168 | 'ProductCategory.PCIntro', |
||
| 169 | '<p>Categories must be created in your |
||
| 170 | <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" target="_blank"> |
||
| 171 | FoxyCart Product Categories |
||
| 172 | </a>, and also manually created in FoxyStripe. |
||
| 173 | </p>' |
||
| 174 | ) |
||
| 175 | ), |
||
| 176 | TextField::create('Code') |
||
| 177 | ->setTitle(_t('ProductCategory.Code', 'Category Code')) |
||
| 178 | ->setDescription(_t('ProductCategory.CodeDescription', 'copy/paste from FoxyCart')), |
||
| 179 | TextField::create('Title') |
||
| 180 | ->setTitle(_t('ProductCategory.Title', 'Category Title')) |
||
| 181 | ->setDescription(_t('ProductCategory.TitleDescription', 'copy/paste from FoxyCart')), |
||
| 182 | DropdownField::create( |
||
| 183 | 'DeliveryType', |
||
| 184 | 'Delivery Type', |
||
| 185 | singleton('ProductCategory')->dbObject('DeliveryType')->enumValues() |
||
| 186 | )->setEmptyString('') |
||
| 187 | ); |
||
| 188 | |||
| 189 | $this->extend('updateCMSFields', $fields); |
||
| 190 | */ |
||
| 191 | |||
| 192 | return $fields; |
||
| 193 | } |
||
| 352 |