Will return the parameters of a given token.

@param  array $tokenId The tokenId you are analyzing
@param  array $tokens  The array of the currently created tokens
@return array
504438
public static function parameters($tokenId, array $tokens) {
		$params = array();
		if ($tokens[$tokenId]['id'] !== T_FUNCTION) {
			throw new \Exception('Cannot call params on non function');
		}
		$foundOpen = false;
		$total = count($tokens);
		for ($key = $tokenId; $key <= $total; $key++) {
			$token = $tokens[$key];
			if ($foundOpen) {
				if ($token['content'] === ')') {
					break;
				} elseif ($token['id'] === T_VARIABLE) {
					$params[] = $key;
				}
			} elseif ($token['content'] === '(') {
				$foundOpen = true;
			}
		}
		return $params;
	}
412841
public static function columns(array $tokens) {
        $columns = array_filter($tokens['INSERT'], function($token) {
            return $token['expr_type'] === 'column-list';
        });

        return array_map(function($column) {
            return end($column['no_quotes']['parts']);
        }, end($columns)['sub_tree']);
    }
77178
private function activeNamespace(int $tokenID): string
    {
        foreach ($this->namespaces as $namespace => $position) {
            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
                return $namespace;
            }
        }

        //Seems like no namespace declaration
        $this->namespaces[''] = [
            self::O_TOKEN => 0,
            self::C_TOKEN => count($this->tokens),
            self::N_USES  => [],
        ];

        return '';
    }
1200352
public function parse($tokens = null, $additional = [], $embedded = false)
    {
        if (is_string($tokens)) {
            $tokens = $this->tokenize($tokens, $additional, $embedded);
        } elseif (!$tokens instanceof TokenIterator) {
            // Todo: Own Exceptions
            throw new \InvalidArgumentException('$tokens must be string or TokenIterator');
        }

        return $this->_process($tokens);
    }
31821
private function createId(array $tokens) {
        $idColumn = Identifier::column($tokens, new MetaData());
        return empty($this->result[$idColumn]) ? null : $this->result[$idColumn];
    }
1153064
public static function getTokenCustomProperties(ContainerInterface $container, TokenInterface $token): array
    {
        $userId = $token->getUserIdentifier();

        /** @var FactoryInterface $factory */
        $factory = $container->get(FactoryInterface::class);
        /** @var UsersApi $usersApi */
        $usersApi = $factory->createApi(UsersApi::class);

        $builder = $usersApi->shouldBeUntyped()->withIndexFilter($userId)->createIndexBuilder([
            User::FIELD_EMAIL,
            User::FIELD_FIRST_NAME,
            User::FIELD_LAST_NAME,
        ]);

        $user = $usersApi->fetchRow($builder, User::class);

        return [
            User::FIELD_ID         => $userId,
            User::FIELD_EMAIL      => $user[User::FIELD_EMAIL],
            User::FIELD_FIRST_NAME => $user[User::FIELD_FIRST_NAME],
            User::FIELD_LAST_NAME  => $user[User::FIELD_LAST_NAME],
        ];
    }
