private function validateRole($role, $roles, $checkExistence = true)
    {
        if (empty($roles)) {
            return null;
        }

        $roleExists = array_key_exists($role, $roles);
        $condition =  $checkExistence ? !$roleExists : $roleExists;
        if ($condition) {
            $errorMessage = $checkExistence ? "Role %s doesn't exist" : 'Role %s already exists';
            throw new \InvalidArgumentException(sprintf($errorMessage, $role));
        }

        return $role;
    }
private function validateRole($role, $roles, $checkExistence = true)
    {
        if (empty($roles)) {
            return null;
        }

        $roleExists = array_key_exists($role, $roles);
        $condition =  $checkExistence ? !$roleExists : $roleExists;
        if ($condition) {
            $errorMessage = $checkExistence ? "Role %s doesn't exist" : 'Role %s already exists';
            throw new \InvalidArgumentException(sprintf($errorMessage, $role));
        }

        return $role;
    }
private function validateRole ( $ role , $ roles , $ checkExistence = true ) { if ( empty ( $ roles ) ) { return null ; } $ roleExists = array_key_exists ( $ role , $ roles ) ; $ condition = $ checkExistence ? ! $ roleExists : $ roleExists ; if ( $ condition ) { $ errorMessage = $ checkExistence ? "Role %s doesn't exist" : 'Role %s already exists' ; throw new \ InvalidArgumentException ( sprintf ( $ errorMessage , $ role ) ) ; } return $ role ; }
Validates role existence or non existence.

@param string $role
Role machine name.
@param array $roles
Array of available roles.
@param bool $checkExistence
To check existence or non existence.

@return string|null
Role machine name.
Validates role existence or non existence .