]> Raphaël G. Git Repositories - userbundle/blobdiff - Entity/Group.php
Add strict type
[userbundle] / Entity / Group.php
index dad79b0132c1a17902541465aa54d317211df0af..1141f91dca6ff863f378ae3e7dfd594ed8f02983 100644 (file)
@@ -1,8 +1,23 @@
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * This file is part of the Rapsys PackBundle package.
+ *
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
 
 
-// src/Rapsys/UserBundle/Entity/Group.php
 namespace Rapsys\UserBundle\Entity;
 
 namespace Rapsys\UserBundle\Entity;
 
+use Doctrine\Common\Collections\ArrayCollection;
+
+use Rapsys\UserBundle\Entity\User;
+
+/**
+ * Group
+ */
 class Group {
        /**
         * @var integer
 class Group {
        /**
         * @var integer
@@ -12,7 +27,7 @@ class Group {
        /**
         * @var string
         */
        /**
         * @var string
         */
-       protected $role;
+       protected $title;
 
        /**
         * @var \DateTime
 
        /**
         * @var \DateTime
@@ -25,50 +40,49 @@ class Group {
        protected $updated;
 
        /**
        protected $updated;
 
        /**
-        * @var \Doctrine\Common\Collections\Collection
+        * @var ArrayCollection
         */
        protected $users;
 
        /**
         * Constructor
         */
        protected $users;
 
        /**
         * Constructor
-        * @param string $role The role name
+        *
+        * @param string $title The group name
         */
         */
-       public function __construct(string $role) {
-               $this->role = (string) $role;
-               $this->users = new \Doctrine\Common\Collections\ArrayCollection();
+       public function __construct(string $title) {
+               $this->title = (string) $title;
+               $this->users = new ArrayCollection();
        }
 
        /**
        }
 
        /**
-        * Set role
+        * Get id
         *
         *
-        * @param string $role
-        *
-        * @return User
+        * @return integer
         */
         */
-       public function setRole($role) {
-               $this->role = $role;
-
-               return $this;
+       public function getId(): int {
+               return $this->id;
        }
 
        /**
        }
 
        /**
-        * Get role
+        * Set title
         *
         *
-        * @return string
+        * @param string $title The group name
+        *
+        * @return User
         */
         */
-       public function getRole() {
-               return $this->role;
+       public function setTitle(string $title) {
+               $this->title = $title;
+
+               return $this;
        }
 
        /**
        }
 
        /**
-        * Returns a string representation of the role.
-        *
-        * @xxx Replace the deprecated "extends \Symfony\Component\Security\Core\Role\Role"
+        * Get title
         *
         * @return string
         */
         *
         * @return string
         */
-       public function __toString(): string {
-               return $this->role;
+       public function getTitle(): ?string {
+               return $this->title;
        }
 
        /**
        }
 
        /**
@@ -78,7 +92,7 @@ class Group {
         *
         * @return User
         */
         *
         * @return User
         */
-       public function setCreated($created) {
+       public function setCreated(\DateTime $created) {
                $this->created = $created;
 
                return $this;
                $this->created = $created;
 
                return $this;
@@ -89,7 +103,7 @@ class Group {
         *
         * @return \DateTime
         */
         *
         * @return \DateTime
         */
-       public function getCreated() {
+       public function getCreated(): \DateTime {
                return $this->created;
        }
 
                return $this->created;
        }
 
@@ -100,7 +114,7 @@ class Group {
         *
         * @return User
         */
         *
         * @return User
         */
-       public function setUpdated($updated) {
+       public function setUpdated(\DateTime $updated) {
                $this->updated = $updated;
 
                return $this;
                $this->updated = $updated;
 
                return $this;
@@ -111,18 +125,18 @@ class Group {
         *
         * @return \DateTime
         */
         *
         * @return \DateTime
         */
-       public function getUpdated() {
+       public function getUpdated(): \DateTime {
                return $this->updated;
        }
 
        /**
         * Add user
         *
                return $this->updated;
        }
 
        /**
         * Add user
         *
-        * @param \Rapsys\UserBundle\Entity\User $user
+        * @param User $user
         *
         * @return Group
         */
         *
         * @return Group
         */
-       public function addUser(\Rapsys\UserBundle\Entity\User $user) {
+       public function addUser(User $user) {
                $this->users[] = $user;
 
                return $this;
                $this->users[] = $user;
 
                return $this;
@@ -131,18 +145,36 @@ class Group {
        /**
         * Remove user
         *
        /**
         * Remove user
         *
-        * @param \Rapsys\UserBundle\Entity\User $user
+        * @param User $user
         */
         */
-       public function removeUser(\Rapsys\UserBundle\Entity\User $user) {
+       public function removeUser(User $user) {
                $this->users->removeElement($user);
        }
 
        /**
         * Get users
         *
                $this->users->removeElement($user);
        }
 
        /**
         * Get users
         *
-        * @return \Doctrine\Common\Collections\Collection
+        * @return ArrayCollection
         */
         */
-       public function getUsers() {
+       public function getUsers(): ArrayCollection {
                return $this->users;
        }
                return $this->users;
        }
+
+       /**
+        * Returns a string representation of the group
+        *
+        * @return string
+        */
+       public function __toString(): string {
+               return $this->title;
+       }
+
+       /**
+        * Get role
+        *
+        * @return string
+        */
+       public function getRole(): string {
+               return 'ROLE_'.strtoupper($this->title);
+       }
 }
 }