Home
CASE clauses should not have too many lines
Rule description
- CASE clauses should not have too many lines
Non-compliant Code Example
public function integer of_getminmaxpoints (windowobject awo_control[], ref integer ai_min_x, ref integer ai_min_y, ref integer ai_max_x, ref integer ai_max_y);
oval loval_cntrl
line ln_cntrl
integer li_x, li_y, li_width, li_height, li_temp
integer li_upperbound
integer li_cnt
//Determine position of the right most and bottom most control.
For li_cnt = 1 to li_upperbound
If IsValid(awo_control[li_cnt]) Then
Choose Case of_TypeOf(awo_control[li_cnt])
Case LINE //Non compliant code (When clause should contains lines less then 6)
ln_cntrl = awo_control[li_cnt]
li_x = ln_cntrl.BeginX
li_y = ln_cntrl.BeginY
li_width = ln_cntrl.EndX
li_height = ln_cntrl.EndY
//Correct for lines that may have the End points
//before to the Begin points.
If li_width >= li_x Then
li_width = li_width - li_x
Else
li_temp = li_x
li_x = li_width
li_width = li_temp - li_x
End If
If li_height >= li_y Then
li_height = li_height - li_y
Else
li_temp = li_y
li_y = li_height
li_height = li_temp - li_y
End If
Case OVAL
loval_cntrl = awo_control[li_cnt]
li_x = loval_cntrl.X
li_y = loval_cntrl.Y
li_width = loval_cntrl.Width
li_height = loval_cntrl.Height
Case Else
//An unknown control type has been encountered
Return -1
End Choose
End If
Next
Return 1
end function
Compliant Code Example
public function integer of_getminmaxpoints (windowobject awo_control[], ref integer ai_min_x, ref integer ai_min_y, ref integer ai_max_x, ref integer ai_max_y);
oval loval_cntrl
line ln_cntrl
integer li_x, li_y, li_width, li_height, li_temp
integer li_upperbound
integer li_cnt
//Determine position of the right most and bottom most control.
For li_cnt = 1 to li_upperbound
If IsValid(awo_control[li_cnt]) Then
Choose Case of_TypeOf(awo_control[li_cnt])
Case LINE //compliant code
ln_cntrl = awo_control[li_cnt]
li_width = calWidth(ln_cntrl,li_x,li_y,li_width,li_height)
li_height = calHeight(ln_cntrl,li_x,li_y,li_width,li_height)
Case OVAL
loval_cntrl = awo_control[li_cnt]
li_x = loval_cntrl.X
li_y = loval_cntrl.Y
li_width = loval_cntrl.Width
li_height = loval_cntrl.Height
Case Else
//An unknown control type has been encountered
Return -1
End Choose
End If
Next
Return 1
end function
private integer calHeight(line ln_cntrl,integer li_x,integer li_y,integer li_width,integer li_height)
li_x = ln_cntrl.BeginX
li_y = ln_cntrl.BeginY
li_height = ln_cntrl.EndY
//Correct for lines that may have the End points
//before to the Begin points.
If li_height >= li_y Then
li_height = li_height - li_y
Else
li_temp = li_y
li_y = li_height
li_height = li_temp - li_y
End If
return li_height;
end function
private integer calWidth(line ln_cntrl,integer li_x,integer li_y,integer li_width,integer li_height)
li_x = ln_cntrl.BeginX
li_y = ln_cntrl.BeginY
li_width = ln_cntrl.EndX
//Correct for lines that may have the End points
//before to the Begin points.
If li_width >= li_x Then
li_width = li_width - li_x
Else
li_temp = li_x
li_x = li_width
li_width = li_temp - li_x
End If
return li_width;
end function