This code is hard to read (at least for me).
For readability and maintenance reasons, I would prefer a normal function with a simple if inside.