Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
9 | class snMath { |
||
10 | |||
11 | /** |
||
12 | * Эта функция выдает нормально распределенное случайное число с матожиднием $mu и стандартным отклонением $sigma |
||
13 | * |
||
14 | * $strict - количество $sigma, по которым идет округление функции. Т.е. $strict = 3 означает, что диапазон значений обрезается по +-3 * $sigma |
||
15 | * Используется http://ru.wikipedia.org/wiki/Преобразование_Бокса_—_Мюллера |
||
16 | * |
||
17 | * @param int $mu |
||
18 | * @param int $sigma |
||
19 | * @param bool $strict |
||
20 | * |
||
21 | * @return int |
||
22 | */ |
||
23 | public static function sn_rand_gauss($mu = 0, $sigma = 1, $strict = false) { |
||
38 | |||
39 | |||
40 | /** |
||
41 | * Функция возвращает случайное нормально распределенное целое число из указанного промежутка |
||
42 | * |
||
43 | * @param float $range_start - Начало диапазона |
||
44 | * @param float $range_end - Конец диапазона |
||
45 | * @param bool|int $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд |
||
46 | * @param int $strict - В сколько сигм надо уложить результат |
||
47 | * @param bool|false $cut_extreme - надо ли обрезать крайние значения. Например, при $strict = 2 их слишком много |
||
48 | * |
||
49 | * @return float|int |
||
50 | */ |
||
51 | public static function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) { |
||
64 | |||
65 | /** |
||
66 | * Returns average of array |
||
67 | * |
||
68 | * @param array $arr |
||
69 | * |
||
70 | * @return float |
||
71 | */ |
||
72 | public static function average($arr) { |
||
75 | |||
76 | /** |
||
77 | * Return median of values - list of them or array of values |
||
78 | * |
||
79 | * @return bool|float|mixed |
||
80 | */ |
||
81 | public static function median() { |
||
116 | |||
117 | /** |
||
118 | * Basic linear equation system solver |
||
119 | * |
||
120 | * @param array $linear |
||
121 | * @param int $from |
||
122 | * @param bool $logProcess |
||
123 | */ |
||
124 | public static function linear_calc(&$linear, $from = 0, $logProcess = false) { |
||
168 | |||
169 | /** |
||
170 | * Calculates geometric progression sum for N-th element |
||
171 | * |
||
172 | * @param int $n |
||
173 | * @param float $b1 |
||
174 | * @param float $q |
||
175 | * |
||
176 | * @return float |
||
177 | */ |
||
178 | public static function geometry_progression_sum($n, $b1, $q) { |
||
181 | |||
182 | /** |
||
183 | * Floor to less preferable value |
||
184 | * |
||
185 | * @param float $value |
||
186 | * |
||
187 | * @return float |
||
188 | */ |
||
189 | public static function sn_floor($value) { |
||
192 | |||
193 | } |
||
194 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: