Professor, analisei a classe, e fiz algumas alterações sobre tipo Primitivos, gostaria de saber se foi felizardo na refatoração
<?php
namespace Alura\Calisthenics\Domain\Student;
use Alura\Calisthenics\Domain\Email\Email;
use Alura\Calisthenics\Domain\Localization\Localization;
use Alura\Calisthenics\Domain\Name\Name;
use Alura\Calisthenics\Domain\Video\Video;
use DateTimeImmutable;
use DateTimeInterface;
use Ds\Map;
class Student
{
private Email $email;
private DateTimeInterface $bd;
private Map $watchedVideos;
private Name $name;
private Localization $localization;
public function __construct(
Email $email,
DateTimeInterface $bd,
Name $name,
Localization $localization
) {
$this->watchedVideos = new Map();
$this->email = $email;
$this->bd = $bd;
$this->name = $name;
$this->localization = $localization;
}
public function getBd(): DateTimeInterface
{
return $this->bd;
}
public function watch(Video $video, DateTimeInterface $date)
{
$this->watchedVideos->put($video, $date);
}
public function hasAccess(): bool
{
if ($this->watchedVideos->count() === 0) {
return true;
}
$this->orderVideoByDateWatch();
$today = new DateTimeImmutable();
$firstDate = $this->renderFirstVideoForWatching();
return $firstDate->diff($today)->days < 90;
}
private function orderVideoByDateWatch(): void
{
$this->watchedVideos->sort(fn(DateTimeInterface $dateA, DateTimeInterface $dateB) => $dateA <=> $dateB);
}
private function renderFirstVideoForWatching(): DateTimeImmutable
{
/** @var DateTimeInterface $firstDate */
return $this->watchedVideos->first()->value;
}
}