Conditions | 27 |
Paths | 3328 |
Total Lines | 158 |
Code Lines | 95 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
8 | function sub_domains_edit($domain, $sub_domain_id=false) { |
||
9 | global $admin, $err, $oldid, $isedit; |
||
10 | |||
11 | $dom=new m_dom(); |
||
12 | $dom->lock(); |
||
13 | if (!$r=$dom->get_domain_all($domain)) { |
||
14 | $error=$err->errstr(); |
||
15 | } |
||
16 | /* |
||
17 | if (! empty($sub)) { |
||
18 | if (!$sd=$dom->get_sub_domain_all($domain,$sub,$type,$value)) { |
||
19 | $error=$err->errstr(); |
||
20 | } |
||
21 | } |
||
22 | */ |
||
23 | $sd=$dom->get_sub_domain_all($sub_domain_id); |
||
24 | |||
25 | $type=$sd['type']; |
||
26 | $sub=$sd['name']; |
||
27 | |||
28 | $dom->unlock(); |
||
29 | ?> |
||
30 | |||
31 | <form action="dom_subdoedit.php" method="post" name="main" id="main"> |
||
32 | <?php csrf_get(); ?> |
||
33 | <table border="0"> |
||
34 | <tr> |
||
35 | <td> |
||
36 | <input type="hidden" name="domain" value="<?php ehe($domain) ?>" /> |
||
37 | <input type="hidden" name="sub_domain_id" value="<?php ehe($sub_domain_id); ?>" /> |
||
|
|||
38 | <input type="hidden" name="action" value="add" /> |
||
39 | <?php |
||
40 | if ($isedit) { |
||
41 | __("Edit a subdomain:"); |
||
42 | } else { |
||
43 | __("Create a subdomain:"); |
||
44 | } |
||
45 | ?></td><td> |
||
46 | <input type="text" class="int" name="sub" style="text-align:right" value="<?php ehe($sub); ?>" size="22" id="sub" /><span class="int" id="newsubname">.<?php ehe($domain); ?></span></td> |
||
47 | </tr> |
||
48 | <?php |
||
49 | $first_advanced=true; |
||
50 | $lst_advanced=array(); |
||
51 | foreach($dom->domains_type_lst() as $dt) { |
||
52 | // If this type is disabled AND it's not the type in use here, continue |
||
53 | if ( $dt['enable'] == 'NONE' && strtoupper($type)!=strtoupper($dt['name'])) continue ; |
||
54 | // If this type is only for ADMIN and i'm not an admin, continue (oldid is to check if we are an admin who take user identity) |
||
55 | if (( $dt['enable'] == 'ADMIN') && (! $admin->enabled and ! intval($oldid))) continue; |
||
56 | |||
57 | if ( (! $r['dns'] ) and ($dt['need_dns']) ) continue; |
||
58 | $targval=(strtoupper($type)==strtoupper($dt['name']))?$sd['dest']:''; |
||
59 | |||
60 | if ($dt['advanced']) { |
||
61 | $lst_advanced[]=$dt['name']; |
||
62 | if ($first_advanced) { |
||
63 | $first_advanced=false; |
||
64 | echo "<tr><td colspan=\"2\" class=\"advdom\"></td></tr>"; |
||
65 | echo "<tr id='domtype_show' onClick=\"domtype_advanced_show();\"><td colspan='2'><a href=\"javascript:domtype_advanced_show();\"><b>+ "; __("Show advanced options"); echo "</b></a></td></tr>"; |
||
66 | echo "<tr id='domtype_hide' onClick=\"domtype_advanced_hide();\" style='display:none'><td colspan='2'><a href=\"javascript:domtype_advanced_hide();\"><b>- "; __("Hide advanced options"); echo "</b></a></td></tr>"; |
||
67 | echo "<tr><td colspan=\"2\" class=\"advdom\"></td></tr>"; |
||
68 | } |
||
69 | } |
||
70 | ?> |
||
71 | <tr id="tr_<?php echo $dt['name']; ?>"> |
||
72 | <td> |
||
73 | <input type="radio" id="r_<?php ehe($dt['name']); ?>" class="inc" name="type" value="<?php ehe($dt['name']); ?>" <?php cbox(strtoupper($type)==strtoupper($dt['name'])); ?> OnClick="getElementById('t_<?php ehe($dt['name']); ?>').focus();"/> |
||
74 | <label for="r_<?php ehe($dt['name']); ?>"><?php __($dt['description']); ?></label> |
||
75 | </td> |
||
76 | <td> |
||
77 | <?php |
||
78 | |||
79 | switch ($dt['target']) { |
||
80 | case "DIRECTORY": ?> |
||
81 | <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval); ?>" size="28" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" /> |
||
82 | <?php display_browser( $targval , "t_".$dt['name'] ); |
||
83 | break; |
||
84 | case "URL": ?> |
||
85 | <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe( (empty($targval)?'http://':$targval) ); ?>" size="50" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" /> |
||
86 | <small><?php __("(enter an URL here)"); ?></small><?php |
||
87 | break;; |
||
88 | case 'IP':?> |
||
89 | <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval); ?>" size="16" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" /> |
||
90 | <small><?php __("(enter an IPv4 address, for example 192.168.1.2)"); ?></small><?php |
||
91 | break; |
||
92 | case 'IPV6':?> |
||
93 | <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval); ?>" size="32" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" /> |
||
94 | <small><?php __("(enter an IPv6 address, for example 2001:0910::0)"); ?></small><?php |
||
95 | break; |
||
96 | case 'TXT':?> |
||
97 | <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval);?>" size="32" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" /> |
||
98 | <small><?php __("(enter a TXT content for this domain)"); ?></small><?php |
||
99 | break; |
||
100 | case 'DOMAIN':?> |
||
101 | <input type="text" class="int" name="t_<?php ehe($dt['name']); ?>" id="t_<?php ehe($dt['name']); ?>" value="<?php ehe($targval);?>" size="32" onKeyPress="getElementById('r_<?php ehe($dt['name']); ?>').checked=true;" /> |
||
102 | <small><?php __("(enter a domain name or subdomain)"); ?></small><?php |
||
103 | break; |
||
104 | case "NONE": |
||
105 | default: |
||
106 | break; |
||
107 | } // switch ?> |
||
108 | </td> |
||
109 | </tr> |
||
110 | <?php } // foreach ?> |
||
111 | |||
112 | <tr class="trbtn"> |
||
113 | <td colspan="2"><input type="submit" class="inb ok" name="add" onclick='return check_type_selected();' value="<?php |
||
114 | if ($isedit) { |
||
115 | __("Edit this subdomain"); |
||
116 | } else { |
||
117 | __("Add this subdomain"); |
||
118 | } |
||
119 | ?>" /></td> |
||
120 | </tr> |
||
121 | </table> |
||
122 | </form> |
||
123 | |||
124 | <script type="text/javascript"> |
||
125 | |||
126 | function check_type_selected() { |
||
127 | if ( $('input[name=type]:radio:checked').val() ) { |
||
128 | // there is a value |
||
129 | var ll = $('input[name=type]:radio:checked').val(); |
||
130 | var tt = $('#t_'+ll); |
||
131 | if ( tt.length == 0 ) { |
||
132 | // this element do not exist, so OK |
||
133 | return true; |
||
134 | } |
||
135 | if ( tt.val() == '' ) { |
||
136 | alert("<?php __("Missing value for this sub-domain"); ?>"); |
||
137 | return false; |
||
138 | } |
||
139 | |||
140 | return true; |
||
141 | } |
||
142 | alert("<?php __("Please select a type for this sub-domain"); ?>"); |
||
143 | return false; |
||
144 | } |
||
145 | |||
146 | function domtype_advanced_hide() { |
||
147 | <?php foreach ($lst_advanced as $adv) echo "$(\"#tr_$adv\").hide();\n"?> |
||
148 | $("#domtype_show").show(); |
||
149 | $("#domtype_hide").hide(); |
||
150 | } |
||
151 | function domtype_advanced_show() { |
||
152 | <?php foreach ($lst_advanced as $adv) echo "$(\"#tr_$adv\").show();\n"?> |
||
153 | $("#domtype_show").hide(); |
||
154 | $("#domtype_hide").show(); |
||
155 | } |
||
156 | |||
157 | <?php if (isset($type) && in_array($type, $lst_advanced) ) { // if it's an edit of an advanced option, we need to show the advanced options ?> |
||
158 | domtype_advanced_show(); |
||
159 | <?php } else { ?> |
||
160 | domtype_advanced_hide(); |
||
161 | <?php } // if advanced ?> |
||
162 | |||
163 | </script> |
||
164 | <?php |
||
165 | } // sub_domains_edit |
||
166 | ?> |
||
168 |
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: