Adds helper method to reduce number of if/else statements
Fixes issues found by scrutinizer-ci
Merge pull request #788 from nsendetzky/master

Fixes issues found by scrutinizer-ci