416507
protected function parseTokens(array $tokens)
    {
        //Current active token
        $activeToken = [];

        //Some blocks can be named as parent. We have to make sure we closing the correct one
        $activeLevel = 0;

        //Content to represent full tag declaration (including body)
        $activeContent = [];

        foreach ($tokens as $token) {
            $tokenType = $token[HtmlTokenizer::TOKEN_TYPE];

            if (empty($activeToken)) {
                switch ($tokenType) {
                    case HtmlTokenizer::TAG_VOID:
                    case HtmlTokenizer::TAG_SHORT:
                        //Token will be clarified using Supervisor
                        $this->mountToken($token);
                        break;

                    case HtmlTokenizer::TAG_OPEN:
                        $activeToken = $token;
                        break;

                    case HtmlTokenizer::TAG_CLOSE:
                        if ($this->compiler->getSyntax()->isStrict()) {
                            throw new StrictSyntaxException(
                                "Unpaired close tag '{$token[HtmlTokenizer::TOKEN_NAME]}'.",
                                $token
                            );
                        }
                        break;
                    case HtmlTokenizer::PLAIN_TEXT:
                        //Everything outside any tag
                        $this->mountContent([$token]);
                        break;
                }

                continue;
            }

            if (
                $tokenType != HtmlTokenizer::PLAIN_TEXT
                && $token[HtmlTokenizer::TOKEN_NAME] == $activeToken[HtmlTokenizer::TOKEN_NAME]
            ) {
                if ($tokenType == HtmlTokenizer::TAG_OPEN) {
                    $activeContent[] = $token;
                    $activeLevel++;
                } elseif ($tokenType == HtmlTokenizer::TAG_CLOSE) {
                    if ($activeLevel === 0) {
                        //Closing current token
                        $this->mountToken($activeToken, $activeContent, $token);
                        $activeToken = $activeContent = [];
                    } else {
                        $activeContent[] = $token;
                        $activeLevel--;
                    }
                } else {
                    //Short tag with same name (used to call for parent content)s
                    $activeContent[] = $token;
                }

                continue;
            }

            //Collecting token content
            $activeContent[] = $token;
        }

        //Everything after last tag
        $this->mountContent($activeContent);
    }
923789
protected static function parameters(array $tokens)
    {
        $arguments = [];

        $options = [];

        foreach ($tokens as $token) {
            if (preg_match('/-{2,}(.*)/', $token, $matches)) {
                $options[] = static::parseOption($matches[1]);
            } else {
                $arguments[] = static::parseArgument($token);
            }
        }

        return [$arguments, $options];
    }
1079990
public function getToken($tokenId)
    {
        $tracker = $this->loader->getTracker();
        $token = $tracker->getToken($tokenId);
        return $token;
    }
49025
public static function create(array $tokens) {
        HashMap::assert($tokens, 'tokens');

        $columns = array_map(function($token) {
            $segments = explode('=', $token['base_expr']);
            return trim($segments[0]);
        }, $tokens['SET']);

        $values = array_map(function($token) {
            $segments = explode('=', $token['base_expr']);
            return Value::create(trim($segments[1]));
        }, $tokens['SET']);

        return array_combine($columns, $values);
    }
842213
public static function locateArguments(array $tokens): array
    {
        $definition = null;
        $level = 0;

        $result = [];
        foreach ($tokens as $token) {
            if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE) {
                continue;
            }

            if (empty($definition)) {
                $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []];
            }

            if (
                $token[ReflectionFile::TOKEN_TYPE] == '('
                || $token[ReflectionFile::TOKEN_TYPE] == '['
            ) {
                ++$level;
                $definition['value'] .= $token[ReflectionFile::TOKEN_CODE];
                continue;
            }

            if (
                $token[ReflectionFile::TOKEN_TYPE] == ')'
                || $token[ReflectionFile::TOKEN_TYPE] == ']'
            ) {
                --$level;
                $definition['value'] .= $token[ReflectionFile::TOKEN_CODE];
                continue;
            }

            if ($level) {
                $definition['value'] .= $token[ReflectionFile::TOKEN_CODE];
                continue;
            }

            if ($token[ReflectionFile::TOKEN_TYPE] == ',') {
                $result[] = self::createArgument($definition);
                $definition = null;
                continue;
            }

            $definition['tokens'][] = $token;
            $definition['value'] .= $token[ReflectionFile::TOKEN_CODE];
        }

        //Last argument
        if (is_array($definition)) {
            $definition = self::createArgument($definition);
            if (!empty($definition->getType())) {
                $result[] = $definition;
            }
        }

        return $result;
    }
198266
public static function values(array $tokens) {
        $values = explode(',', self::removeBrackets(self::removeSpacesBetweenComma(end($tokens['VALUES'])['base_expr'])));

        return array_map(function($value) {
            return Value::create($value);
        }, $values);
    }
