Conditions | 18 |
Paths | 112 |
Total Lines | 104 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 342 |
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 |
||
5 | function generateFieldDefsJS2() |
||
6 | { |
||
7 | global $app_list_strings, $beanList, $beanFiles; |
||
8 | |||
9 | |||
10 | $badFields = array( |
||
11 | 'account_description', |
||
12 | 'contact_id', |
||
13 | 'lead_id', |
||
14 | 'opportunity_amount', |
||
15 | 'opportunity_id', |
||
16 | 'opportunity_name', |
||
17 | 'opportunity_role_id', |
||
18 | 'opportunity_role_fields', |
||
19 | 'opportunity_role', |
||
20 | 'campaign_id', |
||
21 | // User objects |
||
22 | 'id', |
||
23 | 'user_preferences', |
||
24 | 'accept_status', |
||
25 | 'user_hash', |
||
26 | 'authenticate_id', |
||
27 | 'sugar_login', |
||
28 | 'reports_to_id', |
||
29 | 'reports_to_name', |
||
30 | 'is_admin', |
||
31 | 'receive_notifications', |
||
32 | 'modified_user_id', |
||
33 | 'modified_by_name', |
||
34 | 'created_by', |
||
35 | 'created_by_name', |
||
36 | 'accept_status_id', |
||
37 | 'accept_status_name', |
||
38 | ); |
||
39 | |||
40 | $loopControl = array(); |
||
41 | $prefixes = array(); |
||
42 | |||
43 | foreach ($app_list_strings['moduleList'] as $key => $name) { |
||
44 | if (isset($beanList[$key]) && isset($beanFiles[$beanList[$key]]) && !str_begin($key, 'AOW_')) { |
||
45 | |||
46 | require_once($beanFiles[$beanList[$key]]); |
||
47 | $focus = new $beanList[$key]; |
||
48 | $loopControl[$key][$key] = $focus; |
||
49 | $prefixes[$key] = strtolower($focus->object_name) . '_'; |
||
50 | if ($focus->object_name == 'Case') $prefixes[$key] = 'a' . strtolower($focus->object_name) . '_'; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | $contact = new Contact(); |
||
55 | $lead = new Lead(); |
||
56 | $prospect = new Prospect(); |
||
57 | |||
58 | $loopControl['Contacts'] = array( |
||
59 | 'Contacts' => $contact, |
||
60 | 'Leads' => $lead, |
||
61 | 'Prospects' => $prospect, |
||
62 | ); |
||
63 | |||
64 | $prefixes['Users'] = 'contact_user_'; |
||
65 | |||
66 | |||
67 | $collection = array(); |
||
68 | foreach ($loopControl as $collectionKey => $beans) { |
||
69 | $collection[$collectionKey] = array(); |
||
70 | foreach ($beans as $beankey => $bean) { |
||
71 | |||
72 | foreach ($bean->field_defs as $key => $field_def) { |
||
73 | if ( /*($field_def['type'] == 'relate' && empty($field_def['custom_type'])) ||*/ |
||
74 | ($field_def['type'] == 'assigned_user_name' || $field_def['type'] == 'link') || |
||
75 | ($field_def['type'] == 'bool') || |
||
76 | (in_array($field_def['name'], $badFields)) |
||
77 | ) { |
||
78 | continue; |
||
79 | } |
||
80 | if (!isset($field_def['vname'])) { |
||
|
|||
81 | //echo $key; |
||
82 | } |
||
83 | // valid def found, process |
||
84 | $optionKey = strtolower("{$prefixes[$collectionKey]}{$key}"); |
||
85 | if (isset($field_def['vname'])) { |
||
86 | $optionLabel = preg_replace('/:$/', "", translate($field_def['vname'], $beankey)); |
||
87 | } else { |
||
88 | $optionLabel = preg_replace('/:$/', "", $field_def['name']); |
||
89 | } |
||
90 | $dup = 1; |
||
91 | foreach ($collection[$collectionKey] as $value) { |
||
92 | if ($value['name'] == $optionKey) { |
||
93 | $dup = 0; |
||
94 | break; |
||
95 | } |
||
96 | } |
||
97 | if ($dup) |
||
98 | $collection[$collectionKey][] = array("name" => $optionKey, "value" => $optionLabel); |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | |||
103 | $json = getJSONobj(); |
||
104 | $ret = "var field_defs = "; |
||
105 | $ret .= $json->encode($collection, false); |
||
106 | $ret .= ";"; |
||
107 | return $ret; |
||
108 | } |
||
109 | |||
146 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.