Commit e731fcea authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Modernisation des typages et signatures dans la classe NotificationDepotVersionCorrigeeAttenduRule.

parent ab0eda1c
Loading
Loading
Loading
Loading
+14 −59
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Application\Constants;
use DateInterval;
use DateTime;
use DomainException;
use Exception;
use Rule\RuleInterface;
use These\Entity\Db\These;
use UnicaenApp\Exception\RuntimeException;
@@ -13,8 +14,6 @@ use UnicaenApp\Traits\MessageAwareTrait;

/**
 * Règle concernant notification au sujet du dépôt attendu de la version corrigée.
 *
 * @author Unicaen
 */
class NotificationDepotVersionCorrigeeAttenduRule implements RuleInterface
{
@@ -22,44 +21,18 @@ class NotificationDepotVersionCorrigeeAttenduRule implements RuleInterface

    public const SPEC_INTERVAL_ENTRE_DATE_NOTIF_ET_BUTOIRE = 'P1M'; // 1 mois

    /**
     * @var These
     */
    private $these;

    /**
     * @var DateTime|null
     */
    private $dateDerniereNotif;

    /**
     * @var DateTime|null
     */
    private $dateProchaineNotif;

    /**
     * @var bool
     */
    private $estPremiereNotif;

    /**
     * @var DateTime
     */
    private $dateAujourdhui;
    private These $these;
    private ?DateTime $dateDerniereNotif = null;
    private ?DateTime $dateProchaineNotif;
    private bool $estPremiereNotif;
    private DateTime $dateAujourdhui;

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this->setDateAujourdhui(new DateTime());
    }

    /**
     * @param These $these
     * @return NotificationDepotVersionCorrigeeAttenduRule
     */
    public function setThese($these)
    public function setThese(These $these): static
    {
        if ($these->getCorrectionAutorisee() === null) {
            throw new DomainException("Thèse spécifiée invalide car aucune correction attendue");
@@ -73,17 +46,10 @@ class NotificationDepotVersionCorrigeeAttenduRule implements RuleInterface
        return $this;
    }

    /**
     * @param DateTime|null $dateDerniereNotif
     * @return NotificationDepotVersionCorrigeeAttenduRule
     */
    public function setDateDerniereNotif($dateDerniereNotif)
    public function setDateDerniereNotif(?DateTime $dateDerniereNotif): static
    {
        $this->dateDerniereNotif = $dateDerniereNotif;

        if ($this->dateDerniereNotif !== null) {
            $this->dateDerniereNotif->setTime(0, 0);
        }
        $this->dateDerniereNotif?->setTime(0, 0);

        return $this;
    }
@@ -116,7 +82,7 @@ class NotificationDepotVersionCorrigeeAttenduRule implements RuleInterface
                $spec = self::SPEC_INTERVAL_ENTRE_DATE_NOTIF_ET_BUTOIRE;
                try {
                    $interval = new DateInterval($spec);
                } catch (\Exception $e) {
                } catch (Exception $e) {
                    throw new RuntimeException("Interval invalide : $spec", null, $e);
                }
                $dateProchaineNotif = $dateButoir->sub($interval); // Date butoir - interval
@@ -146,7 +112,7 @@ class NotificationDepotVersionCorrigeeAttenduRule implements RuleInterface
            return;
        }
        // La date de prochaine notif égale la date de dernière notif: les notifications sont terminées.
        if ($dateProchaineNotif == $this->dateDerniereNotif) {
        if ($dateProchaineNotif === $this->dateDerniereNotif) {
            $this->dateProchaineNotif = null;
            $this->addMessage("Les notifications sont terminées.");
            return;
@@ -156,35 +122,24 @@ class NotificationDepotVersionCorrigeeAttenduRule implements RuleInterface
        $this->addMessage(sprintf("Prochaine notification le %s.", $this->dateProchaineNotif->format(Constants::DATETIME_FORMAT)));
    }

    /**
     * @return DateTime|null
     */
    public function getDateProchaineNotif()
    public function getDateProchaineNotif(): ?DateTime
    {
        return $this->dateProchaineNotif;
    }

    /**
     * @return bool
     */
    public function estPremiereNotif()
    public function estPremiereNotif(): bool
    {
        return $this->estPremiereNotif;
    }

    /**
     * Permet de voyager dans le temps en déplaçant la date d'aujourdhui.
     *
     * @param DateTime $dateAujourdhui
     * @return static
     */
    public function setDateAujourdhui(DateTime $dateAujourdhui)
    public function setDateAujourdhui(DateTime $dateAujourdhui): static
    {
        $this->dateAujourdhui = $dateAujourdhui;
        $this->dateAujourdhui->setTime(0, 0);

        return $this;
    }


}
 No newline at end of file