| Conditions | 12 |
| Paths | 482 |
| Total Lines | 109 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 140 | protected function getProductFields(FieldList $fields): FieldList |
||
| 141 | { |
||
| 142 | $hiddenTitle = ($this->product->ReceiptTitle) ? |
||
| 143 | htmlspecialchars($this->product->ReceiptTitle) : |
||
| 144 | htmlspecialchars($this->product->Title); |
||
| 145 | $code = $this->product->Code; |
||
| 146 | |||
| 147 | if ($this->product->getIsAvailable()) { |
||
| 148 | $fields->push( |
||
| 149 | HiddenField::create('name') |
||
| 150 | ->setValue( |
||
| 151 | self::getGeneratedValue($code, 'name', $hiddenTitle, 'value') |
||
| 152 | ) |
||
| 153 | ); |
||
| 154 | |||
| 155 | $fields->push( |
||
| 156 | HiddenField::create('category') |
||
| 157 | ->setValue( |
||
| 158 | self::getGeneratedValue($code, 'category', $this->product->FoxyCategory()->Code, 'value') |
||
| 159 | ) |
||
| 160 | ); |
||
| 161 | |||
| 162 | $fields->push( |
||
| 163 | HiddenField::create('code') |
||
| 164 | ->setValue( |
||
| 165 | self::getGeneratedValue($code, 'code', $this->product->Code, 'value') |
||
| 166 | ) |
||
| 167 | ); |
||
| 168 | |||
| 169 | $fields->push( |
||
| 170 | HiddenField::create('product_id') |
||
| 171 | ->setValue( |
||
| 172 | self::getGeneratedValue($code, 'product_id', $this->product->ID, 'value') |
||
| 173 | ) |
||
| 174 | ->setName('h:product_id') |
||
| 175 | ); |
||
| 176 | |||
| 177 | $fields->push( |
||
| 178 | HiddenField::create('price') |
||
| 179 | ->setValue( |
||
| 180 | self::getGeneratedValue($code, 'price', $this->product->Price, 'value') |
||
| 181 | ) |
||
| 182 | ); |
||
| 183 | |||
| 184 | if ($this->product->hasMethod('AbsoluteLink')) { |
||
| 185 | $fields->push( |
||
| 186 | HiddenField::create('url') |
||
| 187 | ->setValue( |
||
| 188 | self::getGeneratedValue($code, 'url', $this->product->AbsoluteLink(), 'value') |
||
| 189 | ) |
||
| 190 | ); |
||
| 191 | } |
||
| 192 | |||
| 193 | if ($this->product instanceof ShippableProduct) { |
||
| 194 | if ($this->product->Weight > 0) { |
||
| 195 | $fields->push( |
||
| 196 | HiddenField::create('weight') |
||
| 197 | ->setValue( |
||
| 198 | self::getGeneratedValue($code, 'weight', $this->product->Weight, 'value') |
||
| 199 | ) |
||
| 200 | ); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | $image = null; |
||
| 205 | if ($this->product->hasMethod('getImage')) { |
||
| 206 | if ($this->product->getImage()) { |
||
| 207 | $image = $this->product->getImage()->CMSThumbnail()->absoluteURL; |
||
| 208 | } |
||
| 209 | if ($image) { |
||
| 210 | $fields->push( |
||
| 211 | HiddenField::create('image') |
||
| 212 | ->setValue( |
||
| 213 | self::getGeneratedValue($code, 'image', $image, 'value') |
||
| 214 | ) |
||
| 215 | ); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | if ($this->product->QuantityMax > 0) { |
||
| 220 | $fields->push( |
||
| 221 | HiddenField::create('quantity_max') |
||
| 222 | ->setValue(self::getGeneratedValue($code, 'quantity_max', $this->product->QuantityMax, 'value')) |
||
| 223 | ); |
||
| 224 | } |
||
| 225 | |||
| 226 | if ($variationsField = $this->getProductVariations()) { |
||
| 227 | $fields->push($variationsField); |
||
| 228 | } |
||
| 229 | |||
| 230 | if ($this->product->QuantityMax != 1) { |
||
| 231 | $fields->push(QuantityField::create('x:visibleQuantity')->setTitle('Quantity')->setValue(1)); |
||
| 232 | } |
||
| 233 | $fields->push( |
||
| 234 | HiddenField::create('quantity') |
||
| 235 | ->setValue( |
||
| 236 | self::getGeneratedValue($code, 'quantity', 1, 'value') |
||
| 237 | ) |
||
| 238 | ); |
||
| 239 | |||
| 240 | $fields->push( |
||
| 241 | HeaderField::create('submitPrice', '$' . $this->product->Price, 4) |
||
| 242 | ->addExtraClass('submit-price') |
||
| 243 | ); |
||
| 244 | } |
||
| 245 | |||
| 246 | $this->extend('updateProductFields', $fields); |
||
| 247 | |||
| 248 | return $fields; |
||
| 249 | } |
||
| 362 |