public function grant(UserRole $aRole)
    {
        if (false === $this->isRoleAllowed($aRole)) {
            throw new UserRoleInvalidException();
        }
        if (true === $this->isGranted($aRole)) {
            throw new UserRoleAlreadyGrantedException();
        }
        $this->roles[] = $aRole;
        $this->updatedOn = new \DateTimeImmutable();

        $this->publish(
            new UserRoleGranted(
                $this->id,
                $this->email,
                $aRole
            )
        );
    }
public function grant(UserRole $aRole)
    {
        if (false === $this->isRoleAllowed($aRole)) {
            throw new UserRoleInvalidException();
        }
        if (true === $this->isGranted($aRole)) {
            throw new UserRoleAlreadyGrantedException();
        }
        $this->roles[] = $aRole;
        $this->updatedOn = new \DateTimeImmutable();

        $this->publish(
            new UserRoleGranted(
                $this->id,
                $this->email,
                $aRole
            )
        );
    }
public function grant ( UserRole $ aRole ) { if ( false === $ this -> isRoleAllowed ( $ aRole ) ) { throw new UserRoleInvalidException ( ) ; } if ( true === $ this -> isGranted ( $ aRole ) ) { throw new UserRoleAlreadyGrantedException ( ) ; } $ this -> roles [ ] = $ aRole ; $ this -> updatedOn = new \ DateTimeImmutable ( ) ; $ this -> publish ( new UserRoleGranted ( $ this -> id , $ this -> email , $ aRole ) ) ; }
Adds the given role.

@param UserRole $aRole The user role

@throws UserRoleInvalidException        when the user is role is invalid
@throws UserRoleAlreadyGrantedException when the user role is already granted
Adds the given role .