Loading module/Depot/src/Depot/Rule/NotificationDepotVersionCorrigeeAttenduRule.php +14 −59 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { Loading @@ -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"); Loading @@ -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; } Loading Loading @@ -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 Loading Loading @@ -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; Loading @@ -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 Loading
module/Depot/src/Depot/Rule/NotificationDepotVersionCorrigeeAttenduRule.php +14 −59 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { Loading @@ -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"); Loading @@ -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; } Loading Loading @@ -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 Loading Loading @@ -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; Loading @@ -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