Tokenize the php code from a given class in in order to determine the class name.

@param string $phpCode The php code to tokenize and find the clas name from
@return array
193155
private static function classNameByTokens($phpCode)
    {
        $classes = [];
        $tokens = token_get_all($phpCode);
        $count = count($tokens);
        for ($i = 2; $i < $count; $i++) {
            if ($tokens[$i - 2][0] == T_CLASS && $tokens[$i - 1][0] == T_WHITESPACE && $tokens[$i][0] == T_STRING) {
                $classes[] = $tokens[$i][1];
            }
        }
        
        return $classes;
    }
956004
public function extractClassName()
    {
        $tokens = token_get_all($this->phpCode);
        $numberOfTokens = count($tokens);
        for ($i = 0; $i < $numberOfTokens; $i++) {
            $token = $tokens[$i];
            if (is_string($token) || $token[0] !== T_CLASS) {
                continue;
            }
            for (++$i; $i < $numberOfTokens; $i++) {
                $token = $tokens[$i];
                if (is_string($token)) {
                    break;
                }
                list($type, $value) = $token;
                if ($type === T_STRING) {
                    return $value;
                }
                if ($type !== T_WHITESPACE) {
                    break;
                }
            }
        }
        return null;
    }
1319622
protected function getTokenByAuthorizationCodeGrant($code)
    {
        try {
            $token = $this->getAuthorizationServer()->getAccessToken('authorization_code', [
                'code' => $code,
            ]);

            $this->getFrameworkBridge()->persistUserToken($token);

            return $token;
        } catch (IdentityProviderException $e) {
            return null;
        }
    }
1153232
public function getTitle($code)
    {
        if (!isset($this->titles[$code])) {
            $code = key($this->getTitles());
        }

        return $this->titles[$code];
    }
1126129
public function analyzeTag($code)
    {
        // name of the tag, opening, closure, autoclosure
        $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)';
        if (!preg_match('/'.$tag.'/isU', $code, $match)) {
            $e = new HtmlParsingException('The HTML tag ['.$code.'] provided is invalid');
            $e->setInvalidTag($code);
            throw $e;
        }
        $close     = ($match[1] === '/' ? true : false);
        $autoclose = preg_match('/\/>$/isU', $code);
        $name      = strtolower($match[2]);

        // required parameters (depends on the tag name)
        $defaultParams = array();
        $defaultParams['style'] = '';
        if ($name === 'img') {
            $defaultParams['alt'] = '';
            $defaultParams['src'] = '';
        } elseif ($name === 'a') {
            $defaultParams['href'] = '';
        }

        $param = array_merge($defaultParams, $this->extractTagAttributes($code));
        $param['style'] = trim($param['style']);
        if (strlen($param['style']) > 0 && substr($param['style'], -1) !== ';') {
            $param['style'].= ';';
        }

        // compliance of each parameter
        $color  = "#000000";
        $border = null;
        foreach ($param as $key => $val) {
            switch ($key) {
                case 'width':
                    unset($param[$key]);
                    $param['style'] .= 'width: '.$val.'px; ';
                    break;

                case 'align':
                    if ($name === 'img') {
                        unset($param[$key]);
                        $param['style'] .= 'float: '.$val.'; ';
                    } elseif ($name !== 'table') {
                        unset($param[$key]);
                        $param['style'] .= 'text-align: '.$val.'; ';
                    }
                    break;

                case 'valign':
                    unset($param[$key]);
                    $param['style'] .= 'vertical-align: '.$val.'; ';
                    break;

                case 'height':
                    unset($param[$key]);
                    $param['style'] .= 'height: '.$val.'px; ';
                    break;

                case 'bgcolor':
                    unset($param[$key]);
                    $param['style'] .= 'background: '.$val.'; ';
                    break;

                case 'bordercolor':
                    unset($param[$key]);
                    $color = $val;
                    break;

                case 'border':
                    unset($param[$key]);
                    if (preg_match('/^[0-9]+$/isU', $val)) {
                        $val = $val.'px';
                    }
                    $border = $val;
                    break;

                case 'cellpadding':
                case 'cellspacing':
                    if (preg_match('/^([0-9]+)$/isU', $val)) {
                        $param[$key] = $val.'px';
                    }
                    break;

                case 'colspan':
                case 'rowspan':
                    $val = preg_replace('/[^0-9]/isU', '', $val);
                    if (!$val) {
                        $val = 1;
                    }
                    $param[$key] = (int) $val;
                    break;

                case 'color':
                    if ($name === 'font') {
                        unset($param[$key]);
                        $param['style'] .= 'color: '.$val.'; ';
                    }
                    break;
            }
        }

        // compliance of the border
        if ($border !== null) {
            if ($border && $border !== '0px') {
                $border = 'solid '.$border.' '.$color;
            } else {
                $border = 'none';
            }

            $param['style'] .= 'border: '.$border.'; ';
            $param['border'] = $border;
        }

        // reading styles: decomposition and standardization
        $styles = explode(';', $param['style']);
        $param['style'] = array();
        foreach ($styles as $style) {
            $tmp = explode(':', $style);
            if (count($tmp) > 1) {
                $cod = $tmp[0];
                unset($tmp[0]);
                $tmp = implode(':', $tmp);
                $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp));
            }
        }

        // determining the level of table opening, with an added level
        if (in_array($name, array('ul', 'ol', 'table')) && !$close) {
            $this->num++;
            array_push($this->level, $this->num);
        }

        // get the level of the table containing the element
        if (!isset($param['num'])) {
            $param['num'] = end($this->level);
        }

        // for closures table: remove a level
        if (in_array($name, array('ul', 'ol', 'table')) && $close) {
            array_pop($this->level);
        }

        // prepare the parameters
        if (isset($param['value'])) {
            $keepSpaces = in_array($name, array('qrcode', 'barcode'));
            $param['value']  = $this->textParser->prepareTxt($param['value'], !$keepSpaces);
        }
        if (isset($param['alt'])) {
            $param['alt']    = $this->textParser->prepareTxt($param['alt']);
        }
        if (isset($param['title'])) {
            $param['title']  = $this->textParser->prepareTxt($param['title']);
        }
        if (isset($param['class'])) {
            $param['class']  = $this->textParser->prepareTxt($param['class']);
        }

        // return the new action to do
        return new Node($name, $param, $close, $autoclose);
    }
