Php refactoring