PHP_CodeSniffer
[ class tree: PHP_CodeSniffer ] [ index: PHP_CodeSniffer ] [ all elements ]

Source for file PHP.php

Documentation is available at PHP.php

  1. <?php
  2. /**
  3.  * Tokenizes PHP code.
  4.  *
  5.  * @author    Greg Sherwood <gsherwood@squiz.net>
  6.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  7.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  8.  */
  9.  
  10. namespace PHP_CodeSniffer\Tokenizers;
  11.  
  12. use PHP_CodeSniffer\Util;
  13.  
  14. class PHP extends Tokenizer
  15. {
  16.  
  17.  
  18.     /**
  19.      * A list of tokens that are allowed to open a scope.
  20.      *
  21.      * This array also contains information about what kind of token the scope
  22.      * opener uses to open and close the scope, if the token strictly requires
  23.      * an opener, if the token can share a scope closer, and who it can be shared
  24.      * with. An example of a token that shares a scope closer is a CASE scope.
  25.      *
  26.      * @var array 
  27.      */
  28.     public $scopeOpeners = array(
  29.                             T_IF            => array(
  30.                                                 'start'  => array(
  31.                                                              T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
  32.                                                              T_COLON              => T_COLON,
  33.                                                             ),
  34.                                                 'end'    => array(
  35.                                                              T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
  36.                                                              T_ENDIF               => T_ENDIF,
  37.                                                              T_ELSE                => T_ELSE,
  38.                                                              T_ELSEIF              => T_ELSEIF,
  39.                                                             ),
  40.                                                 'strict' => false,
  41.                                                 'shared' => false,
  42.                                                 'with'   => array(
  43.                                                              T_ELSE   => T_ELSE,
  44.                                                              T_ELSEIF => T_ELSEIF,
  45.                                                             ),
  46.                                                ),
  47.                             T_TRY           => array(
  48.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  49.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  50.                                                 'strict' => true,
  51.                                                 'shared' => false,
  52.                                                 'with'   => array(),
  53.                                                ),
  54.                             T_CATCH         => array(
  55.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  56.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  57.                                                 'strict' => true,
  58.                                                 'shared' => false,
  59.                                                 'with'   => array(),
  60.                                                ),
  61.                             T_FINALLY       => array(
  62.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  63.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  64.                                                 'strict' => true,
  65.                                                 'shared' => false,
  66.                                                 'with'   => array(),
  67.                                                ),
  68.                             T_ELSE          => array(
  69.                                                 'start'  => array(
  70.                                                              T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
  71.                                                              T_COLON              => T_COLON,
  72.                                                             ),
  73.                                                 'end'    => array(
  74.                                                              T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
  75.                                                              T_ENDIF               => T_ENDIF,
  76.                                                             ),
  77.                                                 'strict' => false,
  78.                                                 'shared' => false,
  79.                                                 'with'   => array(
  80.                                                              T_IF     => T_IF,
  81.                                                              T_ELSEIF => T_ELSEIF,
  82.                                                             ),
  83.                                                ),
  84.                             T_ELSEIF        => array(
  85.                                                 'start'  => array(
  86.                                                              T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
  87.                                                              T_COLON              => T_COLON,
  88.                                                             ),
  89.                                                 'end'    => array(
  90.                                                              T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
  91.                                                              T_ENDIF               => T_ENDIF,
  92.                                                              T_ELSE                => T_ELSE,
  93.                                                              T_ELSEIF              => T_ELSEIF,
  94.                                                             ),
  95.                                                 'strict' => false,
  96.                                                 'shared' => false,
  97.                                                 'with'   => array(
  98.                                                              T_IF   => T_IF,
  99.                                                              T_ELSE => T_ELSE,
  100.                                                             ),
  101.                                                ),
  102.                             T_FOR           => array(
  103.                                                 'start'  => array(
  104.                                                              T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
  105.                                                              T_COLON              => T_COLON,
  106.                                                             ),
  107.                                                 'end'    => array(
  108.                                                              T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
  109.                                                              T_ENDFOR              => T_ENDFOR,
  110.                                                             ),
  111.                                                 'strict' => false,
  112.                                                 'shared' => false,
  113.                                                 'with'   => array(),
  114.                                                ),
  115.                             T_FOREACH       => array(
  116.                                                 'start'  => array(
  117.                                                              T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
  118.                                                              T_COLON              => T_COLON,
  119.                                                             ),
  120.                                                 'end'    => array(
  121.                                                              T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
  122.                                                              T_ENDFOREACH          => T_ENDFOREACH,
  123.                                                             ),
  124.                                                 'strict' => false,
  125.                                                 'shared' => false,
  126.                                                 'with'   => array(),
  127.                                                ),
  128.                             T_INTERFACE     => array(
  129.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  130.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  131.                                                 'strict' => true,
  132.                                                 'shared' => false,
  133.                                                 'with'   => array(),
  134.                                                ),
  135.                             T_FUNCTION      => array(
  136.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  137.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  138.                                                 'strict' => true,
  139.                                                 'shared' => false,
  140.                                                 'with'   => array(),
  141.                                                ),
  142.                             T_CLASS         => array(
  143.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  144.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  145.                                                 'strict' => true,
  146.                                                 'shared' => false,
  147.                                                 'with'   => array(),
  148.                                                ),
  149.                             T_TRAIT         => array(
  150.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  151.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  152.                                                 'strict' => true,
  153.                                                 'shared' => false,
  154.                                                 'with'   => array(),
  155.                                                ),
  156.                             T_USE           => array(
  157.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  158.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  159.                                                 'strict' => false,
  160.                                                 'shared' => false,
  161.                                                 'with'   => array(),
  162.                                                ),
  163.                             T_DECLARE       => array(
  164.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  165.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  166.                                                 'strict' => false,
  167.                                                 'shared' => false,
  168.                                                 'with'   => array(),
  169.                                                ),
  170.                             T_NAMESPACE     => array(
  171.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  172.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  173.                                                 'strict' => false,
  174.                                                 'shared' => false,
  175.                                                 'with'   => array(),
  176.                                                ),
  177.                             T_WHILE         => array(
  178.                                                 'start'  => array(
  179.                                                              T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
  180.                                                              T_COLON              => T_COLON,
  181.                                                             ),
  182.                                                 'end'    => array(
  183.                                                              T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
  184.                                                              T_ENDWHILE            => T_ENDWHILE,
  185.                                                             ),
  186.                                                 'strict' => false,
  187.                                                 'shared' => false,
  188.                                                 'with'   => array(),
  189.                                                ),
  190.                             T_DO            => array(
  191.                                                 'start'  => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET),
  192.                                                 'end'    => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET),
  193.                                                 'strict' => true,
  194.                                                 'shared' => false,
  195.                                                 'with'   => array(),
  196.                                                ),
  197.                             T_SWITCH        => array(
  198.                                                 'start'  => array(
  199.                                                              T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
  200.                                                              T_COLON              => T_COLON,
  201.                                                             ),
  202.                                                 'end'    => array(
  203.                                                              T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
  204.                                                              T_ENDSWITCH           => T_ENDSWITCH,
  205.                                                             ),
  206.                                                 'strict' => true,
  207.                                                 'shared' => false,
  208.                                                 'with'   => array(),
  209.                                                ),
  210.                             T_CASE          => array(
  211.                                                 'start'  => array(
  212.                                                              T_COLON     => T_COLON,
  213.                                                              T_SEMICOLON => T_SEMICOLON,
  214.                                                             ),
  215.                                                 'end'    => array(
  216.                                                              T_BREAK    => T_BREAK,
  217.                                                              T_RETURN   => T_RETURN,
  218.                                                              T_CONTINUE => T_CONTINUE,
  219.                                                              T_THROW    => T_THROW,
  220.                                                              T_EXIT     => T_EXIT,
  221.                                                             ),
  222.                                                 'strict' => true,
  223.                                                 'shared' => true,
  224.                                                 'with'   => array(
  225.                                                              T_DEFAULT => T_DEFAULT,
  226.                                                              T_CASE    => T_CASE,
  227.                                                              T_SWITCH  => T_SWITCH,
  228.                                                             ),
  229.                                                ),
  230.                             T_DEFAULT       => array(
  231.                                                 'start'  => array(
  232.                                                              T_COLON     => T_COLON,
  233.                                                              T_SEMICOLON => T_SEMICOLON,
  234.                                                             ),
  235.                                                 'end'    => array(
  236.                                                              T_BREAK    => T_BREAK,
  237.                                                              T_RETURN   => T_RETURN,
  238.                                                              T_CONTINUE => T_CONTINUE,
  239.                                                              T_THROW    => T_THROW,
  240.                                                              T_EXIT     => T_EXIT,
  241.                                                             ),
  242.                                                 'strict' => true,
  243.                                                 'shared' => true,
  244.                                                 'with'   => array(
  245.                                                              T_CASE   => T_CASE,
  246.                                                              T_SWITCH => T_SWITCH,
  247.                                                             ),
  248.                                                ),
  249.                             T_START_HEREDOC => array(
  250.                                                 'start'  => array(T_START_HEREDOC => T_START_HEREDOC),
  251.                                                 'end'    => array(T_END_HEREDOC => T_END_HEREDOC),
  252.                                                 'strict' => true,
  253.                                                 'shared' => false,
  254.                                                 'with'   => array(),
  255.                                                ),
  256.                            );
  257.  
  258.     /**
  259.      * A list of tokens that end the scope.
  260.      *
  261.      * This array is just a unique collection of the end tokens
  262.      * from the _scopeOpeners array. The data is duplicated here to
  263.      * save time during parsing of the file.
  264.      *
  265.      * @var array 
  266.      */
  267.     public $endScopeTokens = array(
  268.                               T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
  269.                               T_ENDIF               => T_ENDIF,
  270.                               T_ENDFOR              => T_ENDFOR,
  271.                               T_ENDFOREACH          => T_ENDFOREACH,
  272.                               T_ENDWHILE            => T_ENDWHILE,
  273.                               T_ENDSWITCH           => T_ENDSWITCH,
  274.                               T_BREAK               => T_BREAK,
  275.                               T_END_HEREDOC         => T_END_HEREDOC,
  276.                              );
  277.  
  278.     /**
  279.      * Known lengths of tokens.
  280.      *
  281.      * @var array<int, int>
  282.      */
  283.     public $knownLengths = array(
  284.                             T_ABSTRACT                 => 8,
  285.                             T_AND_EQUAL                => 2,
  286.                             T_ARRAY                    => 5,
  287.                             T_AS                       => 2,
  288.                             T_BOOLEAN_AND              => 2,
  289.                             T_BOOLEAN_OR               => 2,
  290.                             T_BREAK                    => 5,
  291.                             T_CALLABLE                 => 8,
  292.                             T_CASE                     => 4,
  293.                             T_CATCH                    => 5,
  294.                             T_CLASS                    => 5,
  295.                             T_CLASS_C                  => 9,
  296.                             T_CLONE                    => 5,
  297.                             T_CONCAT_EQUAL             => 2,
  298.                             T_CONST                    => 5,
  299.                             T_CONTINUE                 => 8,
  300.                             T_CURLY_OPEN               => 2,
  301.                             T_DEC                      => 2,
  302.                             T_DECLARE                  => 7,
  303.                             T_DEFAULT                  => 7,
  304.                             T_DIR                      => 7,
  305.                             T_DIV_EQUAL                => 2,
  306.                             T_DO                       => 2,
  307.                             T_DOLLAR_OPEN_CURLY_BRACES => 2,
  308.                             T_DOUBLE_ARROW             => 2,
  309.                             T_DOUBLE_COLON             => 2,
  310.                             T_ECHO                     => 4,
  311.                             T_ELSE                     => 4,
  312.                             T_ELSEIF                   => 6,
  313.                             T_EMPTY                    => 5,
  314.                             T_ENDDECLARE               => 10,
  315.                             T_ENDFOR                   => 6,
  316.                             T_ENDFOREACH               => 10,
  317.                             T_ENDIF                    => 5,
  318.                             T_ENDSWITCH                => 9,
  319.                             T_ENDWHILE                 => 8,
  320.                             T_EVAL                     => 4,
  321.                             T_EXTENDS                  => 7,
  322.                             T_FILE                     => 8,
  323.                             T_FINAL                    => 5,
  324.                             T_FINALLY                  => 7,
  325.                             T_FOR                      => 3,
  326.                             T_FOREACH                  => 7,
  327.                             T_FUNCTION                 => 8,
  328.                             T_FUNC_C                   => 12,
  329.                             T_GLOBAL                   => 6,
  330.                             T_GOTO                     => 4,
  331.                             T_HALT_COMPILER            => 15,
  332.                             T_IF                       => 2,
  333.                             T_IMPLEMENTS               => 10,
  334.                             T_INC                      => 2,
  335.                             T_INCLUDE                  => 7,
  336.                             T_INCLUDE_ONCE             => 12,
  337.                             T_INSTANCEOF               => 10,
  338.                             T_INSTEADOF                => 9,
  339.                             T_INTERFACE                => 9,
  340.                             T_ISSET                    => 5,
  341.                             T_IS_EQUAL                 => 2,
  342.                             T_IS_GREATER_OR_EQUAL      => 2,
  343.                             T_IS_IDENTICAL             => 3,
  344.                             T_IS_NOT_EQUAL             => 2,
  345.                             T_IS_NOT_IDENTICAL         => 3,
  346.                             T_IS_SMALLER_OR_EQUAL      => 2,
  347.                             T_LINE                     => 8,
  348.                             T_LIST                     => 4,
  349.                             T_LOGICAL_AND              => 3,
  350.                             T_LOGICAL_OR               => 2,
  351.                             T_LOGICAL_XOR              => 3,
  352.                             T_METHOD_C                 => 10,
  353.                             T_MINUS_EQUAL              => 2,
  354.                             T_POW_EQUAL                => 3,
  355.                             T_MOD_EQUAL                => 2,
  356.                             T_MUL_EQUAL                => 2,
  357.                             T_NAMESPACE                => 9,
  358.                             T_NS_C                     => 13,
  359.                             T_NS_SEPARATOR             => 1,
  360.                             T_NEW                      => 3,
  361.                             T_OBJECT_OPERATOR          => 2,
  362.                             T_OPEN_TAG_WITH_ECHO       => 3,
  363.                             T_OR_EQUAL                 => 2,
  364.                             T_PLUS_EQUAL               => 2,
  365.                             T_PRINT                    => 5,
  366.                             T_PRIVATE                  => 7,
  367.                             T_PUBLIC                   => 6,
  368.                             T_PROTECTED                => 9,
  369.                             T_REQUIRE                  => 7,
  370.                             T_REQUIRE_ONCE             => 12,
  371.                             T_RETURN                   => 6,
  372.                             T_STATIC                   => 6,
  373.                             T_SWITCH                   => 6,
  374.                             T_THROW                    => 5,
  375.                             T_TRAIT                    => 5,
  376.                             T_TRAIT_C                  => 9,
  377.                             T_TRY                      => 3,
  378.                             T_UNSET                    => 5,
  379.                             T_USE                      => 3,
  380.                             T_VAR                      => 3,
  381.                             T_WHILE                    => 5,
  382.                             T_XOR_EQUAL                => 2,
  383.                             T_YIELD                    => 5,
  384.                             T_OPEN_CURLY_BRACKET       => 1,
  385.                             T_CLOSE_CURLY_BRACKET      => 1,
  386.                             T_OPEN_SQUARE_BRACKET      => 1,
  387.                             T_CLOSE_SQUARE_BRACKET     => 1,
  388.                             T_OPEN_PARENTHESIS         => 1,
  389.                             T_CLOSE_PARENTHESIS        => 1,
  390.                             T_COLON                    => 1,
  391.                             T_STRING_CONCAT            => 1,
  392.                             T_INLINE_THEN              => 1,
  393.                             T_INLINE_ELSE              => 1,
  394.                             T_NULL                     => 4,
  395.                             T_FALSE                    => 5,
  396.                             T_TRUE                     => 4,
  397.                             T_SEMICOLON                => 1,
  398.                             T_EQUAL                    => 1,
  399.                             T_MULTIPLY                 => 1,
  400.                             T_DIVIDE                   => 1,
  401.                             T_PLUS                     => 1,
  402.                             T_MINUS                    => 1,
  403.                             T_MODULUS                  => 1,
  404.                             T_POW                      => 2,
  405.                             T_SPACESHIP                => 3,
  406.                             T_COALESCE                 => 2,
  407.                             T_BITWISE_AND              => 1,
  408.                             T_BITWISE_OR               => 1,
  409.                             T_BITWISE_XOR              => 1,
  410.                             T_SL                       => 2,
  411.                             T_SR                       => 2,
  412.                             T_SL_EQUAL                 => 3,
  413.                             T_SR_EQUAL                 => 3,
  414.                             T_ARRAY_HINT               => 5,
  415.                             T_GREATER_THAN             => 1,
  416.                             T_LESS_THAN                => 1,
  417.                             T_BOOLEAN_NOT              => 1,
  418.                             T_SELF                     => 4,
  419.                             T_PARENT                   => 6,
  420.                             T_COMMA                    => 1,
  421.                             T_THIS                     => 4,
  422.                             T_CLOSURE                  => 8,
  423.                             T_BACKTICK                 => 1,
  424.                             T_OPEN_SHORT_ARRAY         => 1,
  425.                             T_CLOSE_SHORT_ARRAY        => 1,
  426.                            );
  427.  
  428.  
  429.     /**
  430.      * A cache of different token types, resolved into arrays.
  431.      *
  432.      * @var array 
  433.      * @see standardiseToken()
  434.      */
  435.     private static $resolveTokenCache = array();
  436.  
  437.  
  438.     /**
  439.      * Creates an array of tokens when given some PHP code.
  440.      *
  441.      * Starts by using token_get_all() but does a lot of extra processing
  442.      * to insert information about the context of the token.
  443.      *
  444.      * @param string $string The string to tokenize.
  445.      *
  446.      * @return array 
  447.      */
  448.     protected function tokenize($string)
  449.     {
  450.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  451.             echo "\t*** START PHP TOKENIZING ***".PHP_EOL;
  452.             $isWin = false;
  453.             if (strtoupper(substr(PHP_OS03)) === 'WIN'{
  454.                 $isWin = true;
  455.             }
  456.         }
  457.  
  458.         $tokens      @token_get_all($string);
  459.         $finalTokens = array();
  460.  
  461.         $newStackPtr       = 0;
  462.         $numTokens         count($tokens);
  463.         $lastNotEmptyToken = 0;
  464.  
  465.         $insideInlineIf = array();
  466.         $insideUseGroup = false;
  467.  
  468.         $commentTokenizer = new Comment();
  469.  
  470.         for ($stackPtr = 0; $stackPtr $numTokens$stackPtr++{
  471.             $token        = (array) $tokens[$stackPtr];
  472.             $tokenIsArray = isset($token[1]);
  473.  
  474.             if (PHP_CODESNIFFER_VERBOSITY > 1{
  475.                 if ($tokenIsArray === true{
  476.                     $type    token_name($token[0]);
  477.                     $content = Util\Common::prepareForOutput($token[1]);
  478.                 else {
  479.                     $newToken = self::resolveSimpleToken($token[0]);
  480.                     $type     $newToken['type'];
  481.                     $content  = Util\Common::prepareForOutput($token[0]);
  482.                 }
  483.  
  484.                 echo "\tProcess token ";
  485.                 if ($tokenIsArray === true{
  486.                     echo "[$stackPtr]";
  487.                 else {
  488.                     echo " $stackPtr ";
  489.                 }
  490.  
  491.                 echo "$type => $content";
  492.             }//end if
  493.  
  494.             if ($newStackPtr > 0 && $finalTokens[($newStackPtr - 1)]['code'!== T_WHITESPACE{
  495.                 $lastNotEmptyToken ($newStackPtr - 1);
  496.             }
  497.  
  498.             /*
  499.                 If we are using \r\n newline characters, the \r and \n are sometimes
  500.                 split over two tokens. This normally occurs after comments. We need
  501.                 to merge these two characters together so that our line endings are
  502.                 consistent for all lines.
  503.             */
  504.  
  505.             if ($tokenIsArray === true && substr($token[1]-1=== "\r"{
  506.                 if (isset($tokens[($stackPtr + 1)]=== true
  507.                     && is_array($tokens[($stackPtr + 1)]=== true
  508.                     && $tokens[($stackPtr + 1)][1][0=== "\n"
  509.                 {
  510.                     $token[1.= "\n";
  511.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  512.                         if ($isWin === true{
  513.                             echo '\n';
  514.                         else {
  515.                             echo "\033[30;1m\\n\033[0m";
  516.                         }
  517.                     }
  518.  
  519.                     if ($tokens[($stackPtr + 1)][1=== "\n"{
  520.                         // This token's content has been merged into the previous,
  521.                         // so we can skip it.
  522.                         $tokens[($stackPtr + 1)'';
  523.                     else {
  524.                         $tokens[($stackPtr + 1)][1substr($tokens[($stackPtr + 1)][1]1);
  525.                     }
  526.                 }
  527.             }//end if
  528.  
  529.             if (PHP_CODESNIFFER_VERBOSITY > 1{
  530.                 echo PHP_EOL;
  531.             }
  532.  
  533.             /*
  534.                 Parse doc blocks into something that can be easily iterated over.
  535.             */
  536.  
  537.             if ($tokenIsArray === true && $token[0=== T_DOC_COMMENT{
  538.                 $commentTokens $commentTokenizer->tokenizeString($token[1]$this->eolChar$newStackPtr);
  539.                 foreach ($commentTokens as $commentToken{
  540.                     $finalTokens[$newStackPtr$commentToken;
  541.                     $newStackPtr++;
  542.                 }
  543.  
  544.                 continue;
  545.             }
  546.  
  547.             /*
  548.                 If this is a double quoted string, PHP will tokenize the whole
  549.                 thing which causes problems with the scope map when braces are
  550.                 within the string. So we need to merge the tokens together to
  551.                 provide a single string.
  552.             */
  553.  
  554.             if ($tokenIsArray === false && ($token[0=== '"' || $token[0=== 'b"')) {
  555.                 // Binary casts need a special token.
  556.                 if ($token[0=== 'b"'{
  557.                     $finalTokens[$newStackPtr= array(
  558.                                                   'code'    => T_BINARY_CAST,
  559.                                                   'type'    => 'T_BINARY_CAST',
  560.                                                   'content' => 'b',
  561.                                                  );
  562.                     $newStackPtr++;
  563.                 }
  564.  
  565.                 $tokenContent '"';
  566.                 $nestedVars   = array();
  567.                 for ($i ($stackPtr + 1)$i $numTokens$i++{
  568.                     $subToken        = (array) $tokens[$i];
  569.                     $subTokenIsArray = isset($subToken[1]);
  570.  
  571.                     if ($subTokenIsArray === true{
  572.                         $tokenContent .= $subToken[1];
  573.                         if ($subToken[1=== '{'
  574.                             && $subToken[0!== T_ENCAPSED_AND_WHITESPACE
  575.                         {
  576.                             $nestedVars[$i;
  577.                         }
  578.                     else {
  579.                         $tokenContent .= $subToken[0];
  580.                         if ($subToken[0=== '}'{
  581.                             array_pop($nestedVars);
  582.                         }
  583.                     }
  584.  
  585.                     if ($subTokenIsArray === false
  586.                         && $subToken[0=== '"'
  587.                         && empty($nestedVars=== true
  588.                     {
  589.                         // We found the other end of the double quoted string.
  590.                         break;
  591.                     }
  592.                 }//end for
  593.  
  594.                 $stackPtr $i;
  595.  
  596.                 // Convert each line within the double quoted string to a
  597.                 // new token, so it conforms with other multiple line tokens.
  598.                 $tokenLines explode($this->eolChar$tokenContent);
  599.                 $numLines   count($tokenLines);
  600.                 $newToken   = array();
  601.  
  602.                 for ($j = 0; $j $numLines$j++{
  603.                     $newToken['content'$tokenLines[$j];
  604.                     if ($j === ($numLines - 1)) {
  605.                         if ($tokenLines[$j=== ''{
  606.                             break;
  607.                         }
  608.                     else {
  609.                         $newToken['content'.= $this->eolChar;
  610.                     }
  611.  
  612.                     $newToken['code']          T_DOUBLE_QUOTED_STRING;
  613.                     $newToken['type']          'T_DOUBLE_QUOTED_STRING';
  614.                     $finalTokens[$newStackPtr$newToken;
  615.                     $newStackPtr++;
  616.                 }
  617.  
  618.                 // Continue, as we're done with this token.
  619.                 continue;
  620.             }//end if
  621.  
  622.             /*
  623.                 If this is a heredoc, PHP will tokenize the whole
  624.                 thing which causes problems when heredocs don't
  625.                 contain real PHP code, which is almost never.
  626.                 We want to leave the start and end heredoc tokens
  627.                 alone though.
  628.             */
  629.  
  630.             if ($tokenIsArray === true && $token[0=== T_START_HEREDOC{
  631.                 // Add the start heredoc token to the final array.
  632.                 $finalTokens[$newStackPtr= self::standardiseToken($token);
  633.  
  634.                 // Check if this is actually a nowdoc and use a different token
  635.                 // to help the sniffs.
  636.                 $nowdoc = false;
  637.                 if ($token[1][3=== "'"{
  638.                     $finalTokens[$newStackPtr]['code'T_START_NOWDOC;
  639.                     $finalTokens[$newStackPtr]['type''T_START_NOWDOC';
  640.                     $nowdoc = true;
  641.                 }
  642.  
  643.                 $tokenContent '';
  644.                 for ($i ($stackPtr + 1)$i $numTokens$i++{
  645.                     $subTokenIsArray is_array($tokens[$i]);
  646.                     if ($subTokenIsArray === true
  647.                         && $tokens[$i][0=== T_END_HEREDOC
  648.                     {
  649.                         // We found the other end of the heredoc.
  650.                         break;
  651.                     }
  652.  
  653.                     if ($subTokenIsArray === true{
  654.                         $tokenContent .= $tokens[$i][1];
  655.                     else {
  656.                         $tokenContent .= $tokens[$i];
  657.                     }
  658.                 }
  659.  
  660.                 if ($i === $numTokens{
  661.                     // We got to the end of the file and never
  662.                     // found the closing token, so this probably wasn't
  663.                     // a heredoc.
  664.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  665.                         $type $finalTokens[$newStackPtr]['type'];
  666.                         echo "\t\t* failed to find the end of the here/nowdoc".PHP_EOL;
  667.                         echo "\t\t* token $stackPtr changed from $type to T_STRING".PHP_EOL;
  668.                     }
  669.  
  670.                     $finalTokens[$newStackPtr]['code'= T_STRING;
  671.                     $finalTokens[$newStackPtr]['type''T_STRING';
  672.                     $newStackPtr++;
  673.                     continue;
  674.                 }
  675.  
  676.                 $stackPtr $i;
  677.                 $newStackPtr++;
  678.  
  679.                 // Convert each line within the heredoc to a
  680.                 // new token, so it conforms with other multiple line tokens.
  681.                 $tokenLines explode($this->eolChar$tokenContent);
  682.                 $numLines   count($tokenLines);
  683.                 $newToken   = array();
  684.  
  685.                 for ($j = 0; $j $numLines$j++{
  686.                     $newToken['content'$tokenLines[$j];
  687.                     if ($j === ($numLines - 1)) {
  688.                         if ($tokenLines[$j=== ''{
  689.                             break;
  690.                         }
  691.                     else {
  692.                         $newToken['content'.= $this->eolChar;
  693.                     }
  694.  
  695.                     if ($nowdoc === true{
  696.                         $newToken['code'T_NOWDOC;
  697.                         $newToken['type''T_NOWDOC';
  698.                     else {
  699.                         $newToken['code'T_HEREDOC;
  700.                         $newToken['type''T_HEREDOC';
  701.                     }
  702.  
  703.                     $finalTokens[$newStackPtr$newToken;
  704.                     $newStackPtr++;
  705.                 }//end for
  706.  
  707.                 // Add the end heredoc token to the final array.
  708.                 $finalTokens[$newStackPtr= self::standardiseToken($tokens[$stackPtr]);
  709.  
  710.                 if ($nowdoc === true{
  711.                     $finalTokens[$newStackPtr]['code'T_END_NOWDOC;
  712.                     $finalTokens[$newStackPtr]['type''T_END_NOWDOC';
  713.                     $nowdoc = true;
  714.                 }
  715.  
  716.                 $newStackPtr++;
  717.  
  718.                 // Continue, as we're done with this token.
  719.                 continue;
  720.             }//end if
  721.  
  722.             /*
  723.                 Before PHP 5.6, the ... operator was tokenized as three
  724.                 T_STRING_CONCAT tokens in a row. So look for and combine
  725.                 these tokens in earlier versions.
  726.             */
  727.  
  728.             if ($tokenIsArray === false
  729.                 && $token[0=== '.'
  730.                 && isset($tokens[($stackPtr + 1)]=== true
  731.                 && isset($tokens[($stackPtr + 2)]=== true
  732.                 && $tokens[($stackPtr + 1)=== '.'
  733.                 && $tokens[($stackPtr + 2)=== '.'
  734.             {
  735.                 $newToken            = array();
  736.                 $newToken['code']    T_ELLIPSIS;
  737.                 $newToken['type']    'T_ELLIPSIS';
  738.                 $newToken['content''...';
  739.                 $finalTokens[$newStackPtr$newToken;
  740.  
  741.                 $newStackPtr++;
  742.                 $stackPtr += 2;
  743.                 continue;
  744.             }
  745.  
  746.             /*
  747.                 Before PHP 5.6, the ** operator was tokenized as two
  748.                 T_MULTIPLY tokens in a row. So look for and combine
  749.                 these tokens in earlier versions.
  750.             */
  751.  
  752.             if ($tokenIsArray === false
  753.                 && $token[0=== '*'
  754.                 && isset($tokens[($stackPtr + 1)]=== true
  755.                 && $tokens[($stackPtr + 1)=== '*'
  756.             {
  757.                 $newToken            = array();
  758.                 $newToken['code']    T_POW;
  759.                 $newToken['type']    'T_POW';
  760.                 $newToken['content''**';
  761.                 $finalTokens[$newStackPtr$newToken;
  762.  
  763.                 $newStackPtr++;
  764.                 $stackPtr++;
  765.                 continue;
  766.             }
  767.  
  768.             /*
  769.                 Before PHP 5.6, the **= operator was tokenized as
  770.                 T_MULTIPLY followed by T_MUL_EQUAL. So look for and combine
  771.                 these tokens in earlier versions.
  772.             */
  773.  
  774.             if ($tokenIsArray === false
  775.                 && $token[0=== '*'
  776.                 && isset($tokens[($stackPtr + 1)]=== true
  777.                 && is_array($tokens[($stackPtr + 1)]=== true
  778.                 && $tokens[($stackPtr + 1)][1=== '*='
  779.             {
  780.                 $newToken            = array();
  781.                 $newToken['code']    T_POW_EQUAL;
  782.                 $newToken['type']    'T_POW_EQUAL';
  783.                 $newToken['content''**=';
  784.                 $finalTokens[$newStackPtr$newToken;
  785.  
  786.                 $newStackPtr++;
  787.                 $stackPtr++;
  788.                 continue;
  789.             }
  790.  
  791.             /*
  792.                 Before PHP 7, the ?? operator was tokenized as
  793.                 T_INLINE_THEN followed by T_INLINE_THEN.
  794.                 So look for and combine these tokens in earlier versions.
  795.             */
  796.  
  797.             if ($tokenIsArray === false
  798.                 && $token[0=== '?'
  799.                 && isset($tokens[($stackPtr + 1)]=== true
  800.                 && $tokens[($stackPtr + 1)][0=== '?'
  801.             {
  802.                 $newToken            = array();
  803.                 $newToken['code']    T_COALESCE;
  804.                 $newToken['type']    'T_COALESCE';
  805.                 $newToken['content''??';
  806.                 $finalTokens[$newStackPtr$newToken;
  807.  
  808.                 $newStackPtr++;
  809.                 $stackPtr++;
  810.                 continue;
  811.             }
  812.  
  813.             /*
  814.                 Before PHP 7, the <=> operator was tokenized as
  815.                 T_IS_SMALLER_OR_EQUAL followed by T_GREATER_THAN.
  816.                 So look for and combine these tokens in earlier versions.
  817.             */
  818.  
  819.             if ($tokenIsArray === true
  820.                 && $token[0=== T_IS_SMALLER_OR_EQUAL
  821.                 && isset($tokens[($stackPtr + 1)]=== true
  822.                 && $tokens[($stackPtr + 1)][0=== '>'
  823.             {
  824.                 $newToken            = array();
  825.                 $newToken['code']    T_SPACESHIP;
  826.                 $newToken['type']    'T_SPACESHIP';
  827.                 $newToken['content''<=>';
  828.                 $finalTokens[$newStackPtr$newToken;
  829.  
  830.                 $newStackPtr++;
  831.                 $stackPtr++;
  832.                 continue;
  833.             }
  834.  
  835.             /*
  836.                 Emulate traits in PHP versions less than 5.4.
  837.             */
  838.  
  839.             if ($tokenIsArray === true
  840.                 && $token[0=== T_STRING
  841.                 && strtolower($token[1]=== 'trait'
  842.                 && $tokens[($stackPtr - 1)][0!== T_OBJECT_OPERATOR
  843.             {
  844.                 $finalTokens[$newStackPtr= array(
  845.                                               'content' => $token[1],
  846.                                               'code'    => T_TRAIT,
  847.                                               'type'    => 'T_TRAIT',
  848.                                              );
  849.  
  850.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  851.                     echo "\t\t* token $stackPtr changed from T_STRING to T_TRAIT".PHP_EOL;
  852.                 }
  853.  
  854.                 $newStackPtr++;
  855.                 continue;
  856.             }
  857.  
  858.             /*
  859.                 PHP doesn't assign a token to goto labels, so we have to.
  860.                 These are just string tokens with a single colon after them. Double
  861.                 colons are already tokenized and so don't interfere with this check.
  862.                 But we do have to account for CASE statements, that look just like
  863.                 goto labels.
  864.             */
  865.  
  866.             if ($tokenIsArray === true
  867.                 && $token[0=== T_STRING
  868.                 && isset($tokens[($stackPtr + 1)]=== true
  869.                 && $tokens[($stackPtr + 1)=== ':'
  870.                 && $tokens[($stackPtr - 1)][0!== T_PAAMAYIM_NEKUDOTAYIM
  871.             {
  872.                 $stopTokens = array(
  873.                                T_CASE               => true,
  874.                                T_SEMICOLON          => true,
  875.                                T_OPEN_CURLY_BRACKET => true,
  876.                                T_INLINE_THEN        => true,
  877.                               );
  878.  
  879.                 for ($x ($newStackPtr - 1)$x > 0; $x--{
  880.                     if (isset($stopTokens[$finalTokens[$x]['code']]=== true{
  881.                         break;
  882.                     }
  883.                 }
  884.  
  885.                 if ($finalTokens[$x]['code'!== T_CASE
  886.                     && $finalTokens[$x]['code'!== T_INLINE_THEN
  887.                 {
  888.                     $finalTokens[$newStackPtr= array(
  889.                                                   'content' => $token[1].':',
  890.                                                   'code'    => T_GOTO_LABEL,
  891.                                                   'type'    => 'T_GOTO_LABEL',
  892.                                                  );
  893.  
  894.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  895.                         echo "\t\t* token $stackPtr changed from T_STRING to T_GOTO_LABEL".PHP_EOL;
  896.                         echo "\t\t* skipping T_COLON token ".($stackPtr + 1).PHP_EOL;
  897.                     }
  898.  
  899.                     $newStackPtr++;
  900.                     $stackPtr++;
  901.                     continue;
  902.                 }
  903.             }//end if
  904.  
  905.             /*
  906.                 HHVM 3.5 tokenizes "else[\s]+if" as a T_ELSEIF token while PHP
  907.                 proper only tokenizes "elseif" as a T_ELSEIF token. So split
  908.                 up the HHVM token to make it looks like proper PHP.
  909.             */
  910.  
  911.             if ($tokenIsArray === true
  912.                 && $token[0=== T_ELSEIF
  913.                 && strtolower($token[1]!== 'elseif'
  914.             {
  915.                 $finalTokens[$newStackPtr= array(
  916.                                               'content' => substr($token[1]04),
  917.                                               'code'    => T_ELSE,
  918.                                               'type'    => 'T_ELSE',
  919.                                              );
  920.  
  921.                 $newStackPtr++;
  922.                 $finalTokens[$newStackPtr= array(
  923.                                               'content' => substr($token[1]4-2),
  924.                                               'code'    => T_WHITESPACE,
  925.                                               'type'    => 'T_WHITESPACE',
  926.                                              );
  927.  
  928.                 $newStackPtr++;
  929.                 $finalTokens[$newStackPtr= array(
  930.                                               'content' => substr($token[1]-2),
  931.                                               'code'    => T_IF,
  932.                                               'type'    => 'T_IF',
  933.                                              );
  934.  
  935.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  936.                     echo "\t\t* token $stackPtr changed from T_ELSEIF to T_ELSE/T_WHITESPACE/T_IF".PHP_EOL;
  937.                 }
  938.  
  939.                 $newStackPtr++;
  940.                 continue;
  941.             }//end if
  942.  
  943.             /*
  944.                 HHVM 3.5 and 3.6 tokenizes a hashbang line such as #!/usr/bin/php
  945.                 as T_HASHBANG while PHP proper uses T_INLINE_HTML.
  946.             */
  947.  
  948.             if ($tokenIsArray === true && token_name($token[0]=== 'T_HASHBANG'{
  949.                 $finalTokens[$newStackPtr= array(
  950.                                               'content' => $token[1],
  951.                                               'code'    => T_INLINE_HTML,
  952.                                               'type'    => 'T_INLINE_HTML',
  953.                                              );
  954.  
  955.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  956.                     echo "\t\t* token $stackPtr changed from T_HASHBANG to T_INLINE_HTML".PHP_EOL;
  957.                 }
  958.  
  959.                 $newStackPtr++;
  960.                 continue;
  961.             }//end if
  962.  
  963.             /*
  964.                 If this token has newlines in its content, split each line up
  965.                 and create a new token for each line. We do this so it's easier
  966.                 to ascertain where errors occur on a line.
  967.                 Note that $token[1] is the token's content.
  968.             */
  969.  
  970.             if ($tokenIsArray === true && strpos($token[1]$this->eolChar!== false{
  971.                 $tokenLines explode($this->eolChar$token[1]);
  972.                 $numLines   count($tokenLines);
  973.                 $newToken   = array(
  974.                                'type'    => token_name($token[0]),
  975.                                'code'    => $token[0],
  976.                                'content' => '',
  977.                               );
  978.  
  979.                 for ($i = 0; $i $numLines$i++{
  980.                     $newToken['content'$tokenLines[$i];
  981.                     if ($i === ($numLines - 1)) {
  982.                         if ($tokenLines[$i=== ''{
  983.                             break;
  984.                         }
  985.                     else {
  986.                         $newToken['content'.= $this->eolChar;
  987.                     }
  988.  
  989.                     $finalTokens[$newStackPtr$newToken;
  990.                     $newStackPtr++;
  991.                 }
  992.             else {
  993.                 if ($tokenIsArray === true && $token[0=== T_STRING{
  994.                     // Some T_STRING tokens should remain that way
  995.                     // due to their context.
  996.                     $context = array(
  997.                                 T_OBJECT_OPERATOR      => true,
  998.                                 T_FUNCTION             => true,
  999.                                 T_CLASS                => true,
  1000.                                 T_EXTENDS              => true,
  1001.                                 T_IMPLEMENTS           => true,
  1002.                                 T_NEW                  => true,
  1003.                                 T_CONST                => true,
  1004.                                 T_NS_SEPARATOR         => true,
  1005.                                 T_USE                  => true,
  1006.                                 T_NAMESPACE            => true,
  1007.                                 T_PAAMAYIM_NEKUDOTAYIM => true,
  1008.                                );
  1009.                     if (isset($context[$finalTokens[$lastNotEmptyToken]['code']]=== true{
  1010.                         $finalTokens[$newStackPtr= array(
  1011.                                                       'content' => $token[1],
  1012.                                                       'code'    => T_STRING,
  1013.                                                       'type'    => 'T_STRING',
  1014.                                                      );
  1015.                         $newStackPtr++;
  1016.                         continue;
  1017.                     }
  1018.                 }//end if
  1019.  
  1020.                 $newToken = null;
  1021.                 if ($tokenIsArray === false{
  1022.                     if (isset(self::$resolveTokenCache[$token[0]]=== true{
  1023.                         $newToken = self::$resolveTokenCache[$token[0]];
  1024.                     }
  1025.                 else {
  1026.                     $cacheKey = null;
  1027.                     if ($token[0=== T_STRING{
  1028.                         $cacheKey strtolower($token[1]);
  1029.                     else if ($token[0!== T_CURLY_OPEN{
  1030.                         $cacheKey $token[0];
  1031.                     }
  1032.  
  1033.                     if ($cacheKey !== null && isset(self::$resolveTokenCache[$cacheKey]=== true{
  1034.                         $newToken            = self::$resolveTokenCache[$cacheKey];
  1035.                         $newToken['content'$token[1];
  1036.                     }
  1037.                 }
  1038.  
  1039.                 if ($newToken === null{
  1040.                     $newToken = self::standardiseToken($token);
  1041.                 }
  1042.  
  1043.                 // Convert colons that are actually the ELSE component of an
  1044.                 // inline IF statement.
  1045.                 if ($newToken['code'=== T_INLINE_THEN{
  1046.                     $insideInlineIf[$stackPtr;
  1047.                 else if (empty($insideInlineIf=== false && $newToken['code'=== T_COLON{
  1048.                     array_pop($insideInlineIf);
  1049.                     $newToken['code'T_INLINE_ELSE;
  1050.                     $newToken['type''T_INLINE_ELSE';
  1051.                 }
  1052.  
  1053.                 // This is a special condition for T_ARRAY tokens used for
  1054.                 // type hinting function arguments as being arrays. We want to keep
  1055.                 // the parenthesis map clean, so let's tag these tokens as
  1056.                 // T_ARRAY_HINT.
  1057.                 if ($newToken['code'=== T_ARRAY{
  1058.                     for ($i $stackPtr$i $numTokens$i++{
  1059.                         if ($tokens[$i=== '('{
  1060.                             break;
  1061.                         else if ($tokens[$i][0=== T_VARIABLE{
  1062.                             $newToken['code'T_ARRAY_HINT;
  1063.                             $newToken['type''T_ARRAY_HINT';
  1064.                             break;
  1065.                         }
  1066.                     }
  1067.                 }
  1068.  
  1069.                 // This is a special case when checking PHP 5.5+ code in PHP < 5.5
  1070.                 // where "finally" should be T_FINALLY instead of T_STRING.
  1071.                 if ($newToken['code'=== T_STRING
  1072.                     && strtolower($newToken['content']=== 'finally'
  1073.                 {
  1074.                     $newToken['code'T_FINALLY;
  1075.                     $newToken['type''T_FINALLY';
  1076.                 }
  1077.  
  1078.                 // This is a special case for the PHP 5.5 classname::class syntax
  1079.                 // where "class" should be T_STRING instead of T_CLASS.
  1080.                 if ($newToken['code'=== T_CLASS
  1081.                     && $finalTokens[($newStackPtr - 1)]['code'=== T_DOUBLE_COLON
  1082.                 {
  1083.                     $newToken['code'= T_STRING;
  1084.                     $newToken['type''T_STRING';
  1085.                 }
  1086.  
  1087.                 // This is a special case for PHP 5.6 use function and use const
  1088.                 // where "function" and "const" should be T_STRING instead of T_FUNCTION
  1089.                 // and T_CONST.
  1090.                 if (($newToken['code'=== T_FUNCTION
  1091.                     || $newToken['code'=== T_CONST)
  1092.                     && $finalTokens[$lastNotEmptyToken]['code'=== T_USE
  1093.                 {
  1094.                     $newToken['code'= T_STRING;
  1095.                     $newToken['type''T_STRING';
  1096.                 }
  1097.  
  1098.                 // This is a special case for use groups in PHP 7+ where leaving
  1099.                 // the curly braces as their normal tokens would confuse
  1100.                 // the scope map and sniffs.
  1101.                 if ($newToken['code'=== T_OPEN_CURLY_BRACKET
  1102.                     && $finalTokens[$lastNotEmptyToken]['code'=== T_NS_SEPARATOR
  1103.                 {
  1104.                     $newToken['code'T_OPEN_USE_GROUP;
  1105.                     $newToken['type''T_OPEN_USE_GROUP';
  1106.                     $insideUseGroup   = true;
  1107.                 }
  1108.  
  1109.                 if ($insideUseGroup === true && $newToken['code'=== T_CLOSE_CURLY_BRACKET{
  1110.                     $newToken['code'T_CLOSE_USE_GROUP;
  1111.                     $newToken['type''T_CLOSE_USE_GROUP';
  1112.                     $insideUseGroup   = false;
  1113.                 }
  1114.  
  1115.                 $finalTokens[$newStackPtr$newToken;
  1116.                 $newStackPtr++;
  1117.             }//end if
  1118.         }//end for
  1119.  
  1120.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1121.             echo "\t*** END PHP TOKENIZING ***".PHP_EOL;
  1122.         }
  1123.  
  1124.         return $finalTokens;
  1125.  
  1126.     }//end tokenize()
  1127.  
  1128.  
  1129.     /**
  1130.      * Performs additional processing after main tokenizing.
  1131.      *
  1132.      * This additional processing checks for CASE statements that are using curly
  1133.      * braces for scope openers and closers. It also turns some T_FUNCTION tokens
  1134.      * into T_CLOSURE when they are not standard function definitions. It also
  1135.      * detects short array syntax and converts those square brackets into new tokens.
  1136.      * It also corrects some usage of the static and class keywords. It also
  1137.      * assigns tokens to function return types.
  1138.      *
  1139.      * @return void 
  1140.      */
  1141.     protected function processAdditional()
  1142.     {
  1143.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1144.             echo "\t*** START ADDITIONAL PHP PROCESSING ***".PHP_EOL;
  1145.         }
  1146.  
  1147.         $numTokens count($this->tokens);
  1148.         for ($i ($numTokens - 1)$i >= 0; $i--{
  1149.             // Check for any unset scope conditions due to alternate IF/ENDIF syntax.
  1150.             if (isset($this->tokens[$i]['scope_opener']=== true
  1151.                 && isset($this->tokens[$i]['scope_condition']=== false
  1152.             {
  1153.                 $this->tokens[$i]['scope_condition'$this->tokens[$this->tokens[$i]['scope_opener']]['scope_condition'];
  1154.             }
  1155.  
  1156.             if ($this->tokens[$i]['code'=== T_FUNCTION{
  1157.                 // Context sensitive keywords support.
  1158.                 for ($x ($i + 1)$x $numTokens$x++{
  1159.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1160.                         // Non-whitespace content.
  1161.                         break;
  1162.                     }
  1163.                 }
  1164.  
  1165.                 if ($x === $numTokens{
  1166.                     // We got to the end without finding any more
  1167.                     // non-whitespace content.
  1168.                     continue;
  1169.                 }
  1170.  
  1171.                 if (in_array($this->tokens[$x]['code']array(T_STRINGT_OPEN_PARENTHESIST_BITWISE_AND)true=== false{
  1172.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1173.                         $line $this->tokens[$x]['line'];
  1174.                         $type $this->tokens[$x]['type'];
  1175.                         echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL;
  1176.                     }
  1177.  
  1178.                     $this->tokens[$x]['code'= T_STRING;
  1179.                     $this->tokens[$x]['type''T_STRING';
  1180.                 }
  1181.  
  1182.                 /*
  1183.                     Detect functions that are actually closures and
  1184.                     assign them a different token.
  1185.                 */
  1186.  
  1187.                 if (isset($this->tokens[$i]['scope_opener']=== true{
  1188.                     for ($x ($i + 1)$x $numTokens$x++{
  1189.                         if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false
  1190.                             && $this->tokens[$x]['code'!== T_BITWISE_AND
  1191.                         {
  1192.                             break;
  1193.                         }
  1194.                     }
  1195.  
  1196.                     if ($this->tokens[$x]['code'=== T_OPEN_PARENTHESIS{
  1197.                         $this->tokens[$i]['code'T_CLOSURE;
  1198.                         $this->tokens[$i]['type''T_CLOSURE';
  1199.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1200.                             $line $this->tokens[$i]['line'];
  1201.                             echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE".PHP_EOL;
  1202.                         }
  1203.  
  1204.                         for ($x ($this->tokens[$i]['scope_opener'+ 1)$x $this->tokens[$i]['scope_closer']$x++{
  1205.                             if (isset($this->tokens[$x]['conditions'][$i]=== false{
  1206.                                 continue;
  1207.                             }
  1208.  
  1209.                             $this->tokens[$x]['conditions'][$iT_CLOSURE;
  1210.                             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1211.                                 $type $this->tokens[$x]['type'];
  1212.                                 echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1213.                             }
  1214.                         }
  1215.                     }
  1216.  
  1217.                     $tokenAfterReturnTypeHint $this->tokens[$i]['scope_opener'];
  1218.                 else if (isset($this->tokens[$i]['parenthesis_closer']=== true{
  1219.                     $tokenAfterReturnTypeHint = null;
  1220.                     for ($x ($this->tokens[$i]['parenthesis_closer'+ 1)$x $numTokens$x++{
  1221.                         if ($this->tokens[$x]['code'=== T_SEMICOLON{
  1222.                             $tokenAfterReturnTypeHint $x;
  1223.                             break;
  1224.                         }
  1225.                     }
  1226.  
  1227.                     if ($tokenAfterReturnTypeHint === null{
  1228.                         // Probably a syntax error.
  1229.                         continue;
  1230.                     }
  1231.                 else {
  1232.                     // Probably a syntax error.
  1233.                     continue;
  1234.                 }//end if
  1235.  
  1236.                 /*
  1237.                     Detect function return values and assign them
  1238.                     a special token, because PHP doesn't.
  1239.                 */
  1240.  
  1241.                 for ($x ($tokenAfterReturnTypeHint - 1)$x $i$x--{
  1242.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1243.                         if (in_array($this->tokens[$x]['code']array(T_STRINGT_ARRAYT_CALLABLET_SELFT_PARENT)true=== true{
  1244.                             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1245.                                 $line $this->tokens[$x]['line'];
  1246.                                 $type $this->tokens[$x]['type'];
  1247.                                 echo "\t* token $x on line $line changed from $type to T_RETURN_TYPE".PHP_EOL;
  1248.                             }
  1249.  
  1250.                             $this->tokens[$x]['code'T_RETURN_TYPE;
  1251.                             $this->tokens[$x]['type''T_RETURN_TYPE';
  1252.                         }
  1253.  
  1254.                         break;
  1255.                     }
  1256.                 }
  1257.  
  1258.                 continue;
  1259.             else if ($this->tokens[$i]['code'=== T_CLASS && isset($this->tokens[$i]['scope_opener']=== true{
  1260.                 /*
  1261.                     Detect anonymous classes and assign them a different token.
  1262.                 */
  1263.  
  1264.                 for ($x ($i + 1)$x $numTokens$x++{
  1265.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1266.                         break;
  1267.                     }
  1268.                 }
  1269.  
  1270.                 if ($this->tokens[$x]['code'=== T_OPEN_PARENTHESIS
  1271.                     || $this->tokens[$x]['code'=== T_OPEN_CURLY_BRACKET
  1272.                     || $this->tokens[$x]['code'=== T_EXTENDS
  1273.                     || $this->tokens[$x]['code'=== T_IMPLEMENTS
  1274.                 {
  1275.                     $this->tokens[$i]['code'T_ANON_CLASS;
  1276.                     $this->tokens[$i]['type''T_ANON_CLASS';
  1277.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1278.                         $line $this->tokens[$i]['line'];
  1279.                         echo "\t* token $i on line $line changed from T_CLASS to T_ANON_CLASS".PHP_EOL;
  1280.                     }
  1281.  
  1282.                     for ($x ($this->tokens[$i]['scope_opener'+ 1)$x $this->tokens[$i]['scope_closer']$x++{
  1283.                         if (isset($this->tokens[$x]['conditions'][$i]=== false{
  1284.                             continue;
  1285.                         }
  1286.  
  1287.                         $this->tokens[$x]['conditions'][$iT_ANON_CLASS;
  1288.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1289.                             $type $this->tokens[$x]['type'];
  1290.                             echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1291.                         }
  1292.                     }
  1293.                 }
  1294.  
  1295.                 continue;
  1296.             else if ($this->tokens[$i]['code'=== T_OPEN_SQUARE_BRACKET{
  1297.                 // Unless there is a variable or a bracket before this token,
  1298.                 // it is the start of an array being defined using the short syntax.
  1299.                 for ($x ($i - 1)$x > 0; $x--{
  1300.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1301.                         break;
  1302.                     }
  1303.                 }
  1304.  
  1305.                 $allowed = array(
  1306.                             T_CLOSE_CURLY_BRACKET  => T_CLOSE_CURLY_BRACKET,
  1307.                             T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET,
  1308.                             T_CLOSE_PARENTHESIS    => T_CLOSE_PARENTHESIS,
  1309.                             T_VARIABLE             => T_VARIABLE,
  1310.                             T_STRING               => T_STRING,
  1311.                            );
  1312.  
  1313.                 if (isset($allowed[$this->tokens[$x]['code']]=== false
  1314.                     && isset($this->tokens[$i]['bracket_closer']=== true
  1315.                 {
  1316.                     $this->tokens[$i]['code'T_OPEN_SHORT_ARRAY;
  1317.                     $this->tokens[$i]['type''T_OPEN_SHORT_ARRAY';
  1318.  
  1319.                     $closer $this->tokens[$i]['bracket_closer'];
  1320.                     $this->tokens[$closer]['code'T_CLOSE_SHORT_ARRAY;
  1321.                     $this->tokens[$closer]['type''T_CLOSE_SHORT_ARRAY';
  1322.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1323.                         $line $this->tokens[$i]['line'];
  1324.                         echo "\t* token $i on line $line changed from T_OPEN_SQUARE_BRACKET to T_OPEN_SHORT_ARRAY".PHP_EOL;
  1325.                         $line $this->tokens[$closer]['line'];
  1326.                         echo "\t* token $closer on line $line changed from T_CLOSE_SQUARE_BRACKET to T_CLOSE_SHORT_ARRAY".PHP_EOL;
  1327.                     }
  1328.                 }
  1329.  
  1330.                 continue;
  1331.             else if ($this->tokens[$i]['code'=== T_STATIC{
  1332.                 for ($x ($i - 1)$x > 0; $x--{
  1333.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1334.                         break;
  1335.                     }
  1336.                 }
  1337.  
  1338.                 if ($this->tokens[$x]['code'=== T_INSTANCEOF{
  1339.                     $this->tokens[$i]['code'= T_STRING;
  1340.                     $this->tokens[$i]['type''T_STRING';
  1341.  
  1342.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1343.                         $line $this->tokens[$i]['line'];
  1344.                         echo "\t* token $i on line $line changed from T_STATIC to T_STRING".PHP_EOL;
  1345.                     }
  1346.                 }
  1347.  
  1348.                 continue;
  1349.             else if ($this->tokens[$i]['code'=== T_ECHO && $this->tokens[$i]['content'=== '<?='{
  1350.                 // HHVM tokenizes <?= as T_ECHO but it should be T_OPEN_TAG_WITH_ECHO.
  1351.                 $this->tokens[$i]['code'= T_OPEN_TAG_WITH_ECHO;
  1352.                 $this->tokens[$i]['type''T_OPEN_TAG_WITH_ECHO';
  1353.  
  1354.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1355.                     $line $this->tokens[$i]['line'];
  1356.                     echo "\t* token $i on line $line changed from T_ECHO to T_OPEN_TAG_WITH_ECHO".PHP_EOL;
  1357.                 }
  1358.             else if ($this->tokens[$i]['code'=== T_TRUE
  1359.                 || $this->tokens[$i]['code'=== T_FALSE
  1360.                 || $this->tokens[$i]['code'=== T_NULL
  1361.             {
  1362.                 for ($x ($i + 1)$i $numTokens$x++{
  1363.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1364.                         // Non-whitespace content.
  1365.                         break;
  1366.                     }
  1367.                 }
  1368.  
  1369.                 $context = array(
  1370.                             T_OBJECT_OPERATOR      => true,
  1371.                             T_NS_SEPARATOR         => true,
  1372.                             T_PAAMAYIM_NEKUDOTAYIM => true,
  1373.                            );
  1374.                 if (isset($context[$this->tokens[$x]['code']]=== true{
  1375.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1376.                         $line $this->tokens[$i]['line'];
  1377.                         $type $this->tokens[$i]['type'];
  1378.                         echo "\t* token $i on line $line changed from $type to T_STRING".PHP_EOL;
  1379.                     }
  1380.  
  1381.                     $this->tokens[$i]['code'= T_STRING;
  1382.                     $this->tokens[$i]['type''T_STRING';
  1383.                 }
  1384.             else if ($this->tokens[$i]['code'=== T_CONST{
  1385.                 // Context sensitive keywords support.
  1386.                 for ($x ($i + 1)$i $numTokens$x++{
  1387.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1388.                         // Non-whitespace content.
  1389.                         break;
  1390.                     }
  1391.                 }
  1392.  
  1393.                 if ($this->tokens[$x]['code'!== T_STRING{
  1394.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1395.                         $line $this->tokens[$x]['line'];
  1396.                         $type $this->tokens[$x]['type'];
  1397.                         echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL;
  1398.                     }
  1399.  
  1400.                     $this->tokens[$x]['code'= T_STRING;
  1401.                     $this->tokens[$x]['type''T_STRING';
  1402.                 }
  1403.             else if ($this->tokens[$i]['code'=== T_PAAMAYIM_NEKUDOTAYIM{
  1404.                 // Context sensitive keywords support.
  1405.                 for ($x ($i + 1)$i $numTokens$x++{
  1406.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1407.                         // Non-whitespace content.
  1408.                         break;
  1409.                     }
  1410.                 }
  1411.  
  1412.                 if (in_array($this->tokens[$x]['code']array(T_STRINGT_VARIABLET_DOLLAR)true=== false{
  1413.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1414.                         $line $this->tokens[$x]['line'];
  1415.                         $type $this->tokens[$x]['type'];
  1416.                         echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL;
  1417.                     }
  1418.  
  1419.                     $this->tokens[$x]['code'= T_STRING;
  1420.                     $this->tokens[$x]['type''T_STRING';
  1421.                 }
  1422.             }//end if
  1423.  
  1424.             if (($this->tokens[$i]['code'!== T_CASE
  1425.                 && $this->tokens[$i]['code'!== T_DEFAULT)
  1426.                 || isset($this->tokens[$i]['scope_opener']=== false
  1427.             {
  1428.                 // Only interested in CASE and DEFAULT statements from here on in.
  1429.                 continue;
  1430.             }
  1431.  
  1432.             $scopeOpener $this->tokens[$i]['scope_opener'];
  1433.             $scopeCloser $this->tokens[$i]['scope_closer'];
  1434.  
  1435.             // If the first char after the opener is a curly brace
  1436.             // and that brace has been ignored, it is actually
  1437.             // opening this case statement and the opener and closer are
  1438.             // probably set incorrectly.
  1439.             for ($x ($scopeOpener + 1)$x $numTokens$x++{
  1440.                 if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1441.                     // Non-whitespace content.
  1442.                     break;
  1443.                 }
  1444.             }
  1445.  
  1446.             if ($this->tokens[$x]['code'=== T_CASE || $this->tokens[$x]['code'=== T_DEFAULT{
  1447.                 // Special case for multiple CASE statements that share the same
  1448.                 // closer. Because we are going backwards through the file, this next
  1449.                 // CASE statement is already fixed, so just use its closer and don't
  1450.                 // worry about fixing anything.
  1451.                 $newCloser $this->tokens[$x]['scope_closer'];
  1452.                 $this->tokens[$i]['scope_closer'$newCloser;
  1453.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1454.                     $oldType $this->tokens[$scopeCloser]['type'];
  1455.                     $newType $this->tokens[$newCloser]['type'];
  1456.                     $line    $this->tokens[$i]['line'];
  1457.                     echo "\t* token $i (T_CASE) on line $line closer changed from $scopeCloser ($oldType) to $newCloser ($newType)".PHP_EOL;
  1458.                 }
  1459.  
  1460.                 continue;
  1461.             }
  1462.  
  1463.             if ($this->tokens[$x]['code'!== T_OPEN_CURLY_BRACKET
  1464.                 || isset($this->tokens[$x]['scope_condition']=== true
  1465.             {
  1466.                 // Not a CASE/DEFAULT with a curly brace opener.
  1467.                 continue;
  1468.             }
  1469.  
  1470.             // The closer for this CASE/DEFAULT should be the closing curly brace and
  1471.             // not whatever it already is. The opener needs to be the opening curly
  1472.             // brace so everything matches up.
  1473.             $newCloser $this->tokens[$x]['bracket_closer'];
  1474.             foreach (array($i$x$newCloseras $index{
  1475.                 $this->tokens[$index]['scope_condition'$i;
  1476.                 $this->tokens[$index]['scope_opener']    $x;
  1477.                 $this->tokens[$index]['scope_closer']    $newCloser;
  1478.             }
  1479.  
  1480.             unset($this->tokens[$scopeOpener]['scope_condition']);
  1481.             unset($this->tokens[$scopeOpener]['scope_opener']);
  1482.             unset($this->tokens[$scopeOpener]['scope_closer']);
  1483.             unset($this->tokens[$scopeCloser]['scope_condition']);
  1484.             unset($this->tokens[$scopeCloser]['scope_opener']);
  1485.             unset($this->tokens[$scopeCloser]['scope_closer']);
  1486.             unset($this->tokens[$x]['bracket_opener']);
  1487.             unset($this->tokens[$x]['bracket_closer']);
  1488.             unset($this->tokens[$newCloser]['bracket_opener']);
  1489.             unset($this->tokens[$newCloser]['bracket_closer']);
  1490.             $this->tokens[$scopeCloser]['conditions'][$i;
  1491.  
  1492.             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1493.                 $line      $this->tokens[$i]['line'];
  1494.                 $tokenType $this->tokens[$i]['type'];
  1495.  
  1496.                 $oldType $this->tokens[$scopeOpener]['type'];
  1497.                 $newType $this->tokens[$x]['type'];
  1498.                 echo "\t* token $i ($tokenType) on line $line opener changed from $scopeOpener ($oldType) to $x ($newType)".PHP_EOL;
  1499.  
  1500.                 $oldType $this->tokens[$scopeCloser]['type'];
  1501.                 $newType $this->tokens[$newCloser]['type'];
  1502.                 echo "\t* token $i ($tokenType) on line $line closer changed from $scopeCloser ($oldType) to $newCloser ($newType)".PHP_EOL;
  1503.             }
  1504.  
  1505.             // Now fix up all the tokens that think they are
  1506.             // inside the CASE/DEFAULT statement when they are really outside.
  1507.             for ($x $newCloser$x $scopeCloser$x++{
  1508.                 foreach ($this->tokens[$x]['conditions'as $num => $oldCond{
  1509.                     if ($oldCond === $this->tokens[$i]['code']{
  1510.                         $oldConditions $this->tokens[$x]['conditions'];
  1511.                         unset($this->tokens[$x]['conditions'][$num]);
  1512.  
  1513.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1514.                             $type     $this->tokens[$x]['type'];
  1515.                             $oldConds '';
  1516.                             foreach ($oldConditions as $condition{
  1517.                                 $oldConds .= token_name($condition).',';
  1518.                             }
  1519.  
  1520.                             $oldConds rtrim($oldConds',');
  1521.  
  1522.                             $newConds '';
  1523.                             foreach ($this->tokens[$x]['conditions'as $condition{
  1524.                                 $newConds .= token_name($condition).',';
  1525.                             }
  1526.  
  1527.                             $newConds rtrim($newConds',');
  1528.  
  1529.                             echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1530.                             echo "\t\t\t=> conditions changed from $oldConds to $newConds".PHP_EOL;
  1531.                         }
  1532.  
  1533.                         break;
  1534.                     }//end if
  1535.                 }//end foreach
  1536.             }//end for
  1537.         }//end for
  1538.  
  1539.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1540.             echo "\t*** END ADDITIONAL PHP PROCESSING ***".PHP_EOL;
  1541.         }
  1542.  
  1543.     }//end processAdditional()
  1544.  
  1545.  
  1546.     /**
  1547.      * Takes a token produced from <code>token_get_all()</code> and produces a
  1548.      * more uniform token.
  1549.      *
  1550.      * @param string|array$token The token to convert.
  1551.      *
  1552.      * @return array The new token.
  1553.      */
  1554.     public static function standardiseToken($token)
  1555.     {
  1556.         if (isset($token[1]=== false{
  1557.             if (isset(self::$resolveTokenCache[$token[0]]=== true{
  1558.                 return self::$resolveTokenCache[$token[0]];
  1559.             }
  1560.         else {
  1561.             $cacheKey = null;
  1562.             if ($token[0=== T_STRING{
  1563.                 $cacheKey strtolower($token[1]);
  1564.             else if ($token[0!== T_CURLY_OPEN{
  1565.                 $cacheKey $token[0];
  1566.             }
  1567.  
  1568.             if ($cacheKey !== null && isset(self::$resolveTokenCache[$cacheKey]=== true{
  1569.                 $newToken            = self::$resolveTokenCache[$cacheKey];
  1570.                 $newToken['content'$token[1];
  1571.                 return $newToken;
  1572.             }
  1573.         }
  1574.  
  1575.         if (isset($token[1]=== false{
  1576.             return self::resolveSimpleToken($token[0]);
  1577.         }
  1578.  
  1579.         if ($token[0=== T_STRING{
  1580.             switch ($cacheKey{
  1581.             case 'false':
  1582.                 $newToken['type''T_FALSE';
  1583.                 break;
  1584.             case 'true':
  1585.                 $newToken['type''T_TRUE';
  1586.                 break;
  1587.             case 'null':
  1588.                 $newToken['type''T_NULL';
  1589.                 break;
  1590.             case 'self':
  1591.                 $newToken['type''T_SELF';
  1592.                 break;
  1593.             case 'parent':
  1594.                 $newToken['type''T_PARENT';
  1595.                 break;
  1596.             default:
  1597.                 $newToken['type''T_STRING';
  1598.                 break;
  1599.             }
  1600.  
  1601.             $newToken['code'constant($newToken['type']);
  1602.  
  1603.             self::$resolveTokenCache[$cacheKey$newToken;
  1604.         else if ($token[0=== T_CURLY_OPEN{
  1605.             $newToken = array(
  1606.                          'code' => T_OPEN_CURLY_BRACKET,
  1607.                          'type' => 'T_OPEN_CURLY_BRACKET',
  1608.                         );
  1609.         else {
  1610.             $newToken = array(
  1611.                          'code' => $token[0],
  1612.                          'type' => token_name($token[0]),
  1613.                         );
  1614.  
  1615.             self::$resolveTokenCache[$token[0]] $newToken;
  1616.         }//end if
  1617.  
  1618.         $newToken['content'$token[1];
  1619.         return $newToken;
  1620.  
  1621.     }//end standardiseToken()
  1622.  
  1623.  
  1624.     /**
  1625.      * Converts simple tokens into a format that conforms to complex tokens
  1626.      * produced by token_get_all().
  1627.      *
  1628.      * Simple tokens are tokens that are not in array form when produced from
  1629.      * token_get_all().
  1630.      *
  1631.      * @param string $token The simple token to convert.
  1632.      *
  1633.      * @return array The new token in array format.
  1634.      */
  1635.     public static function resolveSimpleToken($token)
  1636.     {
  1637.         $newToken = array();
  1638.  
  1639.         switch ($token{
  1640.         case '{':
  1641.             $newToken['type''T_OPEN_CURLY_BRACKET';
  1642.             break;
  1643.         case '}':
  1644.             $newToken['type''T_CLOSE_CURLY_BRACKET';
  1645.             break;
  1646.         case '[':
  1647.             $newToken['type''T_OPEN_SQUARE_BRACKET';
  1648.             break;
  1649.         case ']':
  1650.             $newToken['type''T_CLOSE_SQUARE_BRACKET';
  1651.             break;
  1652.         case '(':
  1653.             $newToken['type''T_OPEN_PARENTHESIS';
  1654.             break;
  1655.         case ')':
  1656.             $newToken['type''T_CLOSE_PARENTHESIS';
  1657.             break;
  1658.         case ':':
  1659.             $newToken['type''T_COLON';
  1660.             break;
  1661.         case '.':
  1662.             $newToken['type''T_STRING_CONCAT';
  1663.             break;
  1664.         case '?':
  1665.             $newToken['type''T_INLINE_THEN';
  1666.             break;
  1667.         case ';':
  1668.             $newToken['type''T_SEMICOLON';
  1669.             break;
  1670.         case '=':
  1671.             $newToken['type''T_EQUAL';
  1672.             break;
  1673.         case '*':
  1674.             $newToken['type''T_MULTIPLY';
  1675.             break;
  1676.         case '/':
  1677.             $newToken['type''T_DIVIDE';
  1678.             break;
  1679.         case '+':
  1680.             $newToken['type''T_PLUS';
  1681.             break;
  1682.         case '-':
  1683.             $newToken['type''T_MINUS';
  1684.             break;
  1685.         case '%':
  1686.             $newToken['type''T_MODULUS';
  1687.             break;
  1688.         case '^':
  1689.             $newToken['type''T_BITWISE_XOR';
  1690.             break;
  1691.         case '&':
  1692.             $newToken['type''T_BITWISE_AND';
  1693.             break;
  1694.         case '|':
  1695.             $newToken['type''T_BITWISE_OR';
  1696.             break;
  1697.         case '<':
  1698.             $newToken['type''T_LESS_THAN';
  1699.             break;
  1700.         case '>':
  1701.             $newToken['type''T_GREATER_THAN';
  1702.             break;
  1703.         case '!':
  1704.             $newToken['type''T_BOOLEAN_NOT';
  1705.             break;
  1706.         case ',':
  1707.             $newToken['type''T_COMMA';
  1708.             break;
  1709.         case '@':
  1710.             $newToken['type''T_ASPERAND';
  1711.             break;
  1712.         case '$':
  1713.             $newToken['type''T_DOLLAR';
  1714.             break;
  1715.         case '`':
  1716.             $newToken['type''T_BACKTICK';
  1717.             break;
  1718.         default:
  1719.             $newToken['type''T_NONE';
  1720.             break;
  1721.         }//end switch
  1722.  
  1723.         $newToken['code']    = constant($newToken['type']);
  1724.         $newToken['content'$token;
  1725.  
  1726.         self::$resolveTokenCache[$token$newToken;
  1727.         return $newToken;
  1728.  
  1729.     }//end resolveSimpleToken()
  1730.  
  1731.  
  1732. }//end class

Documentation generated on Mon, 11 Mar 2019 14:51:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.