Created
October 19, 2021 10:53
-
-
Save asprega/f23444902509be6bc3b685f608051953 to your computer and use it in GitHub Desktop.
[ClockMock article on Medium] Codebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Entity; | |
use DateTimeImmutable; | |
class Entity | |
{ | |
private DateTimeImmutable $creationDate; | |
private ?DateTimeImmutable $processingDate = null; | |
public function __construct() | |
{ | |
$this->creationDate = new DateTimeImmutable(); | |
} | |
public function getCreationDate(): DateTimeImmutable | |
{ | |
return $this->creationDate; | |
} | |
public function getProcessingDate(): ?DateTimeImmutable | |
{ | |
return $this->processingDate; | |
} | |
public function scheduleNextProcessing(DateTimeImmutable $processingDate): void | |
{ | |
$this->processingDate = $processingDate; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Service; | |
use DateTimeImmutable; | |
use Exception; | |
use App\Entity\Entity; | |
class Service | |
{ | |
public function doSomething(): void | |
{ | |
$now = new DateTimeImmutable(); | |
if ((int) $now->format('d') > 28) { | |
throw new Exception('This thing cannot be done after the 28th of every month.'); | |
} | |
// ... Something is done here | |
} | |
public function scheduleProcessing(Entity $entity): void | |
{ | |
$entity->scheduleNextProcessing(new DateTimeImmutable('+5 minutes')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment