Download the PHP package robertology/todo_or_die without Composer
On this page you can find all versions of the php package robertology/todo_or_die. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download robertology/todo_or_die
More information about robertology/todo_or_die
Files in robertology/todo_or_die
Package todo_or_die
Short Description A deadly reminder for your code rot
License MIT
Informations about the package todo_or_die
Todo Or Die
A deadly reminder for your code rot.
Replace your // @todo
comments with something more actionable. This library will help put those more in your face when the time is right. Yes, "Or Die" means an exception will be thrown if your condition is met.
WHY??
I know what you're thinking: Why would anyone want to purposefully cause a failure?
The main idea is that you should hit these in your testing, not in production. But they will be in production, and there's nothing like a little fire under your seat to get things done. (but keep reading for how not to break production)
Yes, it is a bit harsh, but try a grep -ri '@todo' . | wc -l
on your codebase and see how many are just sitting around being ignored. Face it, Later equals Never. No one is looking at these todo
s and your code is just rotting away.
Put a real, actionable deadline on those "for now"s and "after next version"s.
Installation
composer require robertology/todo_or_die
For PHP 7.4
, install version 1, and read the README of that version for usage instructions.
(composer require robertology/todo_or_die:^1
)
Usage
(string $todo_message, bool|Check $check, callable $callable_for_alerting = null)
Modes of Use
-
Die
-
Alert
- Die or Alert
Don't Die
Ensure the "Or Die" part never happens by setting the environment variable TODOORDIE_SKIP_DIE
to a truthy
value. This will cause only Alerts to be triggered. Any Die condition is ignored. (Hint: this might be a smart move for production)
Alert Throttling
To avoid saturating your alert systems, throttling is built in (for Alerts only, not for Die). Each Todo
should alert only once per hour. Change that by setting the environment variable TODOORDIE_ALERT_THRESHOLD
to the number of seconds desired. Disable throttling by setting this to zero.
Examples
Notes
-
I used
strtotime()
in the examples for readability, but do not use relative dates such asstrtotime('+2 months')
because it will be evaluated each time and "two months from now" will never come when "now" keeps moving. -
The Alert throttling uses a file placed in PHP's temp directory (
sys_get_temp_dir()
) which may be prone to garbage collection now and then, but is likely to work fine for this. -
The name was (also) shamelessly stolen from the ruby gem
searls/todo_or_die
. - Tip o' the Hat to The Changelog (Episode 463) where I first heard of the idea.
Personal Quest
In addition to having an actual working tool, I had a few goals for myself with this project.
- Full TDD (Test Driven Development)
- The tests are a mix of Behavior and Functional tests, and I'm OK with that for this small project.
- I'm not concerned with 100% coverage, but all behavior should have a test.
- SOLID "To The Extreme"
- After getting to a working version, I continued to refactor with an eye on SOLID principles.
- Such a simple concept could have been written with a single class, but being strict here was a good exercise in defining the Single Responsibility.
License
This project is licensed under the MIT license.