Review

a lot of code changed
You should consider creating a Helper/Utils or similar class and moving this method to that class. 
No need to have methods in constants :)