View on GitHub

RefactoringPHP

A PHP version of the refactors from Refactoring: Improving the Design of Existing Code (Second Edition) by Martin Fowler

Remove Subclass (369)

Inverse of Replace Type Code with Subclasses (362)

Old Code

<?php
class Person {
    public function getGenderCode()
    {
        return 'X';
    }
}

class Male extends Person {
    public function getGenderCode()
    {
        return 'M';
    }
}

class Female extends Person {
    public function getGenderCode()
    {
        return 'F';
    }
}

New Code

<?php
class Person {
    public function getGenderCode()
    {
        return $this->genderCode;
    }
}