Remove duplicated code

Previously, Code Climate identified some duplicated code.  This has
been simplified into a function.

[#49694411]
Merge 49694411-code-climate to master

[Completes #49694411]