Conditions | 6 |
Paths | 18 |
Total Lines | 64 |
Code Lines | 45 |
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 |
||
60 | public function updateCMSFields(FieldList $fields) |
||
61 | { |
||
62 | $additionalWhereForDefault = ""; |
||
63 | $fields->removeByName("ExcludedFrom"); |
||
64 | $fields->removeByName("AdditionalTax"); |
||
65 | $tabName = "Root.Tax"; |
||
66 | if ($this->owner instanceof ProductVariation) { |
||
67 | $fields->addFieldToTab( |
||
68 | $tabName, |
||
69 | new LiteralField( |
||
70 | "SeeProductForAdditionalTax", |
||
71 | _t("GSTTaxModifier.SEE_PARENT", "See parent Product for Additional Tax") |
||
72 | ) |
||
73 | ); |
||
74 | } else { |
||
75 | //additional taxes |
||
76 | $additionalOptions = GSTTaxModifierOptions::get()->filter(array("DoesNotApplyToAllProducts" => 1)); |
||
77 | if ($additionalOptions->count()) { |
||
78 | $additionalOptionsList = $additionalOptions->map()->toArray(); |
||
79 | $fields->addFieldToTab( |
||
80 | $tabName, |
||
81 | new CheckboxSetField( |
||
82 | "AdditionalTax", |
||
83 | _t("GSTTaxMofidifier.ADDITIONAL_TAXES", "Additional taxes ..."), |
||
84 | $additionalOptionsList |
||
85 | ) |
||
86 | ); |
||
87 | } |
||
88 | } |
||
89 | if ($this->owner instanceof ProductVariation) { |
||
90 | $fields->addFieldToTab( |
||
91 | $tabName, |
||
92 | new LiteralField( |
||
93 | "SeeProductForExcludedFrom", |
||
94 | _t("GSTTaxModifier.SEE_PARRENT", "See parent product for excluded taxes") |
||
95 | ) |
||
96 | ); |
||
97 | } else { |
||
98 | //excluded options |
||
99 | $excludedOptions = GSTTaxModifierOptions::get()->filter(array("DoesNotApplyToAllProducts" => 0)); |
||
100 | if ($excludedOptions->count()) { |
||
101 | $excludedOptionsList = $excludedOptions->map()->toArray(); |
||
102 | $fields->addFieldToTab( |
||
103 | $tabName, |
||
104 | new CheckboxSetField( |
||
105 | "ExcludedFrom", |
||
106 | _t("GSTTaxMofidifier.EXCLUDE_TAXES", "Taxes that do not apply ..."), |
||
107 | $excludedOptionsList |
||
108 | ) |
||
109 | ); |
||
110 | $additionalWhereForDefault = " \"GSTTaxModifierOptions\".\"ID\" NOT IN (".implode(", ", $excludedOptions->map("ID", "ID")->toArray()).")"; |
||
111 | } |
||
112 | } |
||
113 | //default options |
||
114 | $defaultOptions = GSTTaxModifierOptions::get() |
||
115 | ->filter(array("DoesNotApplyToAllProducts" => 0)) |
||
116 | ->where($additionalWhereForDefault); |
||
117 | if ($defaultOptions->count()) { |
||
118 | $fields->addFieldToTab( |
||
119 | $tabName, |
||
120 | new ReadonlyField("AlwaysApplies", "+ ".implode(", ", $defaultOptions->map()->toArray()).".") |
||
121 | ); |
||
122 | } |
||
123 | } |
||
124 | |||
145 |
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.