773885
public static function getDescription($code)
    {
        if (isset(self::$codes[$code])) {
            return sprintf('%d (%s)', $code, self::$codes[$code]);
        }
        return $code;
    }
308221
public function tokenize($code, $filename = null)
    {
        if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
            $encoding = mb_internal_encoding();
            mb_internal_encoding('ASCII');
        }

        $this->code = str_replace(array("\r\n", "\r"), "\n", $code);
        $this->source = '';
        $this->filename = $filename;
        $this->cursor = 0;
        $this->lineno = 1;
        $this->end = strlen($this->code);
        $this->tokens = array();
        $this->state = self::STATE_DATA;
        $this->states = array();
        $this->brackets = array();
        $this->position = -1;

        preg_match_all(self::REGEX_CHAR, $this->code, $this->positions, PREG_OFFSET_CAPTURE);

        while ($this->cursor < $this->end) {
            switch ($this->state) {
                case self::STATE_DATA:
                    $this->lexData();
                    break;

                case self::STATE_OUTPUT:
                    $this->lexOutput();
                    break;

                case self::STATE_DIRECTIVE:
                    $this->lexDirective();
                    break;
            }
        }

        if ($this->state != self::STATE_DATA) {
            $this->addCode(' ?>');
            $this->popState();
        }

        if (!empty($this->brackets)) {
            list($expect, $lineno) = array_pop($this->brackets);
            throw new SyntaxErrorException(sprintf('Unclosed "%s" at line %d in file %s', $expect, $lineno, $this->filename));
        }

        if (isset($encoding)) {
            mb_internal_encoding($encoding);
        }

        return new TokenStream(token_get_all($this->source));
    }
490644
public function tokenize($code)
    {
        $code = trim((string) $code);
        if (empty($code)) {
            throw new \InvalidArgumentException('Cannot tokenize empty string.');
        }

        $this->code = $code;
        $this->tokens = array();

        $tokenArray = explode(' ', $this->code);

        if (!is_array($tokenArray) || empty($tokenArray)) {
            throw new \InvalidArgumentException(
                sprintf('Cannot tokenize string: %s, please use " "(empty space for delimeter betwwen tokens)', $this->code)
            );
        }

        foreach ($tokenArray as $t) {
            if (array_key_exists($t, static::$operatorsMap)) {
                $token = new Operator(
                        $t,
                        static::$operatorsMap[$t]['priority'],
                        static::$operatorsMap[$t]['associativity']
                );
            } elseif (is_numeric($t)) {
                $token = new Token((float) $t, Token::T_OPERAND);
            }elseif('(' === $t) {
                $token = new Token($t, Token::T_LEFT_BRACKET);
            }elseif(')' === $t) {
                $token = new Token($t, Token::T_RIGHT_BRACKET);
            }elseif('' === $t) {
                continue;
            }else {
                throw new \InvalidArgumentException(sprintf('Syntax error: unknown token "%s"', $t));
            }

            $this->tokens[] = $token;
        }

        return $this->tokens;
    }
