Conditions | 11 |
Paths | 2 |
Total Lines | 36 |
Code Lines | 26 |
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 |
||
38 | public function render($param, $url) |
||
39 | { |
||
40 | if (is_array($param)) { |
||
41 | $func = null; |
||
42 | $length = null; |
||
43 | $imgClass = null; |
||
44 | $inputClass = null; |
||
45 | foreach ($param as $key => $val) { |
||
46 | if ('type' == $key) { |
||
47 | $func = $key; |
||
48 | } |
||
49 | if ('length' == $key) { |
||
50 | $length = $key; |
||
51 | } |
||
52 | if ('class' == $key && is_array($key)) { |
||
53 | if (array_key_exists('img', $key)) { |
||
54 | $imgClass = $key['img']; |
||
55 | } elseif (array_key_exists('input', $key)) { |
||
56 | $inputClass = $key['input']; |
||
57 | } |
||
58 | } else { |
||
59 | $imgClass = $inputClass = $key; |
||
60 | } |
||
61 | } |
||
62 | if (method_exists($this, $func)) { |
||
63 | $response = $this->$key($length, $imgClass).$this->input($inputClass); |
||
|
|||
64 | } else { |
||
65 | throw new Exception("Error Processing Captcha Method", 1); |
||
66 | } |
||
67 | } elseif (is_numeric($param)) { |
||
68 | $response = $this->img($param).$this->input(); |
||
69 | } else { |
||
70 | throw new Exception("Error Processing Captcha Parameters", 1); |
||
71 | } |
||
72 | |||
73 | return '<form method="post" action="'.$url.'">'.$response.'</form>'; |
||
74 | } |
||
125 |