@param $state

@return array|string
@throws \Exception
346719
protected function setBinaryState($state)
    {
        $service = $this->services['BridgeService']['serviceType'];
        $controlUrl = $this->services['BridgeService']['controlURL'];
        $method = 'SetBinaryState';
        $arguments = [
            'BinaryState' => $state
        ];

        $rs = $this->client->request($controlUrl, $service, $method, $arguments);
        if(!empty($rs)) {
            $rs = $this->unwrapResponse($rs);

            if (isset($rs['s:Fault'])) {
                throw new \Exception('Failed to change switch state. ' . print_r($rs, true));
            }

            return $rs;
        } else {
            $this->saveState($state);

            return true;
        }
    }
854687
public function listPullRequests(string $state = AbstractApi::STATE_OPEN, string $head = null, string $base = null,
                                     string $sort = AbstractApi::SORT_CREATED,
                                     string $direction = AbstractApi::DIRECTION_ASC): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/pulls?:args', $this->getOwner(),
            $this->getRepo(), http_build_query([
                'state'     => $state,
                'head'      => $head,
                'base'      => $base,
                'sort'      => $sort,
                'direction' => $direction
            ])));
    }
773043
protected function getCodeFields($state = null)
    {
        $fields = array_merge([
            'client_id' => $this->clientId,
            'redirect_uri' => $this->redirectUrl,
            'scope' => $this->formatScopes($this->scopes, $this->scopeSeparator),
            'response_type' => 'code',
        ], $this->parameters);

        if ($this->usesState()) {
            $fields['state'] = $state;
        }

        return $fields;
    }
885722
public function setState($state = null)
        {
            if (null === $state) {
                $this->_state = $state;
                return $this;
            }

            if (in_array($state, array(static::STATE_SUCCESS, static::STATE_ERROR, static::STATE_INFO))) {
                $this->_state = $state;
            }

            return $this;
        }
422840
public function setState(int $state): ControllerInterface
    {
        switch ($state) {
            case self::STATE_PLAYING:
                return $this->play();
            case self::STATE_PAUSED:
                return $this->pause();
            case self::STATE_STOPPED:
                return $this->pause();
        }
        throw new \InvalidArgumentException("Unknown state: {$state})");
    }
6009
public final function enable($state = true){

		$old_state = $this->_enabled;

		$this->_enabled = (bool) $state;

		return $old_state;
	}
585527
protected function setState($state)
    {
        $serviceService = $this->getServiceLocator()->get(StateStorage::SERVICE_ID);
        $userUri = $this->getSession()->getUserUri();
        return is_null($userUri) ? false : $serviceService->set($userUri, $this->getServiceCallId(), $state);
    }
67586
public function serialize(UserState $state)
    {
        $saveFile = sprintf('%s/%s', $this->path, static::SAVE_FILE);

        $data = file_exists($saveFile)
            ? $this->readJson($saveFile)
            : [];

        $data[$this->workshopName] = [
            'completed_exercises'   => $state->getCompletedExercises(),
            'current_exercise'      => $state->getCurrentExercise(),
        ];

        return file_put_contents($saveFile, json_encode($data));
    }
290670
public function execute(State $state) {
        $errors = [];
        foreach ($state->functions as $function) {
            $errors = array_merge($errors, $this->verifyReturn($function, $state));
        }
        foreach ($state->methods as $method) {
            $errors = array_merge($errors, $this->verifyReturn($method, $state));
        }
        return $errors;
    }
948913
public function getStateMessage(ModelState $state)
    {
        $message = '';

        if ($state->getSuccessful()) {
            $data = $state->getData();

            $message = isset($data['success_message']) ? $data['success_message'] : '';
        } else {
            $message = implode("\n", $state->getErrors());
        }

        return $message;
    }
62347
public function set_state($state) {
        if ($state != $this->_state + 1 || $state > self::STATE_DONE) {
            throw new coding_exception('Invalid state passed to moodle_page::set_state. We are in state ' .
                    $this->_state . ' and state ' . $state . ' was requested.');
        }

        if ($state == self::STATE_PRINTING_HEADER) {
            $this->starting_output();
        }

        $this->_state = $state;
    }
1146706
public function getStateCandidates(int $state): array
    {
        $candidates = [];

        foreach ($this->candidates as $candidateId => $candidate) {
            if ($candidate->getState() == $state) {
                $candidates[$candidateId] = $candidate;
            }
        }

        return $candidates;
    }
1178931
protected function setState($state)
    {
        if (!array_key_exists($state, $this->stateDirectives)) {
            throw new InvalidArgumentException("Invalid state {$state}");
        }
        $this->state = $state;
        return $this;
    }
714249
public function getState($state = null)
	{
		if ($state === null) {
			$state = $this->getValue();
		}

		if (!isset($this->states[$state])) {
			return 'default';
		}

		return $this->states[$state];
	}
449799
protected function stateAttributes($state, array $attributes)
    {
        $stateAttributes = $this->states[$this->class][$state];

        if (! is_callable($stateAttributes)) {
            return $stateAttributes;
        }

        return call_user_func(
            $stateAttributes,
            $this->faker, $attributes
        );
    }
268506
private function makeCallable($state) : callable
    {
        if (is_callable($state)) {
            return $state;
        }
        return function () use ($state) {
            if (is_string($state) && class_exists($state)) {
                $state = new $state;
            }
            return $state;
        };
    }
1333092
public function removeAuthContextClassRefWithPrefix(&$state)
    {
        $conf = Configuration::getConfig(self::CONFIG_FILE_NAME);
        $prefix = $conf->getString(self::PROPNAME_PREFIX, null);

        if (is_null($prefix)) {
            return;
        }
        unset($state['saml:RequestedAuthnContext']['AuthnContextClassRef']);
        $array = array();
        foreach ($this->authnContextClassRef as $value) {
            if (!(substr($value, 0, strlen($prefix)) === $prefix)) {
                array_push($array, $value);
            }
        }
        if (!empty($array)) {
            $state['saml:RequestedAuthnContext']['AuthnContextClassRef']
                = $array;
        }
    }