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 into Function (213)

Inverse of Move Statements to Callers (217)

Old Code

<?php
array_push($result,'<p>title: ' . $person->photo->title . '</p>');
$result = array_merge($result,photoData($person->photo));

function photoData($aPhoto)
{
    return [
        '<p>location: ' . $aPhoto->location . '</p>',
        '<p>date: ' . $aPhoto->date->toDateString() . '</p>',    
    ];
}

New Code

<?php
$result = array_merge($result,photoData($person->photo));

function photoData($aPhoto)
{
    return [
        '<p>title: ' . $person->photo->title . '</p>',
        '<p>location: ' . $aPhoto->location . '</p>',
        '<p>date: ' . $aPhoto->date->toDateString() . '</p>',    
    ];
}