Fix two Scruntinizer issues

For some reason, https://scrutinizer-ci.com/g/wmde/WikibaseDataModel/issues/master blames me for one of these issues. This simple fix also reduces the complexity of the method.

I did not wanted to do to much refactoring. Just a simple replacement of a loop with a native function.