Conditions | 20 |
Paths | 3457 |
Total Lines | 98 |
Code Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Tests | 59 |
CRAP Score | 20.6808 |
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 |
||
101 | 4 | function process($file, $data, $htmlVar) { |
|
102 | 4 | if(!$this->should_process)return; |
|
103 | 4 | global $odd_bg, $even_bg, $hilite_bg, $click_bg, $app_strings, $sugar_config; |
|
104 | 4 | parent::process($file, $data, $htmlVar); |
|
105 | |||
106 | 4 | $this->tpl = $file; |
|
107 | 4 | $this->data = $data; |
|
108 | |||
109 | 4 | $totalWidth = 0; |
|
110 | 4 | foreach($this->displayColumns as $name => $params) { |
|
111 | 2 | $totalWidth += $params['width']; |
|
112 | } |
||
113 | 4 | $adjustment = $totalWidth / 100; |
|
114 | |||
115 | 4 | $contextMenuObjectsTypes = array(); |
|
116 | 4 | foreach($this->displayColumns as $name => $params) { |
|
117 | 2 | $this->displayColumns[$name]['width'] = floor($this->displayColumns[$name]['width'] / $adjustment); |
|
118 | // figure out which contextMenu objectsTypes are required |
||
119 | 2 | if(!empty($params['contextMenu']['objectType'])) |
|
120 | 2 | $contextMenuObjectsTypes[$params['contextMenu']['objectType']] = true; |
|
121 | } |
||
122 | |||
123 | //Check if inline editing is enabled for list view. |
||
124 | 4 | if(!isset($sugar_config['enable_line_editing_list']) || $sugar_config['enable_line_editing_list']){ |
|
125 | 4 | $this->ss->assign('inline_edit', true); |
|
126 | } |
||
127 | |||
128 | 4 | $this->ss->assign('sugarconfig', $this->displayColumns); |
|
129 | 4 | $this->ss->assign('displayColumns', $this->displayColumns); |
|
130 | 4 | $this->ss->assign('APP',$app_strings); |
|
131 | |||
132 | 4 | $this->ss->assign('bgHilite', $hilite_bg); |
|
133 | 4 | $this->ss->assign('colCount', count($this->displayColumns) + 10); |
|
134 | 4 | $this->ss->assign('htmlVar', strtoupper($htmlVar)); |
|
135 | 4 | $this->ss->assign('moduleString', $this->moduleString); |
|
136 | 4 | $this->ss->assign('editLinkString', $app_strings['LBL_EDIT_BUTTON']); |
|
137 | 4 | $this->ss->assign('viewLinkString', $app_strings['LBL_VIEW_BUTTON']); |
|
138 | 4 | $this->ss->assign('allLinkString',$app_strings['LBL_LINK_ALL']); |
|
139 | 4 | $this->ss->assign('noneLinkString',$app_strings['LBL_LINK_NONE']); |
|
140 | 4 | $this->ss->assign('recordsLinkString',$app_strings['LBL_LINK_RECORDS']); |
|
141 | 4 | $this->ss->assign('selectLinkString',$app_strings['LBL_LINK_SELECT']); |
|
142 | |||
143 | // Bug 24677 - Correct the page total amount on the last page of listviews |
||
144 | 4 | $pageTotal = $this->data['pageData']['offsets']['next']-$this->data['pageData']['offsets']['current']; |
|
145 | 4 | if ( $this->data['pageData']['offsets']['next'] < 0 ) { |
|
146 | 4 | $pageTotal = $this->data['pageData']['offsets']['total'] - $this->data['pageData']['offsets']['current']; |
|
147 | } |
||
148 | |||
149 | 4 | if($this->select)$this->ss->assign('selectLinkTop', $this->buildSelectLink('select_link', $this->data['pageData']['offsets']['total'], $pageTotal)); |
|
150 | 4 | if($this->select)$this->ss->assign('selectLinkBottom', $this->buildSelectLink('select_link', $this->data['pageData']['offsets']['total'], $pageTotal, "bottom")); |
|
151 | |||
152 | 4 | if($this->show_action_dropdown) |
|
153 | { |
||
154 | 4 | $action_menu = $this->buildActionsLink(); |
|
155 | 4 | $this->ss->assign('actionsLinkTop', $action_menu); |
|
156 | 4 | if(count($action_menu['buttons']) > 0) { |
|
157 | 4 | $this->ss->assign('actionDisabledLink', preg_replace("/id\s*\=(\"\w+\"|w+)/i", "", $action_menu['buttons'][0])); |
|
158 | } |
||
159 | 4 | $menu_location = 'bottom'; |
|
160 | 4 | $this->ss->assign('actionsLinkBottom', $this->buildActionsLink('actions_link' ,$menu_location)); |
|
161 | } |
||
162 | |||
163 | 4 | $this->ss->assign('quickViewLinks', $this->quickViewLinks); |
|
164 | |||
165 | // handle save checks and stuff |
||
166 | 4 | if($this->multiSelect) |
|
167 | { |
||
168 | 2 | $this->ss->assign('selectedObjectsSpan', $this->buildSelectedObjectsSpan(true, (isset($_POST['mass'])) ? count($_POST['mass']): 0)); |
|
169 | 2 | $this->ss->assign('multiSelectData', $this->getMultiSelectData()); |
|
170 | } else { |
||
171 | 2 | $this->ss->assign('multiSelectData', '<textarea style="display: none" name="uid"></textarea>'); |
|
172 | } |
||
173 | // include button for Adding to Target List if in one of four applicable modules |
||
174 | 4 | if ( isset ( $_REQUEST['module']) && in_array ( $_REQUEST['module'] , array ( 'Contacts','Prospects','Leads','Accounts' )) |
|
175 | 4 | && ACLController::checkAccess('ProspectLists','edit',true)) { |
|
176 | $this->ss->assign( 'targetLink', $this->buildTargetList() ) ; |
||
177 | } |
||
178 | 4 | $this->processArrows($data['pageData']['ordering']); |
|
179 | 4 | $this->ss->assign('prerow', $this->multiSelect); |
|
180 | 4 | $this->ss->assign('clearAll', $app_strings['LBL_CLEARALL']); |
|
181 | 4 | $this->ss->assign('rowColor', array('oddListRow', 'evenListRow')); |
|
182 | 4 | $this->ss->assign('bgColor', array($odd_bg, $even_bg)); |
|
183 | 4 | $this->ss->assign('contextMenus', $this->contextMenus); |
|
184 | 4 | $this->ss->assign('is_admin_for_user', $GLOBALS['current_user']->isAdminForModule('Users')); |
|
185 | 4 | $this->ss->assign('is_admin', $GLOBALS['current_user']->isAdmin()); |
|
186 | |||
187 | |||
188 | 4 | if($this->contextMenus && !empty($contextMenuObjectsTypes)) { |
|
189 | $script = ''; |
||
190 | $cm = new contextMenu(); |
||
191 | foreach($contextMenuObjectsTypes as $type => $value) { |
||
192 | $cm->loadFromFile($type); |
||
193 | $script .= $cm->getScript(); |
||
194 | $cm->menuItems = array(); // clear menuItems out |
||
195 | } |
||
196 | $this->ss->assign('contextMenuScript', $script); |
||
197 | } |
||
198 | 4 | } |
|
199 | |||
275 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.