public function userHasRole(AccountInterface $account, Site $site = null, $role = null)
    {
        if (null === $site && null === $role) {
          return (bool)count($this->getUserRoleCacheValue($account));
        }

        if (null === $site) {
            foreach ($this->getUserRoleCacheValue($account) as $grant) {
                if ($grant->getRole() === (int)$role) {
                    return true;
                }
            }
            return false;
        }

        if (null === $role) {
            $grant = $this->getUserRoleCacheValue($account, $site);
            return ($grant instanceof SiteAccessRecord) && ($grant->getRole() !== Access::ROLE_NONE);
        }

        if ($grant = $this->getUserRoleCacheValue($account, $site)) {
            return $grant->getRole() === (int)$role;
        }

        return false;
    }