82256
public function user_webservice_tokens_box($tokens, $userid, $documentation = false) {
        global $CFG, $DB;

        // display strings
        $stroperation = get_string('operation', 'webservice');
        $strtoken = get_string('key', 'webservice');
        $strservice = get_string('service', 'webservice');
        $strcreator = get_string('tokencreator', 'webservice');
        $strcontext = get_string('context', 'webservice');
        $strvaliduntil = get_string('validuntil', 'webservice');

        $return = $this->output->heading(get_string('securitykeys', 'webservice'), 3, 'main', true);
        $return .= $this->output->box_start('generalbox webservicestokenui');

        $return .= get_string('keyshelp', 'webservice');

        $table = new html_table();
        $table->head = array($strtoken, $strservice, $strvaliduntil, $strcreator, $stroperation);
        $table->align = array('left', 'left', 'left', 'center', 'left', 'center');
        $table->width = '100%';
        $table->data = array();

        if ($documentation) {
            $table->head[] = get_string('doc', 'webservice');
            $table->align[] = 'center';
        }

        if (!empty($tokens)) {
            foreach ($tokens as $token) {

                if ($token->creatorid == $userid) {
                    $reset = "<a href=\"" . $CFG->wwwroot . "/user/managetoken.php?sesskey="
                            . sesskey() . "&amp;action=resetwstoken&amp;tokenid=" . $token->id . "\">";
                    $reset .= get_string('reset') . "</a>";
                    $creator = $token->firstname . " " . $token->lastname;
                } else {
                    //retrieve administrator name
                    $admincreator = $DB->get_record('user', array('id'=>$token->creatorid));
                    $creator = $admincreator->firstname . " " . $admincreator->lastname;
                    $reset = '';
                }

                $userprofilurl = new moodle_url('/user/view.php?id=' . $token->creatorid);
                $creatoratag = html_writer::start_tag('a', array('href' => $userprofilurl));
                $creatoratag .= $creator;
                $creatoratag .= html_writer::end_tag('a');

                $validuntil = '';
                if (!empty($token->validuntil)) {
                    $validuntil = userdate($token->validuntil, get_string('strftimedatetime', 'langconfig'));
                }

                $tokenname = $token->name;
                if (!$token->enabled) { //that is the (1 token-1ws) related ws is not enabled.
                    $tokenname = '<span class="dimmed_text">'.$token->name.'</span>';
                }
                $row = array($token->token, $tokenname, $validuntil, $creatoratag, $reset);

                if ($documentation) {
                    $doclink = new moodle_url('/webservice/wsdoc.php',
                            array('id' => $token->id, 'sesskey' => sesskey()));
                    $row[] = html_writer::tag('a', get_string('doc', 'webservice'),
                            array('href' => $doclink));
                }

                $table->data[] = $row;
            }
            $return .= html_writer::table($table);
        } else {
            $return .= get_string('notoken', 'webservice');
        }

        $return .= $this->output->box_end();
        return $return;
    }
464357
protected function _controlContent($tokenId, $tokens, $root = true) {
		$token = $tokens[$tokenId];
		$body = $token['content'];

		foreach ($token['children'] as $childrenId) {
			if (!$tokens[$childrenId]['children']) {
				$body .= $tokens[$childrenId]['content'];
			} elseif ($root && $tokens[$childrenId]['content'] === '{') {
				$body .= $tokens[$childrenId]['content'];
				break;
			} else {
				$body .= $this->_controlContent($childrenId, $tokens, false);
			}
		}
		return $body;
	}
805906
public static function create(array $tokens) {
        HashMap::assert($tokens, 'tokens');

        return array_combine(self::columns($tokens), self::values($tokens));
    }
670759
public function refreshToken($tokenId) {

		$this->storage->removeToken($tokenId);

		$token = new CsrfToken(
			$tokenId,
			$this->generateValue((int) $this->tokenLength)
		);

		$this->storage->setToken($tokenId, $token);

		return $token;

	}
866388
public function serializeNodes(array $nodes, $language, TokenInterface $token)
    {
        $return = [];

        foreach ($nodes as $node) {
            $nodeData = $this->serializeNode($node, $language, $token);

            if ($nodeData) {
                $return[] = $nodeData;
            }
        }

        return $return;
    }