Factor out duplicated code

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

[Completes #57611752]