View on GitHub

RefactoringPHP

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

Change Reference to Value (252)

Inverse of Change Value to Reference (256)

Old Code

<?php
class Product {
    public function applyDiscount($arg)
    {
        $this->price->amount -= $arg;
    }
}

New Code

<?php
class Product {
    public function applyDiscount($arg)
    {
        $this->price = new Money($this->price->amount - $arg, $this->price->currency);
    }
}