refactoring

  • A default export makes a rename silent

    A default export has no name at the boundary, so the importing file invents one. Rename the thing being exported and every import keeps working under the old…

  • Upgrading a production application to PHP 7

    Twice the throughput and half the memory, for a migration that is mostly deletions — plus the four behaviour changes nobody puts in the upgrade notes.

  • Implicit route model binding removes the find()

    Every controller method that takes an id begins the same way: find the record, check it exists, abort with a 404. Multiply that by every route and it…

  • Return types make a refactor fail at the boundary

    A docblock @return is a comment; the engine never reads it, so a method that starts returning null on a Tuesday fails somewhere else on a Thursday. A…

  • intdiv() says what the floor division meant

    Integer division in PHP has always been (int) ($a / $b) or floor($a / $b), both of which route through a float — so past 253 the answer…

  • Destructuring pulls values out without temporaries

    Unpacking a few fields out of an options object is three or four lines of near-identical assignment at the top of every function. Destructuring does it in the…

  • DatePeriod iterates a date range without a loop counter

    Walking every day between two dates is usually a while loop with a manual increment and an off-by-one at one end. DatePeriod is an iterator over a start,…

  • Utils classes are where responsibilities go to hide

    A class named Utils, Helpers or Common has no definition, so nothing can be excluded from it. It grows monotonically, it is imported everywhere, and it ends up…

  • Migrating PSR-0 to PSR-4 removes a directory level

    PSR-0 mapped the entire namespace onto the path, so AppReportBuilder had to live at src/App/Report/Builder.php — the vendor and package name repeated inside a directory that was already…

  • Restructuring an application for Laravel 5

    4.2 to 5.0 is not an upgrade, it is a relocation. Moving an application through it in an order that keeps it booting at every step.