| Conditions | 21 |
| Paths | 338 |
| Total Lines | 97 |
| Code Lines | 57 |
| Lines | 33 |
| Ratio | 34.02 % |
| 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 |
||
| 131 | public function genRandomToFile( |
||
| 132 | $min_elem_cnt = 3, |
||
| 133 | $max_elem_cnt = 10, |
||
| 134 | $threshold = 32768, |
||
| 135 | $lim_depth = 3, |
||
| 136 | $lim_elements = 10000, |
||
| 137 | $root = '' |
||
| 138 | ) { |
||
| 139 | if ($lim_elements) { |
||
| 140 | $this->lim_elements = $lim_elements; |
||
| 141 | } |
||
| 142 | View Code Duplication | if ($lim_depth < 1 |
|
| 143 | || $this->lim_elements < 0 |
||
| 144 | || $this->max_arr_key < 0 |
||
| 145 | || $this->max_arr_key < $this->min_arr_key |
||
| 146 | || $this->max_arr_val < 0 |
||
| 147 | || $this->max_arr_val < $this->min_arr_val |
||
| 148 | ) { |
||
| 149 | return false; |
||
| 150 | } |
||
| 151 | |||
| 152 | if (!$oh = $fh = $this->file_handler) { |
||
| 153 | $this->openOutputFile(); |
||
| 154 | $fh = $this->file_handler; |
||
| 155 | $signal = 'init'; |
||
| 156 | \call_user_func($this->fn_file_output, |
||
| 157 | \compact('signal', 'fh', 'threshold', 'lim_depth', 'root') |
||
| 158 | ); |
||
| 159 | } |
||
| 160 | |||
| 161 | $elem_cnt = mt_rand($min_elem_cnt, $max_elem_cnt); |
||
| 162 | if ($elem_cnt > $this->lim_elements) { |
||
| 163 | $elem_cnt = $this->lim_elements; |
||
| 164 | } |
||
| 165 | |||
| 166 | $this->lim_elements -= $elem_cnt; |
||
| 167 | |||
| 168 | $signal = 'open'; |
||
| 169 | \call_user_func($this->fn_file_output, |
||
| 170 | \compact('signal', 'fh', 'elem_cnt', 'lim_depth', 'root') |
||
| 171 | ); |
||
| 172 | |||
| 173 | $signal = 'next'; |
||
| 174 | |||
| 175 | foreach ($this->genBigRange($elem_cnt) as $k => $v) { |
||
| 176 | if ($this->keys_model) { |
||
| 177 | if ($this->keys_model === 3) { |
||
| 178 | $k = \call_user_func($this->fn_gen_key, |
||
| 179 | \compact('k', 'v', 'threshold', 'lim_depth', 'root') |
||
| 180 | ); |
||
| 181 | } else { |
||
| 182 | $k = \mt_rand($this->min_arr_key, $this->max_arr_key); |
||
| 183 | if ($this->keys_model === 2) { |
||
| 184 | $k = $this->genRandomStr($k, 1); |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | View Code Duplication | if ($v > $threshold || $lim_depth < 2 || $this->lim_elements < 2) { |
|
| 190 | if ($this->values_model) { |
||
| 191 | if ($this->values_model == 3) { |
||
| 192 | $v = \call_user_func($this->fn_gen_value, |
||
| 193 | \compact('k', 'v', 'threshold', 'lim_depth', 'root') |
||
| 194 | ); |
||
| 195 | } else { |
||
| 196 | $v = mt_rand($this->min_arr_val, $this->max_arr_val); |
||
| 197 | if ($this->values_model == 2) { |
||
| 198 | $v = $this->genRandomStr($v, 2); |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | } else { |
||
| 203 | $this->genRandomToFile( |
||
| 204 | $min_elem_cnt, |
||
| 205 | $max_elem_cnt, |
||
| 206 | $threshold, |
||
| 207 | $lim_depth - 1, |
||
| 208 | 0, |
||
| 209 | $k |
||
| 210 | ); |
||
| 211 | continue; |
||
| 212 | } |
||
| 213 | |||
| 214 | \call_user_func($this->fn_file_output, |
||
| 215 | \compact('signal', 'k', 'v', 'fh', 'lim_depth', 'root') |
||
| 216 | ); |
||
| 217 | } |
||
| 218 | |||
| 219 | $signal = 'close'; |
||
| 220 | \call_user_func($this->fn_file_output, |
||
| 221 | \compact('signal', 'fh', 'elem_cnt', 'lim_depth', 'root') |
||
| 222 | ); |
||
| 223 | |||
| 224 | if (!$oh) { |
||
| 225 | $this->closeOutputFile(); |
||
| 226 | } |
||
| 227 | return true; |
||
| 228 | } |
||
| 278 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..