for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the DoyoUserBundle project.
*
* (c) Anthonius Munthi <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Doyo\UserBundle\Model;
/**
* Base group.
* @author Anthonius Munthi <[email protected]>
abstract class Group implements GroupInterface
{
* @var mixed
protected $id;
* @var string
protected $name;
* @var array
protected $roles;
* Group constructor.
* @param string $name
* @param array $roles
public function __construct($name, $roles = [])
$this->name = $name;
$this->roles = $roles;
}
* {@inheritdoc}
public function addRole($role)
if (!$this->hasRole($role)) {
$this->roles[] = strtoupper($role);
return $this;
public function getId()
return $this->id;
public function getName()
return $this->name;
public function hasRole($role)
return \in_array(strtoupper($role), $this->roles, true);
public function getRoles()
return $this->roles;
public function removeRole($role)
if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
unset($this->roles[$key]);
$this->roles = array_values($this->roles);
public function setName($name)
public function setRoles(array $roles)