View on GitHub

RefactoringPHP

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

Replace Primitive with Object (174)

Note: Due to semantic differences between languages, this sample differs more than most.

Old Code

<?php
array_filter($orders,function($o) {
    return 'high' === $o['priority'] ||
    'rush' === $o['priority']
});

New Code

<?php
array_filter($orders,function($o) {
    return $o['priority']->higherThan(new Priority('normal'));
});