users = new ArrayCollection(); } public function __toString(): string { return $this->getName() ?: ''; } public function addRole(string $role): self { if (!$this->hasRole($role)) { $this->roles[] = strtoupper($role); } return $this; } public function hasRole(string $role): bool { return \in_array(strtoupper($role), $this->roles, true); } public function getRoles(): array { return $this->roles; } public function removeRole(string $role): self { if (false !== $key = array_search(strtoupper($role), $this->roles, true)) { unset($this->roles[$key]); $this->roles = array_values($this->roles); } return $this; } public function getName(): string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } public function setRoles(array $roles): self { $this->roles = $roles; return $this; } /** * Get id. * * @return int */ public function getId() { return $this->id; } /** * @return User[]|Collection */ public function getUsers(): array|Collection { return $this->users; } public function getCode(): string { return $this->code; } public function setCode(string $code): self { $this->code = $code; return $this; } }