Skip to content

Instantly share code, notes, and snippets.

@localheinz
Created April 8, 2022 10:42
Show Gist options
  • Save localheinz/2d47fbcde3852febc0772d0e366e355e to your computer and use it in GitHub Desktop.
Save localheinz/2d47fbcde3852febc0772d0e366e355e to your computer and use it in GitHub Desktop.
sleeper
<?php
interface Sleeper
{
public function sleep(int $seconds): void;
}
final class SystemSleeper implements Sleeper
{
public function sleep(int $seconds): void
{
sleep($seconds);
}
}
final class NullSleeper implements Sleeper
{
public function sleep(int $seconds): void
{
}
}
final class ServiceThatNeedsToSleep
{
public function __construct(private Sleeper $sleeper)
{
}
public function doSomething(): void
{
// ...
$this->sleeper->sleep(3);
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment