Conditions | 10 |
Paths | 10 |
Total Lines | 28 |
Code Lines | 21 |
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 |
||
58 | public function Field($properties = array()) { |
||
59 | $options = ''; |
||
60 | foreach($this->getSource() as $value => $title) { |
||
61 | if(is_array($title)) { |
||
62 | $options .= "<optgroup label=\"$value\">"; |
||
63 | foreach($title as $value2 => $title2) { |
||
64 | $disabled = ''; |
||
65 | if( array_key_exists($value, $this->disabledItems) |
||
66 | && is_array($this->disabledItems[$value]) |
||
67 | && in_array($value2, $this->disabledItems[$value]) ){ |
||
68 | $disabled = 'disabled="disabled"'; |
||
69 | } |
||
70 | $selected = $value2 == $this->value ? " selected=\"selected\"" : ""; |
||
71 | $options .= "<option$selected value=\"$value2\" $disabled>$title2</option>"; |
||
72 | } |
||
73 | $options .= "</optgroup>"; |
||
74 | } else { // Fall back to the standard dropdown field |
||
75 | $disabled = ''; |
||
76 | if( in_array($value, $this->disabledItems) ){ |
||
77 | $disabled = 'disabled="disabled"'; |
||
78 | } |
||
79 | $selected = $value == $this->value ? " selected=\"selected\"" : ""; |
||
80 | $options .= "<option$selected value=\"$value\" $disabled>$title</option>"; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | return FormField::create_tag('select', $this->getAttributes(), $options); |
||
85 | } |
||
86 | |||
135 |