Conditions | 10 |
Paths | 32 |
Total Lines | 53 |
Code Lines | 38 |
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 |
||
25 | public function __construct($optionalController = null, $name, FieldList $fields, FieldList $actions, $optionalValidator = null, $recommendedBuyables) |
||
26 | { |
||
27 | if (! ($fields instanceof FieldList)) { |
||
28 | $fields = FieldList::create(); |
||
29 | } |
||
30 | $fields->push(HeaderField::create($this->config()->get("something_recommended_text"))); |
||
31 | $productFieldList = new FieldList(); |
||
32 | foreach ($recommendedBuyables as $buyable) { |
||
33 | $template = Config::inst()->get("RecommendedProductsModifier_Form", "product_template"); |
||
34 | if ($template) { |
||
35 | $checkboxID = $buyable->ClassName."|".$buyable->ID; |
||
36 | $arrayData = new ArrayData( |
||
37 | array( |
||
38 | "Buyable" => $buyable, |
||
39 | "CheckboxID" => $checkboxID, |
||
40 | "Checkbox" => new CheckboxField($checkboxID, _t("RecommendedProductsModifier_Form.ADD", "add")) |
||
41 | ) |
||
42 | ); |
||
43 | $productFieldList->push(new LiteralField("Buyable_".$buyable->ID, $arrayData->renderWith($template))); |
||
44 | } else { |
||
45 | //foreach product in cart get recommended products |
||
46 | $imageID = $buyable->ImageID; |
||
47 | $imagePart = ''; |
||
48 | if ($buyable && $buyable->ImageID > 0) { |
||
49 | $resizedImage = $buyable->Image()->SetWidth($this->Config()->get("image_width")); |
||
50 | if (is_object($resizedImage) && $resizedImage) { |
||
51 | $imageLink = $resizedImage->Filename; |
||
52 | $imagePart = '<span class="secondPart"><img src="'.$imageLink.'" alt="'.Convert::raw2att($buyable->Title).'" /></span>'; |
||
53 | } |
||
54 | } |
||
55 | if (!$imagePart) { |
||
56 | $imagePart = '<span class="secondPart noImage">[no image available for '.$buyable->Title.']</span>'; |
||
57 | } |
||
58 | $priceAsMoney = EcommerceCurrency::get_money_object_from_order_currency($buyable->calculatedPrice()); |
||
59 | $pricePart = '<span class="firstPart">'.$priceAsMoney->NiceLongSymbol().'</span>'; |
||
60 | $title = '<a href="'.$buyable->Link().'">'.$buyable->Title.'</a>'.$pricePart.$imagePart.''; |
||
61 | $newField = new CheckboxField($buyable->ClassName."|".$buyable->ID, $title); |
||
62 | $fields->push($newField); |
||
63 | } |
||
64 | } |
||
65 | $fields->push(new CompositeField($productFieldList)); |
||
66 | if (! $actions instanceof FieldList) { |
||
67 | $actions = FieldList::create(); |
||
68 | } |
||
69 | $actions->push(FormAction::create('processOrderModifier', $this->config()->get("add_button_text"))); |
||
70 | // 6) Form construction |
||
71 | parent::__construct($optionalController, $name, $fields, $actions, $optionalValidator); |
||
72 | Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
||
73 | //Requirements::block(THIRDPARTY_DIR."/jquery/jquery.js"); |
||
74 | //Requirements::javascript(Director::protocol()."ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"); |
||
75 | Requirements::javascript("ecommerce_alsorecommended/javascript/RecommendedProductsModifier.js"); |
||
76 | Requirements::themedCSS("RecommendedProductsModifier", "ecommerce_alsrecommended"); |
||
77 | } |
||
78 | |||
112 |
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.