]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Dance.php
Replace deprecated DateTime by DateTimeImmutable
[airbundle] / Entity / Dance.php
index 0b132c8418cd76f59846514ffb62784aaa222743..888a56890a38571888309c206b5ceb11d62336e3 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,39 +20,29 @@ use Doctrine\ORM\Event\PreUpdateEventArgs;
  */
 class Dance {
        /**
-        * @var integer
+        * Primary key
         */
-       private $id;
+       private ?int $id = null;
 
        /**
-        * @var string
+        * Create datetime
         */
-       protected $name;
+       private \DateTimeImmutable $created;
 
        /**
-        * @var string
+        * Update datetime
         */
-       protected $type;
+       private \DateTimeImmutable $updated;
 
        /**
-        * @var \DateTime
+        * Applications collection
         */
-       private $created;
+       private Collection $applications;
 
        /**
-        * @var \DateTime
+        * Users collection
         */
-       private $updated;
-
-       /**
-        * @var ArrayCollection
-        */
-       private $applications;
-
-       /**
-        * @var ArrayCollection
-        */
-       private $users;
+       private Collection $users;
 
        /**
         * Constructor
@@ -59,12 +50,10 @@ class Dance {
         * @param string $name The dance name
         * @param string $type The dance type
         */
-       public function __construct(string $name, string $type) {
+       public function __construct(private string $name, private string $type) {
                //Set defaults
-               $this->name = $name;
-               $this->type = $type;
-               $this->created = new \DateTime('now');
-               $this->updated = new \DateTime('now');
+               $this->created = new \DateTimeImmutable('now');
+               $this->updated = new \DateTimeImmutable('now');
 
                //Set collections
                $this->applications = new ArrayCollection();
@@ -76,7 +65,7 @@ class Dance {
         *
         * @return integer
         */
-       public function getId(): int {
+       public function getId(): ?int {
                return $this->id;
        }
 
@@ -127,11 +116,11 @@ class Dance {
        /**
         * Set created
         *
-        * @param \DateTime $created
+        * @param \DateTimeImmutable $created
         *
         * @return Dance
         */
-       public function setCreated(\DateTime $created): Dance {
+       public function setCreated(\DateTimeImmutable $created): Dance {
                $this->created = $created;
 
                return $this;
@@ -140,20 +129,20 @@ class Dance {
        /**
         * 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 Dance
         */
-       public function setUpdated(\DateTime $updated): Dance {
+       public function setUpdated(\DateTimeImmutable $updated): Dance {
                $this->updated = $updated;
 
                return $this;
@@ -162,9 +151,9 @@ class Dance {
        /**
         * Get updated
         *
-        * @return \DateTime
+        * @return \DateTimeImmutable
         */
-       public function getUpdated(): \DateTime {
+       public function getUpdated(): \DateTimeImmutable {
                return $this->updated;
        }
 
@@ -251,7 +240,7 @@ class Dance {
                //Check that we have a dance instance
                if (($dance = $eventArgs->getObject()) instanceof Dance) {
                        //Set updated value
-                       $dance->setUpdated(new \DateTime('now'));
+                       $dance->setUpdated(new \DateTimeImmutable('now'));
                }
        }