Could be avoided by having more functions, one for each case.
(Only if you control the code, of course.)