PHP refactoring