Normalizes the role list

@param (BaseRole|string)[] $roles

@return Role[]
501249
private function normalizeRoleList (array $roles)
    {
        $normalized = [];

        foreach ($roles as $role)
        {
            $roleKey = (is_object($role) && ($role instanceof BaseRole))
                ? $role->getRole()
                : (string) $role;

            if (isset($this->roleCollection[$roleKey]))
            {
                $normalized[] = $this->roleCollection[$roleKey];
            }
        }

        return $normalized;
    }
1023675
public function revokeRole($role)
    {
        return $this->mapArray($role, function ($role) {

            $roleId = $this->parseRoleId($role);

            return $this->roles()->detach($roleId);
        });
    }
1219179
private function getSpecifiedEnvironmentRoles(array $roles)
    {
        $environmentRoles = [];
        $project = $this->getSelectedProject();
        $environments = $this->api()->getEnvironments($project);
        foreach ($roles as $role) {
            if (strpos($role, ':') === false) {
                continue;
            }
            list($id, $role) = explode(':', $role, 2);
            $role = $this->validateEnvironmentRole($role);
            // Match environment IDs by wildcard.
            if (strpos($id, '%') !== false) {
                $pattern = '/^' . str_replace('%', '.*', preg_quote($id)) . '$/';
                $matched = preg_grep($pattern, array_keys($environments));
                if (empty($matched)) {
                    throw new InvalidArgumentException('No environment IDs match: ' . $id);
                }
                foreach ($matched as $environmentId) {
                    $environmentRoles[$environmentId] = $role;
                }
                continue;
            }
            if (!$this->api()->getEnvironment($id, $project)) {
                throw new InvalidArgumentException('Environment not found: ' . $id);
            }
            $environmentRoles[$id] = $role;
        }

        return $environmentRoles;
    }
977645
protected function get_roles( $roles ) {
		if ( empty($roles) ) {
			// @codeCoverageIgnoreStart
			return null;
			// @codeCoverageIgnoreEnd
		}

		$wp_roles = wp_roles();
		$names    = $wp_roles->get_names();

		$values = array();

		foreach ( $roles as $role ) {
			$name = $role;
			if ( isset($names[ $role ]) ) {
				$name = translate_user_role($names[ $role ]);
			}
			$values[ $role ] = $name;
		}

		return $values;
	}
39922
public function addDefaultRoles(DefaultRole ...$roles)
    {
        foreach ($roles as $role) {
            $this->getDefaultRoles()->add($role);
        }

        return $this;
    }
505125
public function setRoles(array $roles)
    {
        $this->roles->clear();
        foreach ($roles as $role) {
            $this->addRole($role);
        }

        return $this;
    }
1120871
public function getRelativeRoleName($role)
    {
        $roles = $this->collectRelativeRoles();
        if (isset($roles[$role])) {
            return $roles[$role];
        }
    }
1017031
private function deleteRole($roles)
    {
        $result = [];
        try {
            foreach ($roles as $value) {
                $role = $this->entityTypeManager->getStorage('user_role')->load($value);
                $this->entityTypeManager->getStorage('user_role')->delete([$role]);

                $result['success'][] = [
                    'role-id' => $value,
                    'role-name' => $value
                ];
            }
        } catch (\Exception $e) {
            $result['error'] = [
                'error' => 'Error: ' . get_class($e) . ', code: ' . $e->getCode() . ', message: ' . $e->getMessage()
            ];
        }

        return $result;
    }
620426
protected function isAll(array $roles)
    {
        foreach ($roles as $role) {
            if (!$this->hasRole($role)) {
                return false;
            }
        }

        return true;
    }
67941
public function authorizeRoles($roles)
    {
        if (is_array($roles)) {
            return $this->hasAnyRole($roles) ||
                abort(401, 'This action is unauthorized.');
        }
        return $this->hasRole($roles) ||
            abort(401, 'This action is unauthorized.');
    }
196307
public function getMultipleByName(array $roles): iterable
    {
        if (null === $this->roles) {
            $this->getAll();
        }

        $results = [];

        foreach ($roles as $role) {
            if (isset($this->names[$role])) {
                $results[] = $this->roles[$this->names[$role]];
            }
        }

        return $results;
    }
838879
public function removeRoles(...$roles): self
    {
        $roles = array_flatten($roles);
        $roles = $this->getRoles($roles);

        $this->roles()->detach($roles);

        return $this;
    }
1224873
public function removeDefaultRoles(DefaultRole ...$roles)
    {
        foreach ($roles as $role) {
            $this->getDefaultRoles()->removeElement($role);
        }

        return $this;
    }
459017
public function hasRole(...$roles)
    {
        $roles = array_flatten($roles);

        foreach ($roles as $role) {
            $name = $role instanceof Role ? $role->name : $role;

            if ($this->roles->contains('name', $name)) {
                return true;
            }
        }

        return false;
    }
143139
public function detachRoles($roles=null)
    {
        if (!$roles) $roles = $this->roles()->get();

        foreach ($roles as $role) {
            $this->detachRole($role);
        }
    }
864611
public function getRoleNames($roles)
    {
        $roles = Helpers::groupModelsAndIdentifiersByType($roles);

        $roles['integers'] = $this->getNamesByKey($roles['integers']);

        $roles['models'] = Arr::pluck($roles['models'], 'name');

        return Arr::collapse($roles);
    }
375328
public function replaceRoles($roles)
    {
        $this->roles()->detach();

        $this->eventRemoveRole($roles);

        $this->roles()->attach($roles);

        $this->eventAddRole($roles);

        return $this;
    }