]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Slot.php
Replace deprecated DateTime by DateTimeImmutable
[airbundle] / Entity / Slot.php
index 445f053da023dd3f7d4e0bf9cec050a2ebc0c6a4..1977b93791977dad4fe7f468a64cd8d77eff4930 100644 (file)
@@ -1,16 +1,17 @@
 <?php declare(strict_types=1);
 
 /*
- * this file is part of the rapsys packbundle package.
+ * This file is part of the Rapsys AirBundle package.
  *
- * (c) raphaël gertz <symfony@rapsys.eu>
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
  *
- * for the full copyright and license information, please view the license
+ * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
 
 namespace Rapsys\AirBundle\Entity;
 
+use Doctrine\Common\Collections\Collection;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Event\PreUpdateEventArgs;
 
@@ -19,37 +20,34 @@ use Doctrine\ORM\Event\PreUpdateEventArgs;
  */
 class Slot {
        /**
-        * @var integer
+        * Primary key
         */
-       private $id;
+       private ?int $id = null;
 
        /**
-        * @var string
+        * Create datetime
         */
-       protected $title;
+       private \DateTimeImmutable $created;
 
        /**
-        * @var \DateTime
+        * Update datetime
         */
-       private $created;
+       private \DateTimeImmutable $updated;
 
        /**
-        * @var \DateTime
+        * Sessions collection
         */
-       private $updated;
-
-       /**
-        * @var ArrayCollection
-        */
-       private $sessions;
+       private Collection $sessions;
 
        /**
         * Constructor
         */
-       public function __construct() {
+       public function __construct(private string $title) {
                //Set defaults
-               $this->created = new \DateTime('now');
-               $this->updated = new \DateTime('now');
+               $this->created = new \DateTimeImmutable('now');
+               $this->updated = new \DateTimeImmutable('now');
+
+               //Set collections
                $this->sessions = new ArrayCollection();
        }
 
@@ -58,7 +56,7 @@ class Slot {
         *
         * @return integer
         */
-       public function getId(): int {
+       public function getId(): ?int {
                return $this->id;
        }
 
@@ -87,11 +85,11 @@ class Slot {
        /**
         * Set created
         *
-        * @param \DateTime $created
+        * @param \DateTimeImmutable $created
         *
         * @return Slot
         */
-       public function setCreated(\DateTime $created) {
+       public function setCreated(\DateTimeImmutable $created) {
                $this->created = $created;
 
                return $this;
@@ -100,20 +98,20 @@ class Slot {
        /**
         * Get created
         *
-        * @return \DateTime
+        * @return \DateTimeImmutable
         */
-       public function getCreated(): \DateTime {
+       public function getCreated(): \DateTimeImmutable {
                return $this->created;
        }
 
        /**
         * Set updated
         *
-        * @param \DateTime $updated
+        * @param \DateTimeImmutable $updated
         *
         * @return Slot
         */
-       public function setUpdated(\DateTime $updated) {
+       public function setUpdated(\DateTimeImmutable $updated) {
                $this->updated = $updated;
 
                return $this;
@@ -122,9 +120,9 @@ class Slot {
        /**
         * Get updated
         *
-        * @return \DateTime
+        * @return \DateTimeImmutable
         */
-       public function getUpdated(): \DateTime {
+       public function getUpdated(): \DateTimeImmutable {
                return $this->updated;
        }
 
@@ -166,7 +164,7 @@ class Slot {
                //Check that we have a slot instance
                if (($slot = $eventArgs->getObject()) instanceof Slot) {
                        //Set updated value
-                       $slot->setUpdated(new \DateTime('now'));
+                       $slot->setUpdated(new \DateTimeImmutable('now'));
                }
        }