Refactor PHP to improve code quality