View on GitHub

RefactoringPHP

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

Remove Flag Argument (314)

Old Code

<?php
public function setDimension($name, $value)
{
    if ( $name === 'height' ) {
        $this->height = $value;
        return;
    }
    if ( $name === 'width' ) {
        $this->width = $value;
        return;
    }
}

New Code

<?php
public function setHeight($value)
{
    $this->height = $value;
}

public function setWidth($value)
{
    $this->width = $value;
}