]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Entity/Country.php
Version 0.6.1
[airbundle] / Entity / Country.php
index 5674007e439c8c008037cf57491f54c3ef7120d6..b6b43918762c7f48af66766ffb878b7617ab075b 100644 (file)
@@ -11,6 +11,7 @@
 
 namespace Rapsys\AirBundle\Entity;
 
+use Doctrine\Common\Collections\Collection;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Event\PreUpdateEventArgs;
 
@@ -19,39 +20,24 @@ use Doctrine\ORM\Event\PreUpdateEventArgs;
  */
 class Country {
        /**
-        * @var integer
+        * Primary key
         */
-       private $id;
+       private ?int $id = null;
 
        /**
-        * @var string
+        * Create datetime
         */
-       protected $code;
+       private \DateTimeImmutable $created;
 
        /**
-        * @var string
+        * Update datetime
         */
-       protected $alpha;
+       private \DateTimeImmutable $updated;
 
        /**
-        * @var string
+        * Users collection
         */
-       protected $title;
-
-       /**
-        * @var \DateTime
-        */
-       protected $created;
-
-       /**
-        * @var \DateTime
-        */
-       protected $updated;
-
-       /**
-        * @var ArrayCollection
-        */
-       protected $users;
+       private Collection $users;
 
        /**
         * Constructor
@@ -60,13 +46,10 @@ class Country {
         * @param string $alpha The country alpha
         * @param string $title The country title
         */
-       public function __construct(string $code, string $alpha, string $title) {
+       public function __construct(private string $code, private string $alpha, private string $title) {
                //Set defaults
-               $this->code = $code;
-               $this->alpha = $alpha;
-               $this->title = $title;
-               $this->created = new \DateTime('now');
-               $this->updated = new \DateTime('now');
+               $this->created = new \DateTimeImmutable('now');
+               $this->updated = new \DateTimeImmutable('now');
 
                //Set collections
                $this->users = new ArrayCollection();
@@ -77,7 +60,7 @@ class Country {
         *
         * @return integer
         */
-       public function getId(): int {
+       public function getId(): ?int {
                return $this->id;
        }
 
@@ -150,11 +133,11 @@ class Country {
        /**
         * Set created
         *
-        * @param \DateTime $created
+        * @param \DateTimeImmutable $created
         *
         * @return Country
         */
-       public function setCreated(\DateTime $created): Country {
+       public function setCreated(\DateTimeImmutable $created): Country {
                $this->created = $created;
 
                return $this;
@@ -163,20 +146,20 @@ class Country {
        /**
         * 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 Country
         */
-       public function setUpdated(\DateTime $updated): Country {
+       public function setUpdated(\DateTimeImmutable $updated): Country {
                $this->updated = $updated;
 
                return $this;
@@ -185,9 +168,9 @@ class Country {
        /**
         * Get updated
         *
-        * @return \DateTime
+        * @return \DateTimeImmutable
         */
-       public function getUpdated(): \DateTime {
+       public function getUpdated(): \DateTimeImmutable {
                return $this->updated;
        }
 
@@ -229,7 +212,7 @@ class Country {
                //Check that we have an country instance
                if (($country = $eventArgs->getObject()) instanceof Country) {
                        //Set updated value
-                       $country->setUpdated(new \DateTime('now'));
+                       $country->setUpdated(new \DateTimeImmutable('now'));
                }
        }