342779
public function extractNamespace()
    {
        $namespaceParts = [];
        $tokens = token_get_all($this->phpCode);
        $numberOfTokens = count($tokens);
        for ($i = 0; $i < $numberOfTokens; $i++) {
            $token = $tokens[$i];
            if (is_string($token) || $token[0] !== T_NAMESPACE) {
                continue;
            }
            for (++$i; $i < $numberOfTokens; $i++) {
                $token = $tokens[$i];
                if (is_string($token)) {
                    break;
                }
                list($type, $value) = $token;
                if ($type === T_STRING) {
                    $namespaceParts[] = $value;
                    continue;
                }
                if ($type !== T_NS_SEPARATOR && $type !== T_WHITESPACE) {
                    break;
                }
            }
            break;
        }
        if ($namespaceParts === []) {
            return null;
        }
        return implode('\\', $namespaceParts);
    }
1164953
public static function unserial($code)
    {
        $codeArr = array();

        $codeLines = explode("\n", gzuncompress($code));
        foreach ($codeLines as $line)
            $codeArr[] = str_split($line);

        return $codeArr;
    }
316479
public function tokenize($code)
    {
        $this->tokens = array();
        $lines        = preg_split('/\r?\n/', $code);
        $number       = 0;

        foreach ($lines as $number => $fragment) {
            $this->processLine($number + 1, $fragment);
            $this->tokens[] = new Token(self::TOKEN_EOL, null, $number + 1);
        }
        $this->tokens[] = new Token(self::TOKEN_EOF, null, $number + 1);

        return new TokenStream($this->tokens);
    }
624610
public static function getTokensFromString($code) {
      try {
        $tokens = token_get_all($code, TOKEN_PARSE);
      } catch (\ParseError $e) {
        // with TOKEN_PARSE flag, the function throws on invalid code
        // let's just ignore the error and tokenize the code without the flag
        $tokens = token_get_all($code);
      }

      foreach ($tokens as $index => $tokenData) {

        if (!is_array($tokenData)) {
          $previousIndex = $index - 1;

          /** @var Token $previousToken */
          $previousToken = $tokens[$previousIndex];
          $line = $previousToken->getLine() + substr_count($previousToken->getValue(), "\n");
          $tokenData = [
            Token::INVALID_TYPE,
            $tokenData,
            $line,
          ];
        }

        $token = new Token($tokenData);
        $token->setIndex($index);
        $tokens[$index] = $token;

      }

      return $tokens;
    }
655224
public static function get($code)
  {
    if (array_key_exists($code, self::$translations)) {
      return self::$translations[$code];
    }
    return sprintf('[%s]', $code);
  }
876669
protected function decodeHash( $code )
	{
		$php	= gzinflate( base64_decode( $code ) );
		$php	= substr( $php, strlen( $this->incodePrefix) , -strlen( $this->incodeSuffix ) );
		return 	$php;
	}
689140
public function getToken($code)
	{
		$request = 	new Request('POST', 'token', [], http_build_query([
			'redirect_uri'  => $this->getRedirectUri(),
			'client_id'		=> $this->getClientId(),
			'client_secret' => $this->getClientSecret(),
			'grant_type' 	=> 'authorization_code',
			'code' 			=> $code
		]));

		try {
			$response = $this->getHttpClient()->send($request);
		} catch (\Exception $e) {
			throw new SurveyMonkeyApiException($e->getMessage(), $e->getCode(), $e);
		}

		if (!$response->hasHeader('content-type') || !preg_match('/application\/json/i', $response->getHeader('content-type')[0])) {
			throw new SurveyMonkeyApiException(spritnf('Response expected to be a JSON response. Received %s', $response->getHeader('content-type')[0]));
		}

		return json_decode($response->getBody(), true);
	}
236421
protected function makeCodeSpan($code) {
		if ($this->code_span_content_func) {
			$code = call_user_func($this->code_span_content_func, $code);
		} else {
			$code = htmlspecialchars(trim($code), ENT_NOQUOTES);
		}
		return $this->hashPart("<code>$code</code>");
	}
587077
public function get($code)
    {
        $result = null;
        $this->hook->attach('language.get.before', $code, $result, $this);

        if (isset($result)) {
            return (array) $result;
        }

        $list = $this->getList();
        $result = isset($list[$code]) ? $list[$code] : array();

        $this->hook->attach('language.get.after', $code, $result, $this);
        return (array) $result;
    }