]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Snippet.php
Replace deprecated DateTime by DateTimeImmutable
[airbundle] / Entity / Snippet.php
index fa5fe996fbcc68d74fc4ccf6d7dec693aaeef29a..e645a69e81d94ecb639462c898dc73fe4d908c9a 100644 (file)
@@ -1,11 +1,11 @@
 <?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.
  */
 
@@ -18,97 +18,76 @@ use Doctrine\ORM\Event\PreUpdateEventArgs;
  */
 class Snippet {
        /**
-        * @var integer
-        */
-       private $id;
-
-       /**
-        * @var string
+        * Primary key
         */
-       protected $locale;
+       private ?int $id = null;
 
        /**
         * @var string
         */
-       protected $description;
+       private ?string $description = null;
 
        /**
         * @var string
         */
-       protected $class;
+       private ?string $class = null;
 
        /**
         * @var string
         */
-       protected $short;
+       private ?string $short = null;
 
        /**
         * @var integer
         */
-       protected $rate;
+       private ?int $rate = null;
 
        /**
         * @var bool
         */
-       protected $hat;
+       private ?bool $hat = null;
 
        /**
         * @var string
         */
-       protected $contact;
+       private ?string $contact = null;
 
        /**
         * @var string
         */
-       protected $donate;
+       private ?string $donate = null;
 
        /**
         * @var string
         */
-       protected $link;
+       private ?string $link = null;
 
        /**
         * @var string
         */
-       protected $profile;
-
-       /**
-        * @var \DateTime
-        */
-       protected $created;
-
-       /**
-        * @var \DateTime
-        */
-       protected $updated;
+       private ?string $profile = null;
 
        /**
-        * @var Location
+        * Create datetime
         */
-       protected $location;
+       private \DateTimeImmutable $created;
 
        /**
-        * @var User
+        * Update datetime
         */
-       protected $user;
+       private \DateTimeImmutable $updated;
 
        /**
         * Constructor
+        *
+        * @param string $locale The locale
+        * @param Location $location The location instance
+        * @param User $user The user instance
         */
-       public function __construct() {
+       public function __construct(private string $locale, private Location $location, private User $user) {
                //Set defaults
-               $this->description = null;
-               $this->class = null;
-               $this->short = null;
-               $this->rate = null;
-               $this->hat = null;
-               $this->contact = null;
-               $this->donate = null;
-               $this->link = null;
-               $this->profile = null;
-               $this->location = null;
-               $this->created = new \DateTime('now');
-               $this->updated = new \DateTime('now');
+               $this->created = new \DateTimeImmutable('now');
+               $this->updated = new \DateTimeImmutable('now');
        }
 
        /**
@@ -116,7 +95,7 @@ class Snippet {
         *
         * @return integer
         */
-       public function getId(): int {
+       public function getId(): ?int {
                return $this->id;
        }
 
@@ -342,11 +321,11 @@ class Snippet {
        /**
         * Set created
         *
-        * @param \DateTime $created
+        * @param \DateTimeImmutable $created
         *
         * @return Snippet
         */
-       public function setCreated(\DateTime $created): Snippet {
+       public function setCreated(\DateTimeImmutable $created): Snippet {
                $this->created = $created;
 
                return $this;
@@ -355,20 +334,20 @@ class Snippet {
        /**
         * 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 Snippet
         */
-       public function setUpdated(\DateTime $updated): Snippet {
+       public function setUpdated(\DateTimeImmutable $updated): Snippet {
                $this->updated = $updated;
 
                return $this;
@@ -377,9 +356,9 @@ class Snippet {
        /**
         * Get updated
         *
-        * @return \DateTime
+        * @return \DateTimeImmutable
         */
-       public function getUpdated(): \DateTime {
+       public function getUpdated(): \DateTimeImmutable {
                return $this->updated;
        }
 
@@ -390,7 +369,7 @@ class Snippet {
         *
         * @return Snippet
         */
-       public function setLocation(Location $location) {
+       public function setLocation(Location $location): Snippet {
                $this->location = $location;
 
                return $this;
@@ -401,7 +380,7 @@ class Snippet {
         *
         * @return Location
         */
-       public function getLocation() {
+       public function getLocation(): Location {
                return $this->location;
        }
 
@@ -412,7 +391,7 @@ class Snippet {
         *
         * @return Snippet
         */
-       public function setUser(User $user) {
+       public function setUser(User $user): Snippet {
                $this->user = $user;
 
                return $this;
@@ -423,7 +402,7 @@ class Snippet {
         *
         * @return User
         */
-       public function getUser() {
+       public function getUser(): User {
                return $this->user;
        }
 
@@ -434,7 +413,7 @@ class Snippet {
                //Check that we have an snippet instance
                if (($snippet = $eventArgs->getObject()) instanceof Snippet) {
                        //Set updated value
-                       $snippet->setUpdated(new \DateTime('now'));
+                       $snippet->setUpdated(new \DateTimeImmutable('now'));
                }
        }
 }