Even with the missing open php tag, this won’t work the way you’re trying to do it. The Divi code module accepts html code and PHP shortcodes. I haven’t tried javascript, so not sure about that.
You’ll need to integrate your code as a stand alone plugin. After that, you can use the shortcode in the Divi code module and should also be able to use it in the text tab mode.