Refactoring for PHP code