Conditions | 2 |
Paths | 2 |
Total Lines | 195 |
Code Lines | 148 |
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 |
||
40 | public function get_settings() { |
||
41 | |||
42 | $currency_code_options = get_woocommerce_currencies(); |
||
43 | |||
44 | foreach ( $currency_code_options as $code => $name ) { |
||
45 | $currency_code_options[ $code ] = $name . ' (' . get_woocommerce_currency_symbol( $code ) . ')'; |
||
46 | } |
||
47 | |||
48 | $settings = apply_filters( 'woocommerce_general_settings', array( |
||
49 | |||
50 | array( 'title' => __( 'General Options', 'woocommerce' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ), |
||
51 | |||
52 | array( |
||
53 | 'title' => __( 'Base Location', 'woocommerce' ), |
||
54 | 'desc' => __( 'This is the base location for your business. Tax rates will be based on this country.', 'woocommerce' ), |
||
55 | 'id' => 'woocommerce_default_country', |
||
56 | 'css' => 'min-width:350px;', |
||
57 | 'default' => 'GB', |
||
58 | 'type' => 'single_select_country', |
||
59 | 'desc_tip' => true, |
||
60 | ), |
||
61 | |||
62 | array( |
||
63 | 'title' => __( 'Selling Location(s)', 'woocommerce' ), |
||
64 | 'desc' => __( 'This option lets you limit which countries you are willing to sell to.', 'woocommerce' ), |
||
65 | 'id' => 'woocommerce_allowed_countries', |
||
66 | 'default' => 'all', |
||
67 | 'type' => 'select', |
||
68 | 'class' => 'wc-enhanced-select', |
||
69 | 'css' => 'min-width: 350px;', |
||
70 | 'desc_tip' => true, |
||
71 | 'options' => array( |
||
72 | 'all' => __( 'Sell to All Countries', 'woocommerce' ), |
||
73 | 'all_except' => __( 'Sell to All Countries, Except For…', 'woocommerce' ), |
||
74 | 'specific' => __( 'Sell to Specific Countries', 'woocommerce' ) |
||
75 | ) |
||
76 | ), |
||
77 | |||
78 | array( |
||
79 | 'title' => __( 'Sell to All Countries, Except For…', 'woocommerce' ), |
||
80 | 'desc' => '', |
||
81 | 'id' => 'woocommerce_all_except_countries', |
||
82 | 'css' => 'min-width: 350px;', |
||
83 | 'default' => '', |
||
84 | 'type' => 'multi_select_countries' |
||
85 | ), |
||
86 | |||
87 | array( |
||
88 | 'title' => __( 'Sell to Specific Countries', 'woocommerce' ), |
||
89 | 'desc' => '', |
||
90 | 'id' => 'woocommerce_specific_allowed_countries', |
||
91 | 'css' => 'min-width: 350px;', |
||
92 | 'default' => '', |
||
93 | 'type' => 'multi_select_countries' |
||
94 | ), |
||
95 | |||
96 | array( |
||
97 | 'title' => __( 'Shipping Location(s)', 'woocommerce' ), |
||
98 | 'desc' => __( 'Choose which countries you want to ship to, or choose to ship to all locations you sell to.', 'woocommerce' ), |
||
99 | 'id' => 'woocommerce_ship_to_countries', |
||
100 | 'default' => '', |
||
101 | 'type' => 'select', |
||
102 | 'class' => 'wc-enhanced-select', |
||
103 | 'desc_tip' => true, |
||
104 | 'options' => array( |
||
105 | '' => __( 'Ship to all countries you sell to', 'woocommerce' ), |
||
106 | 'all' => __( 'Ship to all countries', 'woocommerce' ), |
||
107 | 'specific' => __( 'Ship to specific countries only', 'woocommerce' ), |
||
108 | 'disabled' => __( 'Disable shipping & shipping calculations', 'woocommerce' ), |
||
109 | ) |
||
110 | ), |
||
111 | |||
112 | array( |
||
113 | 'title' => __( 'Ship to Specific Countries', 'woocommerce' ), |
||
114 | 'desc' => '', |
||
115 | 'id' => 'woocommerce_specific_ship_to_countries', |
||
116 | 'css' => '', |
||
117 | 'default' => '', |
||
118 | 'type' => 'multi_select_countries' |
||
119 | ), |
||
120 | |||
121 | array( |
||
122 | 'title' => __( 'Default Customer Location', 'woocommerce' ), |
||
123 | 'id' => 'woocommerce_default_customer_address', |
||
124 | 'desc_tip' => __( 'This option determines a customers default location. The MaxMind GeoLite Database will be periodically downloaded to your wp-content directory if using geolocation.', 'woocommerce' ), |
||
125 | 'default' => 'geolocation', |
||
126 | 'type' => 'select', |
||
127 | 'class' => 'wc-enhanced-select', |
||
128 | 'options' => array( |
||
129 | '' => __( 'No location by default', 'woocommerce' ), |
||
130 | 'base' => __( 'Shop base address', 'woocommerce' ), |
||
131 | 'geolocation' => __( 'Geolocate', 'woocommerce' ), |
||
132 | 'geolocation_ajax' => __( 'Geolocate (with page caching support)', 'woocommerce' ), |
||
133 | ), |
||
134 | ), |
||
135 | |||
136 | array( |
||
137 | 'title' => __( 'Enable Taxes', 'woocommerce' ), |
||
138 | 'desc' => __( 'Enable taxes and tax calculations', 'woocommerce' ), |
||
139 | 'id' => 'woocommerce_calc_taxes', |
||
140 | 'default' => 'no', |
||
141 | 'type' => 'checkbox' |
||
142 | ), |
||
143 | |||
144 | array( |
||
145 | 'title' => __( 'Store Notice', 'woocommerce' ), |
||
146 | 'desc' => __( 'Enable site-wide store notice text', 'woocommerce' ), |
||
147 | 'id' => 'woocommerce_demo_store', |
||
148 | 'default' => 'no', |
||
149 | 'type' => 'checkbox' |
||
150 | ), |
||
151 | |||
152 | array( |
||
153 | 'title' => __( 'Store Notice Text', 'woocommerce' ), |
||
154 | 'desc' => '', |
||
155 | 'id' => 'woocommerce_demo_store_notice', |
||
156 | 'default' => __( 'This is a demo store for testing purposes — no orders shall be fulfilled.', 'woocommerce' ), |
||
157 | 'type' => 'textarea', |
||
158 | 'css' => 'width:350px; height: 65px;', |
||
159 | 'autoload' => false |
||
160 | ), |
||
161 | |||
162 | array( 'type' => 'sectionend', 'id' => 'general_options'), |
||
163 | |||
164 | array( 'title' => __( 'Currency Options', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'The following options affect how prices are displayed on the frontend.', 'woocommerce' ), 'id' => 'pricing_options' ), |
||
165 | |||
166 | array( |
||
167 | 'title' => __( 'Currency', 'woocommerce' ), |
||
168 | 'desc' => __( 'This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.', 'woocommerce' ), |
||
169 | 'id' => 'woocommerce_currency', |
||
170 | 'css' => 'min-width:350px;', |
||
171 | 'default' => 'GBP', |
||
172 | 'type' => 'select', |
||
173 | 'class' => 'wc-enhanced-select', |
||
174 | 'desc_tip' => true, |
||
175 | 'options' => $currency_code_options |
||
176 | ), |
||
177 | |||
178 | array( |
||
179 | 'title' => __( 'Currency Position', 'woocommerce' ), |
||
180 | 'desc' => __( 'This controls the position of the currency symbol.', 'woocommerce' ), |
||
181 | 'id' => 'woocommerce_currency_pos', |
||
182 | 'css' => 'min-width:350px;', |
||
183 | 'class' => 'wc-enhanced-select', |
||
184 | 'default' => 'left', |
||
185 | 'type' => 'select', |
||
186 | 'options' => array( |
||
187 | 'left' => __( 'Left', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . '99.99)', |
||
188 | 'right' => __( 'Right', 'woocommerce' ) . ' (99.99' . get_woocommerce_currency_symbol() . ')', |
||
189 | 'left_space' => __( 'Left with space', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ' 99.99)', |
||
190 | 'right_space' => __( 'Right with space', 'woocommerce' ) . ' (99.99 ' . get_woocommerce_currency_symbol() . ')' |
||
191 | ), |
||
192 | 'desc_tip' => true, |
||
193 | ), |
||
194 | |||
195 | array( |
||
196 | 'title' => __( 'Thousand Separator', 'woocommerce' ), |
||
197 | 'desc' => __( 'This sets the thousand separator of displayed prices.', 'woocommerce' ), |
||
198 | 'id' => 'woocommerce_price_thousand_sep', |
||
199 | 'css' => 'width:50px;', |
||
200 | 'default' => ',', |
||
201 | 'type' => 'text', |
||
202 | 'desc_tip' => true, |
||
203 | ), |
||
204 | |||
205 | array( |
||
206 | 'title' => __( 'Decimal Separator', 'woocommerce' ), |
||
207 | 'desc' => __( 'This sets the decimal separator of displayed prices.', 'woocommerce' ), |
||
208 | 'id' => 'woocommerce_price_decimal_sep', |
||
209 | 'css' => 'width:50px;', |
||
210 | 'default' => '.', |
||
211 | 'type' => 'text', |
||
212 | 'desc_tip' => true, |
||
213 | ), |
||
214 | |||
215 | array( |
||
216 | 'title' => __( 'Number of Decimals', 'woocommerce' ), |
||
217 | 'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'woocommerce' ), |
||
218 | 'id' => 'woocommerce_price_num_decimals', |
||
219 | 'css' => 'width:50px;', |
||
220 | 'default' => '2', |
||
221 | 'desc_tip' => true, |
||
222 | 'type' => 'number', |
||
223 | 'custom_attributes' => array( |
||
224 | 'min' => 0, |
||
225 | 'step' => 1 |
||
226 | ) |
||
227 | ), |
||
228 | |||
229 | array( 'type' => 'sectionend', 'id' => 'pricing_options' ) |
||
230 | |||
231 | ) ); |
||
232 | |||
233 | return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); |
||
234 | } |
||
235 | |||
264 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.