Fix Rubocop CyclomaticComplexity offense
This backport a change pushed to the Upstream merge branch (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1725).
This backport a change pushed to the Upstream merge branch (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1725).