View on GitHub

RefactoringPHP

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

Move Statements to Callers (217)

Inverse of Move Statements into Function (213)

Old Code

<?php
emitPhotoData($outStream, $person->photo);
function emitPhotoData($outStream,$photo)
{
    fwrite($outStream,'<p>title: ' . $photo->title . '</p>' . "\n");
    fwrite($outStream,'<p>location: ' . $photo->location . '</p>' . "\n");
}

New Code

<?php
emitPhotoData($outStream, $person->photo);
fwrite($outStream,'<p>location: ' . $person->photo->location . '</p>' . "\n");

function emitPhotoData($outStream,$photo)
{
    fwrite($outStream,'<p>title: ' . $photo->title . '</p>' . "\n");
}