Conditions | 30 |
Paths | 4800 |
Total Lines | 98 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Tests | 2 |
CRAP Score | 30 |
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 |
||
98 | 1 | function format_number_sugarpdf($amount, $round = null, $decimals = null, $params = array()) { |
|
99 | global $app_strings, $current_user, $sugar_config, $locale; |
||
100 | static $current_users_currency = null; |
||
101 | static $last_override_currency = null; |
||
102 | static $override_currency_id = null; |
||
103 | static $currency; |
||
104 | |||
105 | $seps = get_number_seperators(); |
||
106 | $num_grp_sep = $seps[0]; |
||
107 | $dec_sep = $seps[1]; |
||
108 | |||
109 | // cn: bug 8522 - sig digits not honored in pdfs |
||
110 | if(is_null($decimals)) { |
||
111 | $decimals = $locale->getPrecision(); |
||
112 | } |
||
113 | if(is_null($round)) { |
||
114 | $round = $locale->getPrecision(); |
||
115 | } |
||
116 | |||
117 | // only create a currency object if we need it |
||
118 | if((!empty($params['currency_symbol']) && $params['currency_symbol']) || |
||
119 | (!empty($params['convert']) && $params['convert']) || |
||
120 | (!empty($params['currency_id']))) { |
||
121 | // if we have an override currency_id |
||
122 | if(!empty($params['currency_id'])) { |
||
123 | if($override_currency_id != $params['currency_id']) { |
||
124 | $override_currency_id = $params['currency_id']; |
||
125 | $currency = new Currency(); |
||
126 | $currency->retrieve($override_currency_id); |
||
127 | $last_override_currency = $currency; |
||
128 | } else { |
||
129 | $currency = $last_override_currency; |
||
130 | } |
||
131 | |||
132 | } elseif(!isset($current_users_currency)) { // else use current user's |
||
133 | $current_users_currency = new Currency(); |
||
134 | if($current_user->getPreference('currency')) $current_users_currency->retrieve($current_user->getPreference('currency')); |
||
135 | else $current_users_currency->retrieve('-99'); // use default if none set |
||
136 | $currency = $current_users_currency; |
||
137 | } |
||
138 | } |
||
139 | if(!empty($params['convert']) && $params['convert']) { |
||
140 | $amount = $currency->convertFromDollar($amount, 6); |
||
141 | } |
||
142 | |||
143 | if(!empty($params['currency_symbol']) && $params['currency_symbol']) { |
||
144 | if(!empty($params['symbol_override'])) { |
||
145 | $symbol = $params['symbol_override']; |
||
146 | } |
||
147 | |||
148 | // BEGIN SUGARPDF |
||
149 | /*elseif(!empty($params['type']) && $params['type'] == 'pdf') { |
||
150 | $symbol = $currency->getPdfCurrencySymbol(); |
||
151 | $symbol_space = false; |
||
152 | }*/ |
||
153 | elseif(!empty($params['type']) && $params['type'] == 'sugarpdf') { |
||
154 | $symbol = $currency->symbol; |
||
155 | $symbol_space = false; |
||
156 | } |
||
157 | // END SUGARPDF |
||
158 | |||
159 | else { |
||
160 | if(empty($currency->symbol)) |
||
161 | $symbol = $currency->getDefaultCurrencySymbol(); |
||
162 | else |
||
163 | $symbol = $currency->symbol; |
||
164 | $symbol_space = true; |
||
165 | } |
||
166 | } else { |
||
167 | $symbol = ''; |
||
168 | } |
||
169 | |||
170 | if(isset($params['charset_convert'])) { |
||
171 | $symbol = $locale->translateCharset($symbol, 'UTF-8', $locale->getExportCharset()); |
||
172 | } |
||
173 | |||
174 | if(empty($params['human'])) { |
||
175 | $amount = number_format(round($amount, $round), $decimals, $dec_sep, $num_grp_sep); |
||
176 | $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true)); |
||
177 | } else { |
||
178 | // If amount is more greater than a thousand(positive or negative) |
||
179 | if(strpos($amount, '.') > 0) { |
||
180 | $checkAmount = strlen(substr($amount, 0, strpos($amount, '.'))); |
||
181 | } |
||
182 | |||
183 | if($checkAmount >= 1000 || $checkAmount <= -1000) { |
||
184 | $amount = round(($amount / 1000), 0); |
||
185 | $amount = $amount . 'k'; |
||
186 | $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true)); |
||
187 | } else { |
||
188 | $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true)); |
||
189 | } |
||
190 | } |
||
191 | |||
192 | if(!empty($params['percentage']) && $params['percentage']) $amount .= $app_strings['LBL_PERCENTAGE_SYMBOL']; |
||
193 | return $amount; |
||
194 | |||
195 | 1 | } //end function format_number |
|
196 | ?> |
||
197 |