Find the class in the tokens starting at a given key.

@param  int  $key
@param  array  $tokens
@return string|null
347927
protected function getClass($key, array $tokens)
    {
        $class = null;
        $tokenCount = count($tokens);
        for ($i = $key; $i < $tokenCount; $i++) {
            if ($this->isPartOfClass($tokens[$i])) {
                $class .= $tokens[$i][1];
            } elseif ($this->isWhitespace($tokens[$i])) {
                return $class;
            }
        }
    }
996650
public static function alias(array $tokens) {
        HashMap::assert($tokens, 'tokens');

        $operation = SqlOperation::create($tokens);
        if ($operation === SqlOperations::INSERT) return null;
        if ($operation === SqlOperations::UPDATE) return $tokens['UPDATE'][0]['alias']['name'];
        return $tokens['FROM'][0]['alias']['name'];
    }
1072698
protected function getNamespace($key, array $tokens)
    {
        $namespace = null;
        $tokenCount = count($tokens);
        for ($i = $key; $i < $tokenCount; $i++) {
            if ($this->isPartOfNamespace($tokens[$i])) {
                $namespace .= $tokens[$i][1];
            } elseif ($tokens[$i] == ';') {
                return $namespace;
            }
        }
    }
280104
public function nextOf($tokenNames)
    {
        $i = $this->index+1;
        $len = count($this->tokens);
        while ($i < $len) {
            $tok = $this->tokens[$i][0];
            if (in_array($tok, $tokenNames)) {
                return $tok;
            }
            $i++;
        }
        return null;
    }
486040
protected function findVariableName(array $tokens, $start) {
        for ($i = $start - 1; $i >= 0; $i--) {
            if (is_array($tokens[$i]) && $tokens[$i][0] == T_VARIABLE) {
                $variable = $tokens[$i][1];

                if (is_array($tokens[$i+1]) &&
                    $tokens[$i+1][0] == T_OBJECT_OPERATOR &&
                    $tokens[$i+2] != '(' &&
                    $tokens[$i+3] != '(') {
                    $variable .= '->' . $tokens[$i+2][1];
                }

                return $variable;
            }
        }

        return false;
    }
119945
private function matchNamePositionForEndOfFunctionCall(Tokens $tokens, int $position): ?int
    {
        try {
            $blockStart = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $position);
        } catch (Throwable $throwable) {
            // not a block start
            return null;
        }

        $previousTokenPosition = $blockStart - 1;
        $possibleMethodNameToken = $tokens[$previousTokenPosition];

        // not a "methodCall()"
        if (! $possibleMethodNameToken->isGivenKind(T_STRING)) {
            return null;
        }

        // starts with small letter?
        $methodOrFunctionName = $possibleMethodNameToken->getContent();
        if (! ctype_lower($methodOrFunctionName[0])) {
            return null;
        }

        // is "someCall()"? we don't care, there are no arguments
        if ($tokens[$blockStart + 1]->equals(')')) {
            return null;
        }

        return $previousTokenPosition;
    }
525298
private static function getNthTokenWithoutWhitespace($tokens, $i) {
		$j = 0;
		foreach ($tokens as $token) {
			if ($token['token'] == 'T_WHITESPACE') {
				continue;
			}
			if ($i == $j) {
				return $token;
			}
			$j++;
		}
		return null;
	}
957809
public function getKey(string $key = null): string
    {
        if ($key === null) {
            return $this->defaultKey;
        }

        if (!isset($this->tokens[$key])) {
            throw new \LogicException(sprintf('Token with name %s could not be found', $key));
        }

        return $key;
    }
745007
protected function getAnyKey(array $keys)
    {
        foreach($keys as $key)
        {
            $value = $this->getValue($key);

            if(!is_null($value))
            {
                return $value;
            }
        }
    }
1230475
public function findUnitByStart(Token $token) {
		foreach ($this->collection as $unit) {
			if ($unit->start === $token) {
				return $unit;
			}
		}

		return null;
	}
403830
public static function check($key, $token)
    {

        if (isset($_SESSION[$key]) && $token === $_SESSION[$key]) {
            unset($_SESSION[$key]);
            return true;
        }

        return false;
    }
525318
protected function extractClassPermissions($key)
    {
        if (! str_contains($key, '@')) {
            return (array) $key;
        }

        $keys = [];

        list($class, $methods) = explode('@', $key);

        foreach (explode(',', $methods) as $method) {
            $keys[] = "{$class}@{$method}";
        }

        return $keys;
    }
589860
private function nextToken(&$tokens, $context)
    {
        while (true) {
            $token = next($tokens);
            if ($token[0] === T_WHITESPACE) {
                continue;
            }
            if ($token[0] === T_COMMENT) {
                $pos = strpos($token[1], '@OA\\');
                if ($pos) {
                    $line = $context->line ? $context->line + $token[2] : $token[2];
                    $commentContext = new Context(['line' => $line], $context);
                    Logger::notice('Annotations are only parsed inside `/**` DocBlocks, skipping ' . $commentContext);
                }
                continue;
            }

            return $token;
        }
    }
1019855
public static function findKeyInATree($data, $key, $hashes = []) {
		if (!empty($data[$key])) {
			$hashes[] = $key;
			return $hashes;
		} else {
			foreach ($data as $k => $v) {
				if (empty($v['options'])) {
					continue;
				}
				$hashes2 = $hashes;
				$hashes2[] = $k;
				$hashes2[] = 'options';
				$result = self::find_key_in_a_tree($v['options'], $key, $hashes2);
				if ($result !== false) {
					return $result;
				}
			}
		}
		return false;
	}
105719
public function parseToken($key = 'access_token')
    {
        if ( $token = $this->getToken() )
        {
            $token_array = json_decode($token, true);

            return $token_array[$key];
        }
    }
574970
public function loadToken($key)
    {
        $token = $this->db
            ->select('ucms_user_token', 'ut')
            ->fields('ut')
            ->condition('token', $key)
            ->range(0, 1)
            ->execute()
            ->fetchObject('MakinaCorpus\\Ucms\\User\\Token');

        if (!$token) {
            return null;
        }

        $token->expiration_date = new \DateTime($token->expiration_date);
        return $token;
    }
1314940
protected function getNamespaceAndClass($tokens)
    {
        $class = '';
        while (self::hasToken(
            [self::T_NS_SEPARATOR, self::T_STRING],
            $token = \array_pop($tokens)
        )) {
            if (self::needCompleteClass($token)) {
                continue;
            }

            $class = $token[1] . $class;
        }

        return $class;
    }