| Conditions | 8 |
| Paths | 18 |
| Total Lines | 58 |
| Code Lines | 40 |
| 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 |
||
| 119 | protected function getProductFields(FieldList $fields) |
||
| 120 | { |
||
| 121 | $hiddenTitle = ($this->product->ReceiptTitle) ? htmlspecialchars($this->product->ReceiptTitle) : htmlspecialchars($this->product->Title); |
||
|
|
|||
| 122 | $code = $this->product->Code; |
||
| 123 | |||
| 124 | if ($this->product->Available) { |
||
| 125 | $fields->push(HiddenField::create(FoxyStripeProduct::getGeneratedValue($code, 'name', |
||
| 126 | $hiddenTitle))->setValue($hiddenTitle)); |
||
| 127 | $fields->push(HiddenField::create(FoxyStripeProduct::getGeneratedValue($code, 'category', |
||
| 128 | $this->product->Category()->Code))->setValue($this->product->Category()->Code)); |
||
| 129 | $fields->push(HiddenField::create(FoxyStripeProduct::getGeneratedValue($code, 'code', |
||
| 130 | $this->product->Code))->setValue($this->product->Code)); |
||
| 131 | $fields->push(HiddenField::create(FoxyStripeProduct::getGeneratedValue($code, 'product_id', |
||
| 132 | $this->product->ID))->setValue($this->product->ID)); |
||
| 133 | $fields->push(HiddenField::create(FoxyStripeProduct::getGeneratedValue($code, 'price', |
||
| 134 | $this->product->Price))->setValue($this->product->Price));//can't override id |
||
| 135 | $fields->push(HiddenField::create(FoxyStripeProduct::getGeneratedValue($code, 'weight', |
||
| 136 | $this->product->Weight))->setValue($this->product->Weight)); |
||
| 137 | if ($this->DiscountTitle && $this->ProductDiscountTiers()->exists()) { |
||
| 138 | $fields->push(HiddenField::create(FoxyStripeProduct::getGeneratedValue($code, 'discount_quantity_percentage', |
||
| 139 | $this->product->getDiscountFieldValue()))->setValue($this->product->getDiscountFieldValue())); |
||
| 140 | } |
||
| 141 | |||
| 142 | |||
| 143 | if ($this->product->PreviewImage()->exists()) { |
||
| 144 | $fields->push( |
||
| 145 | HiddenField::create(FoxyStripeProduct::getGeneratedValue($code, 'image', |
||
| 146 | $this->product->PreviewImage()->PaddedImage(80, 80)->absoluteURL)) |
||
| 147 | ->setValue($this->product->PreviewImage()->PaddedImage(80, 80)->absoluteURL) |
||
| 148 | ); |
||
| 149 | } |
||
| 150 | |||
| 151 | $optionsSet = $this->getProductOptionSet(); |
||
| 152 | $fields->push($optionsSet); |
||
| 153 | |||
| 154 | $quantityMax = ($this->site_config->MaxQuantity) ? $this->site_config->MaxQuantity : 10; |
||
| 155 | $count = 1; |
||
| 156 | $quantity = array(); |
||
| 157 | while ($count <= $quantityMax) { |
||
| 158 | $countVal = FoxyStripeProduct::getGeneratedValue($this->product->Code, 'quantity', $count, 'value'); |
||
| 159 | $quantity[$countVal] = $count; |
||
| 160 | $count++; |
||
| 161 | } |
||
| 162 | |||
| 163 | $fields->push(DropdownField::create('quantity', 'Quantity', $quantity)); |
||
| 164 | |||
| 165 | $fields->push(HeaderField::create('submitPrice', '$' . $this->product->Price, 4)); |
||
| 166 | |||
| 167 | |||
| 168 | $this->extend('updatePurchaseFormFields', $fields); |
||
| 169 | } else { |
||
| 170 | $fields->push(HeaderField::create('submitPrice', 'Currently Out of Stock'), 4); |
||
| 171 | } |
||
| 172 | |||
| 173 | $this->extend('updateFoxyStripePurchaseFormFields', $fields); |
||
| 174 | |||
| 175 | return $fields; |
||
| 176 | } |
||
| 177 | |||
| 245 | } |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.