Adds helper method to reduce number of if/else statements
Fixes issues found by scrutinizer-ci