Best Before
Have you ever shipped a backfill command or a temporary fix to production, and wanted to make sure you clean up after yourself one day?
You could add a // TODO or a ticket to your backlog, but you know it'll be forgotten, never to be seen again.
Well... that's why I created Best Before, a package that forces you to set a deadline for removing temporary code from your codebase.
composer require --dev duncanmcclean/best-before
Simply add the #[BestBefore] attribute to a class or method, along with the date it should be removed by and an optional description:
use DuncanMcClean\BestBefore\BestBefore;
#[BestBefore('2026-12-25', 'Only valid until Christmas.')]
class BackfillOrderTotals extends Command
{
// ...
}
class OrderResource extends JsonResource
{
#[BestBefore('2027-01-31', 'Keep `total` until the mobile app reads `grand_total`.')]
private function legacyFields(): array
{
// ...
}
}
Then, point the best-before binary at the directories you want to scan:
vendor/bin/best-before app src
If anything has gone off, it'll be listed and the command will fail:
✗ App\Console\Commands\BackfillOrderTotals was best before 2026-12-25
Only valid until Christmas.
app/Console/Commands/BackfillOrderTotals.php:7
Found 1 piece(s) of code past their best before date.
Pair it with a Git hook or a GitHub Actions workflow, and your builds will start failing once temporary code outstays its welcome, reminding you to clean up your mess.
The README has an example workflow which also runs on a schedule, so you'll find out even during quiet weeks when nobody's pushing.
Support my work
If you found this post helpful, consider sponsoring me on GitHub. It helps me keep writing and maintaining open source projects like Runway.