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_NULLABLE                 => 1,
  395.                             T_NULL                     => 4,
  396.                             T_FALSE                    => 5,
  397.                             T_TRUE                     => 4,
  398.                             T_SEMICOLON                => 1,
  399.                             T_EQUAL                    => 1,
  400.                             T_MULTIPLY                 => 1,
  401.                             T_DIVIDE                   => 1,
  402.                             T_PLUS                     => 1,
  403.                             T_MINUS                    => 1,
  404.                             T_MODULUS                  => 1,
  405.                             T_POW                      => 2,
  406.                             T_SPACESHIP                => 3,
  407.                             T_COALESCE                 => 2,
  408.                             T_COALESCE_EQUAL           => 3,
  409.                             T_BITWISE_AND              => 1,
  410.                             T_BITWISE_OR               => 1,
  411.                             T_BITWISE_XOR              => 1,
  412.                             T_SL                       => 2,
  413.                             T_SR                       => 2,
  414.                             T_SL_EQUAL                 => 3,
  415.                             T_SR_EQUAL                 => 3,
  416.                             T_ARRAY_HINT               => 5,
  417.                             T_GREATER_THAN             => 1,
  418.                             T_LESS_THAN                => 1,
  419.                             T_BOOLEAN_NOT              => 1,
  420.                             T_SELF                     => 4,
  421.                             T_PARENT                   => 6,
  422.                             T_COMMA                    => 1,
  423.                             T_THIS                     => 4,
  424.                             T_CLOSURE                  => 8,
  425.                             T_BACKTICK                 => 1,
  426.                             T_OPEN_SHORT_ARRAY         => 1,
  427.                             T_CLOSE_SHORT_ARRAY        => 1,
  428.                            );
  429.  
  430.  
  431.     /**
  432.      * A cache of different token types, resolved into arrays.
  433.      *
  434.      * @var array 
  435.      * @see standardiseToken()
  436.      */
  437.     private static $resolveTokenCache = array();
  438.  
  439.  
  440.     /**
  441.      * Creates an array of tokens when given some PHP code.
  442.      *
  443.      * Starts by using token_get_all() but does a lot of extra processing
  444.      * to insert information about the context of the token.
  445.      *
  446.      * @param string $string The string to tokenize.
  447.      *
  448.      * @return array 
  449.      */
  450.     protected function tokenize($string)
  451.     {
  452.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  453.             echo "\t*** START PHP TOKENIZING ***".PHP_EOL;
  454.             $isWin = false;
  455.             if (strtoupper(substr(PHP_OS03)) === 'WIN'{
  456.                 $isWin = true;
  457.             }
  458.         }
  459.  
  460.         $tokens      @token_get_all($string);
  461.         $finalTokens = array();
  462.  
  463.         $newStackPtr       = 0;
  464.         $numTokens         count($tokens);
  465.         $lastNotEmptyToken = 0;
  466.  
  467.         $insideInlineIf = array();
  468.         $insideUseGroup = false;
  469.  
  470.         $commentTokenizer = new Comment();
  471.  
  472.         for ($stackPtr = 0; $stackPtr $numTokens$stackPtr++{
  473.             $token        = (array) $tokens[$stackPtr];
  474.             $tokenIsArray = isset($token[1]);
  475.  
  476.             if (PHP_CODESNIFFER_VERBOSITY > 1{
  477.                 if ($tokenIsArray === true{
  478.                     $type    token_name($token[0]);
  479.                     $content = Util\Common::prepareForOutput($token[1]);
  480.                 else {
  481.                     $newToken = self::resolveSimpleToken($token[0]);
  482.                     $type     $newToken['type'];
  483.                     $content  = Util\Common::prepareForOutput($token[0]);
  484.                 }
  485.  
  486.                 echo "\tProcess token ";
  487.                 if ($tokenIsArray === true{
  488.                     echo "[$stackPtr]";
  489.                 else {
  490.                     echo " $stackPtr ";
  491.                 }
  492.  
  493.                 echo "$type => $content";
  494.             }//end if
  495.  
  496.             if ($newStackPtr > 0 && $finalTokens[($newStackPtr - 1)]['code'!== T_WHITESPACE{
  497.                 $lastNotEmptyToken ($newStackPtr - 1);
  498.             }
  499.  
  500.             /*
  501.                 If we are using \r\n newline characters, the \r and \n are sometimes
  502.                 split over two tokens. This normally occurs after comments. We need
  503.                 to merge these two characters together so that our line endings are
  504.                 consistent for all lines.
  505.             */
  506.  
  507.             if ($tokenIsArray === true && substr($token[1]-1=== "\r"{
  508.                 if (isset($tokens[($stackPtr + 1)]=== true
  509.                     && is_array($tokens[($stackPtr + 1)]=== true
  510.                     && $tokens[($stackPtr + 1)][1][0=== "\n"
  511.                 {
  512.                     $token[1.= "\n";
  513.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  514.                         if ($isWin === true{
  515.                             echo '\n';
  516.                         else {
  517.                             echo "\033[30;1m\\n\033[0m";
  518.                         }
  519.                     }
  520.  
  521.                     if ($tokens[($stackPtr + 1)][1=== "\n"{
  522.                         // This token's content has been merged into the previous,
  523.                         // so we can skip it.
  524.                         $tokens[($stackPtr + 1)'';
  525.                     else {
  526.                         $tokens[($stackPtr + 1)][1substr($tokens[($stackPtr + 1)][1]1);
  527.                     }
  528.                 }
  529.             }//end if
  530.  
  531.             if (PHP_CODESNIFFER_VERBOSITY > 1{
  532.                 echo PHP_EOL;
  533.             }
  534.  
  535.             /*
  536.                 Parse doc blocks into something that can be easily iterated over.
  537.             */
  538.  
  539.             if ($tokenIsArray === true && $token[0=== T_DOC_COMMENT{
  540.                 $commentTokens $commentTokenizer->tokenizeString($token[1]$this->eolChar$newStackPtr);
  541.                 foreach ($commentTokens as $commentToken{
  542.                     $finalTokens[$newStackPtr$commentToken;
  543.                     $newStackPtr++;
  544.                 }
  545.  
  546.                 continue;
  547.             }
  548.  
  549.             /*
  550.                 If this is a double quoted string, PHP will tokenize the whole
  551.                 thing which causes problems with the scope map when braces are
  552.                 within the string. So we need to merge the tokens together to
  553.                 provide a single string.
  554.             */
  555.  
  556.             if ($tokenIsArray === false && ($token[0=== '"' || $token[0=== 'b"')) {
  557.                 // Binary casts need a special token.
  558.                 if ($token[0=== 'b"'{
  559.                     $finalTokens[$newStackPtr= array(
  560.                                                   'code'    => T_BINARY_CAST,
  561.                                                   'type'    => 'T_BINARY_CAST',
  562.                                                   'content' => 'b',
  563.                                                  );
  564.                     $newStackPtr++;
  565.                 }
  566.  
  567.                 $tokenContent '"';
  568.                 $nestedVars   = array();
  569.                 for ($i ($stackPtr + 1)$i $numTokens$i++{
  570.                     $subToken        = (array) $tokens[$i];
  571.                     $subTokenIsArray = isset($subToken[1]);
  572.  
  573.                     if ($subTokenIsArray === true{
  574.                         $tokenContent .= $subToken[1];
  575.                         if ($subToken[1=== '{'
  576.                             && $subToken[0!== T_ENCAPSED_AND_WHITESPACE
  577.                         {
  578.                             $nestedVars[$i;
  579.                         }
  580.                     else {
  581.                         $tokenContent .= $subToken[0];
  582.                         if ($subToken[0=== '}'{
  583.                             array_pop($nestedVars);
  584.                         }
  585.                     }
  586.  
  587.                     if ($subTokenIsArray === false
  588.                         && $subToken[0=== '"'
  589.                         && empty($nestedVars=== true
  590.                     {
  591.                         // We found the other end of the double quoted string.
  592.                         break;
  593.                     }
  594.                 }//end for
  595.  
  596.                 $stackPtr $i;
  597.  
  598.                 // Convert each line within the double quoted string to a
  599.                 // new token, so it conforms with other multiple line tokens.
  600.                 $tokenLines explode($this->eolChar$tokenContent);
  601.                 $numLines   count($tokenLines);
  602.                 $newToken   = array();
  603.  
  604.                 for ($j = 0; $j $numLines$j++{
  605.                     $newToken['content'$tokenLines[$j];
  606.                     if ($j === ($numLines - 1)) {
  607.                         if ($tokenLines[$j=== ''{
  608.                             break;
  609.                         }
  610.                     else {
  611.                         $newToken['content'.= $this->eolChar;
  612.                     }
  613.  
  614.                     $newToken['code']          T_DOUBLE_QUOTED_STRING;
  615.                     $newToken['type']          'T_DOUBLE_QUOTED_STRING';
  616.                     $finalTokens[$newStackPtr$newToken;
  617.                     $newStackPtr++;
  618.                 }
  619.  
  620.                 // Continue, as we're done with this token.
  621.                 continue;
  622.             }//end if
  623.  
  624.             /*
  625.                 If this is a heredoc, PHP will tokenize the whole
  626.                 thing which causes problems when heredocs don't
  627.                 contain real PHP code, which is almost never.
  628.                 We want to leave the start and end heredoc tokens
  629.                 alone though.
  630.             */
  631.  
  632.             if ($tokenIsArray === true && $token[0=== T_START_HEREDOC{
  633.                 // Add the start heredoc token to the final array.
  634.                 $finalTokens[$newStackPtr= self::standardiseToken($token);
  635.  
  636.                 // Check if this is actually a nowdoc and use a different token
  637.                 // to help the sniffs.
  638.                 $nowdoc = false;
  639.                 if ($token[1][3=== "'"{
  640.                     $finalTokens[$newStackPtr]['code'T_START_NOWDOC;
  641.                     $finalTokens[$newStackPtr]['type''T_START_NOWDOC';
  642.                     $nowdoc = true;
  643.                 }
  644.  
  645.                 $tokenContent '';
  646.                 for ($i ($stackPtr + 1)$i $numTokens$i++{
  647.                     $subTokenIsArray is_array($tokens[$i]);
  648.                     if ($subTokenIsArray === true
  649.                         && $tokens[$i][0=== T_END_HEREDOC
  650.                     {
  651.                         // We found the other end of the heredoc.
  652.                         break;
  653.                     }
  654.  
  655.                     if ($subTokenIsArray === true{
  656.                         $tokenContent .= $tokens[$i][1];
  657.                     else {
  658.                         $tokenContent .= $tokens[$i];
  659.                     }
  660.                 }
  661.  
  662.                 if ($i === $numTokens{
  663.                     // We got to the end of the file and never
  664.                     // found the closing token, so this probably wasn't
  665.                     // a heredoc.
  666.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  667.                         $type $finalTokens[$newStackPtr]['type'];
  668.                         echo "\t\t* failed to find the end of the here/nowdoc".PHP_EOL;
  669.                         echo "\t\t* token $stackPtr changed from $type to T_STRING".PHP_EOL;
  670.                     }
  671.  
  672.                     $finalTokens[$newStackPtr]['code'= T_STRING;
  673.                     $finalTokens[$newStackPtr]['type''T_STRING';
  674.                     $newStackPtr++;
  675.                     continue;
  676.                 }
  677.  
  678.                 $stackPtr $i;
  679.                 $newStackPtr++;
  680.  
  681.                 // Convert each line within the heredoc to a
  682.                 // new token, so it conforms with other multiple line tokens.
  683.                 $tokenLines explode($this->eolChar$tokenContent);
  684.                 $numLines   count($tokenLines);
  685.                 $newToken   = array();
  686.  
  687.                 for ($j = 0; $j $numLines$j++{
  688.                     $newToken['content'$tokenLines[$j];
  689.                     if ($j === ($numLines - 1)) {
  690.                         if ($tokenLines[$j=== ''{
  691.                             break;
  692.                         }
  693.                     else {
  694.                         $newToken['content'.= $this->eolChar;
  695.                     }
  696.  
  697.                     if ($nowdoc === true{
  698.                         $newToken['code'T_NOWDOC;
  699.                         $newToken['type''T_NOWDOC';
  700.                     else {
  701.                         $newToken['code'T_HEREDOC;
  702.                         $newToken['type''T_HEREDOC';
  703.                     }
  704.  
  705.                     $finalTokens[$newStackPtr$newToken;
  706.                     $newStackPtr++;
  707.                 }//end for
  708.  
  709.                 // Add the end heredoc token to the final array.
  710.                 $finalTokens[$newStackPtr= self::standardiseToken($tokens[$stackPtr]);
  711.  
  712.                 if ($nowdoc === true{
  713.                     $finalTokens[$newStackPtr]['code'T_END_NOWDOC;
  714.                     $finalTokens[$newStackPtr]['type''T_END_NOWDOC';
  715.                     $nowdoc = true;
  716.                 }
  717.  
  718.                 $newStackPtr++;
  719.  
  720.                 // Continue, as we're done with this token.
  721.                 continue;
  722.             }//end if
  723.  
  724.             /*
  725.                 Before PHP 5.6, the ... operator was tokenized as three
  726.                 T_STRING_CONCAT tokens in a row. So look for and combine
  727.                 these tokens in earlier versions.
  728.             */
  729.  
  730.             if ($tokenIsArray === false
  731.                 && $token[0=== '.'
  732.                 && isset($tokens[($stackPtr + 1)]=== true
  733.                 && isset($tokens[($stackPtr + 2)]=== true
  734.                 && $tokens[($stackPtr + 1)=== '.'
  735.                 && $tokens[($stackPtr + 2)=== '.'
  736.             {
  737.                 $newToken            = array();
  738.                 $newToken['code']    T_ELLIPSIS;
  739.                 $newToken['type']    'T_ELLIPSIS';
  740.                 $newToken['content''...';
  741.                 $finalTokens[$newStackPtr$newToken;
  742.  
  743.                 $newStackPtr++;
  744.                 $stackPtr += 2;
  745.                 continue;
  746.             }
  747.  
  748.             /*
  749.                 Before PHP 5.6, the ** operator was tokenized as two
  750.                 T_MULTIPLY tokens in a row. So look for and combine
  751.                 these tokens in earlier versions.
  752.             */
  753.  
  754.             if ($tokenIsArray === false
  755.                 && $token[0=== '*'
  756.                 && isset($tokens[($stackPtr + 1)]=== true
  757.                 && $tokens[($stackPtr + 1)=== '*'
  758.             {
  759.                 $newToken            = array();
  760.                 $newToken['code']    T_POW;
  761.                 $newToken['type']    'T_POW';
  762.                 $newToken['content''**';
  763.                 $finalTokens[$newStackPtr$newToken;
  764.  
  765.                 $newStackPtr++;
  766.                 $stackPtr++;
  767.                 continue;
  768.             }
  769.  
  770.             /*
  771.                 Before PHP 5.6, the **= operator was tokenized as
  772.                 T_MULTIPLY followed by T_MUL_EQUAL. So look for and combine
  773.                 these tokens in earlier versions.
  774.             */
  775.  
  776.             if ($tokenIsArray === false
  777.                 && $token[0=== '*'
  778.                 && isset($tokens[($stackPtr + 1)]=== true
  779.                 && is_array($tokens[($stackPtr + 1)]=== true
  780.                 && $tokens[($stackPtr + 1)][1=== '*='
  781.             {
  782.                 $newToken            = array();
  783.                 $newToken['code']    T_POW_EQUAL;
  784.                 $newToken['type']    'T_POW_EQUAL';
  785.                 $newToken['content''**=';
  786.                 $finalTokens[$newStackPtr$newToken;
  787.  
  788.                 $newStackPtr++;
  789.                 $stackPtr++;
  790.                 continue;
  791.             }
  792.  
  793.             /*
  794.                 Before PHP 7, the ??= operator was tokenized as
  795.                 T_INLINE_THEN, T_INLINE_THEN, T_EQUAL.
  796.                 Between PHP 7.0 and 7.2, the ??= operator was tokenized as
  797.                 T_COALESCE, T_EQUAL.
  798.                 So look for and combine these tokens in earlier versions.
  799.             */
  800.  
  801.             if (($tokenIsArray === false
  802.                 && $token[0=== '?'
  803.                 && isset($tokens[($stackPtr + 1)]=== true
  804.                 && $tokens[($stackPtr + 1)][0=== '?'
  805.                 && isset($tokens[($stackPtr + 2)]=== true
  806.                 && $tokens[($stackPtr + 2)][0=== '=')
  807.                 || ($tokenIsArray === true
  808.                 && $token[0=== T_COALESCE
  809.                 && isset($tokens[($stackPtr + 1)]=== true
  810.                 && $tokens[($stackPtr + 1)][0=== '=')
  811.             {
  812.                 $newToken            = array();
  813.                 $newToken['code']    T_COALESCE_EQUAL;
  814.                 $newToken['type']    'T_COALESCE_EQUAL';
  815.                 $newToken['content''??=';
  816.                 $finalTokens[$newStackPtr$newToken;
  817.  
  818.                 $newStackPtr++;
  819.                 $stackPtr++;
  820.  
  821.                 if ($tokenIsArray === false{
  822.                     // Pre PHP 7.
  823.                     $stackPtr++;
  824.                 }
  825.  
  826.                 continue;
  827.             }
  828.  
  829.             /*
  830.                 Before PHP 7, the ?? operator was tokenized as
  831.                 T_INLINE_THEN followed by T_INLINE_THEN.
  832.                 So look for and combine these tokens in earlier versions.
  833.             */
  834.  
  835.             if ($tokenIsArray === false
  836.                 && $token[0=== '?'
  837.                 && isset($tokens[($stackPtr + 1)]=== true
  838.                 && $tokens[($stackPtr + 1)][0=== '?'
  839.             {
  840.                 $newToken            = array();
  841.                 $newToken['code']    T_COALESCE;
  842.                 $newToken['type']    'T_COALESCE';
  843.                 $newToken['content''??';
  844.                 $finalTokens[$newStackPtr$newToken;
  845.  
  846.                 $newStackPtr++;
  847.                 $stackPtr++;
  848.                 continue;
  849.             }
  850.  
  851.             /*
  852.                 Convert ? to T_NULLABLE OR T_INLINE_THEN
  853.             */
  854.  
  855.             if ($tokenIsArray === false && $token[0=== '?'{
  856.                 $newToken            = array();
  857.                 $newToken['content''?';
  858.  
  859.                 $prevNonEmpty = null;
  860.                 for ($i ($stackPtr - 1)$i >= 0; $i--{
  861.                     if (is_array($tokens[$i]=== true{
  862.                         $tokenType $tokens[$i][0];
  863.                     else {
  864.                         $tokenType $tokens[$i];
  865.                     }
  866.  
  867.                     if ($prevNonEmpty === null
  868.                         && isset(Util\Tokens::$emptyTokens[$tokenType]=== false
  869.                     {
  870.                         // Found the previous non-empty token.
  871.                         if ($tokenType === ':' || $tokenType === ','{
  872.                             $newToken['code'T_NULLABLE;
  873.                             $newToken['type''T_NULLABLE';
  874.                             break;
  875.                         }
  876.  
  877.                         $prevNonEmpty $tokenType;
  878.                     }
  879.  
  880.                     if ($tokenType === T_FUNCTION{
  881.                         $newToken['code'T_NULLABLE;
  882.                         $newToken['type''T_NULLABLE';
  883.                         break;
  884.                     else if (in_array($tokenTypearray(T_OPEN_TAGT_OPEN_TAG_WITH_ECHO'=''{'';')) === true{
  885.                         $newToken['code'T_INLINE_THEN;
  886.                         $newToken['type''T_INLINE_THEN';
  887.  
  888.                         $insideInlineIf[$stackPtr;
  889.                         break;
  890.                     }
  891.                 }//end for
  892.  
  893.                 $finalTokens[$newStackPtr$newToken;
  894.                 $newStackPtr++;
  895.                 continue;
  896.             }//end if
  897.  
  898.             /*
  899.                 Tokens after a double colon may be look like scope openers,
  900.                 such as when writing code like Foo::NAMESPACE, but they are
  901.                 only ever variables or strings.
  902.             */
  903.  
  904.             if ($stackPtr > 1
  905.                 && (is_array($tokens[($stackPtr - 1)]=== true
  906.                 && $tokens[($stackPtr - 1)][0=== T_PAAMAYIM_NEKUDOTAYIM)
  907.                 && $tokenIsArray === true
  908.                 && $token[0!== T_STRING
  909.                 && $token[0!== T_VARIABLE
  910.                 && $token[0!== T_DOLLAR
  911.                 && isset(Util\Tokens::$emptyTokens[$token[0]]=== false
  912.             {
  913.                 $newToken            = array();
  914.                 $newToken['code']    = T_STRING;
  915.                 $newToken['type']    'T_STRING';
  916.                 $newToken['content'$token[1];
  917.                 $finalTokens[$newStackPtr$newToken;
  918.  
  919.                 $newStackPtr++;
  920.                 continue;
  921.             }
  922.  
  923.             /*
  924.                 The string-like token after a function keyword should always be
  925.                 tokenized as T_STRING even if it appears to be a different token,
  926.                 such as when writing code like: function default(): foo
  927.                 so go forward and change the token type before it is processed.
  928.             */
  929.  
  930.             if ($tokenIsArray === true && $token[0=== T_FUNCTION{
  931.                 for ($x ($stackPtr + 1)$x $numTokens$x++{
  932.                     if (is_array($tokens[$x]=== false
  933.                         || isset(Util\Tokens::$emptyTokens[$tokens[$x][0]]=== false
  934.                     {
  935.                         // Non-empty content.
  936.                         break;
  937.                     }
  938.                 }
  939.  
  940.                 if ($x $numTokens && is_array($tokens[$x]=== true{
  941.                     $tokens[$x][0= T_STRING;
  942.                 }
  943.             }
  944.  
  945.             /*
  946.                 Before PHP 7, the <=> operator was tokenized as
  947.                 T_IS_SMALLER_OR_EQUAL followed by T_GREATER_THAN.
  948.                 So look for and combine these tokens in earlier versions.
  949.             */
  950.  
  951.             if ($tokenIsArray === true
  952.                 && $token[0=== T_IS_SMALLER_OR_EQUAL
  953.                 && isset($tokens[($stackPtr + 1)]=== true
  954.                 && $tokens[($stackPtr + 1)][0=== '>'
  955.             {
  956.                 $newToken            = array();
  957.                 $newToken['code']    T_SPACESHIP;
  958.                 $newToken['type']    'T_SPACESHIP';
  959.                 $newToken['content''<=>';
  960.                 $finalTokens[$newStackPtr$newToken;
  961.  
  962.                 $newStackPtr++;
  963.                 $stackPtr++;
  964.                 continue;
  965.             }
  966.  
  967.             /*
  968.                 PHP doesn't assign a token to goto labels, so we have to.
  969.                 These are just string tokens with a single colon after them. Double
  970.                 colons are already tokenized and so don't interfere with this check.
  971.                 But we do have to account for CASE statements, that look just like
  972.                 goto labels.
  973.             */
  974.  
  975.             if ($tokenIsArray === true
  976.                 && $token[0=== T_STRING
  977.                 && isset($tokens[($stackPtr + 1)]=== true
  978.                 && $tokens[($stackPtr + 1)=== ':'
  979.                 && $tokens[($stackPtr - 1)][0!== T_PAAMAYIM_NEKUDOTAYIM
  980.             {
  981.                 $stopTokens = array(
  982.                                T_CASE               => true,
  983.                                T_SEMICOLON          => true,
  984.                                T_OPEN_CURLY_BRACKET => true,
  985.                                T_INLINE_THEN        => true,
  986.                               );
  987.  
  988.                 for ($x ($newStackPtr - 1)$x > 0; $x--{
  989.                     if (isset($stopTokens[$finalTokens[$x]['code']]=== true{
  990.                         break;
  991.                     }
  992.                 }
  993.  
  994.                 if ($finalTokens[$x]['code'!== T_CASE
  995.                     && $finalTokens[$x]['code'!== T_INLINE_THEN
  996.                 {
  997.                     $finalTokens[$newStackPtr= array(
  998.                                                   'content' => $token[1].':',
  999.                                                   'code'    => T_GOTO_LABEL,
  1000.                                                   'type'    => 'T_GOTO_LABEL',
  1001.                                                  );
  1002.  
  1003.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1004.                         echo "\t\t* token $stackPtr changed from T_STRING to T_GOTO_LABEL".PHP_EOL;
  1005.                         echo "\t\t* skipping T_COLON token ".($stackPtr + 1).PHP_EOL;
  1006.                     }
  1007.  
  1008.                     $newStackPtr++;
  1009.                     $stackPtr++;
  1010.                     continue;
  1011.                 }
  1012.             }//end if
  1013.  
  1014.             /*
  1015.                 HHVM 3.5 tokenizes "else[\s]+if" as a T_ELSEIF token while PHP
  1016.                 proper only tokenizes "elseif" as a T_ELSEIF token. So split
  1017.                 up the HHVM token to make it looks like proper PHP.
  1018.             */
  1019.  
  1020.             if ($tokenIsArray === true
  1021.                 && $token[0=== T_ELSEIF
  1022.                 && strtolower($token[1]!== 'elseif'
  1023.             {
  1024.                 $finalTokens[$newStackPtr= array(
  1025.                                               'content' => substr($token[1]04),
  1026.                                               'code'    => T_ELSE,
  1027.                                               'type'    => 'T_ELSE',
  1028.                                              );
  1029.  
  1030.                 $newStackPtr++;
  1031.                 $finalTokens[$newStackPtr= array(
  1032.                                               'content' => substr($token[1]4-2),
  1033.                                               'code'    => T_WHITESPACE,
  1034.                                               'type'    => 'T_WHITESPACE',
  1035.                                              );
  1036.  
  1037.                 $newStackPtr++;
  1038.                 $finalTokens[$newStackPtr= array(
  1039.                                               'content' => substr($token[1]-2),
  1040.                                               'code'    => T_IF,
  1041.                                               'type'    => 'T_IF',
  1042.                                              );
  1043.  
  1044.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1045.                     echo "\t\t* token $stackPtr changed from T_ELSEIF to T_ELSE/T_WHITESPACE/T_IF".PHP_EOL;
  1046.                 }
  1047.  
  1048.                 $newStackPtr++;
  1049.                 continue;
  1050.             }//end if
  1051.  
  1052.             /*
  1053.                 HHVM 3.5 and 3.6 tokenizes a hashbang line such as #!/usr/bin/php
  1054.                 as T_HASHBANG while PHP proper uses T_INLINE_HTML.
  1055.             */
  1056.  
  1057.             if ($tokenIsArray === true && token_name($token[0]=== 'T_HASHBANG'{
  1058.                 $finalTokens[$newStackPtr= array(
  1059.                                               'content' => $token[1],
  1060.                                               'code'    => T_INLINE_HTML,
  1061.                                               'type'    => 'T_INLINE_HTML',
  1062.                                              );
  1063.  
  1064.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1065.                     echo "\t\t* token $stackPtr changed from T_HASHBANG to T_INLINE_HTML".PHP_EOL;
  1066.                 }
  1067.  
  1068.                 $newStackPtr++;
  1069.                 continue;
  1070.             }//end if
  1071.  
  1072.             /*
  1073.                 If this token has newlines in its content, split each line up
  1074.                 and create a new token for each line. We do this so it's easier
  1075.                 to ascertain where errors occur on a line.
  1076.                 Note that $token[1] is the token's content.
  1077.             */
  1078.  
  1079.             if ($tokenIsArray === true && strpos($token[1]$this->eolChar!== false{
  1080.                 $tokenLines explode($this->eolChar$token[1]);
  1081.                 $numLines   count($tokenLines);
  1082.                 $newToken   = array(
  1083.                                'type'    => token_name($token[0]),
  1084.                                'code'    => $token[0],
  1085.                                'content' => '',
  1086.                               );
  1087.  
  1088.                 for ($i = 0; $i $numLines$i++{
  1089.                     $newToken['content'$tokenLines[$i];
  1090.                     if ($i === ($numLines - 1)) {
  1091.                         if ($tokenLines[$i=== ''{
  1092.                             break;
  1093.                         }
  1094.                     else {
  1095.                         $newToken['content'.= $this->eolChar;
  1096.                     }
  1097.  
  1098.                     $finalTokens[$newStackPtr$newToken;
  1099.                     $newStackPtr++;
  1100.                 }
  1101.             else {
  1102.                 if ($tokenIsArray === true && $token[0=== T_STRING{
  1103.                     // Some T_STRING tokens should remain that way
  1104.                     // due to their context.
  1105.                     $context = array(
  1106.                                 T_OBJECT_OPERATOR      => true,
  1107.                                 T_FUNCTION             => true,
  1108.                                 T_CLASS                => true,
  1109.                                 T_EXTENDS              => true,
  1110.                                 T_IMPLEMENTS           => true,
  1111.                                 T_NEW                  => true,
  1112.                                 T_CONST                => true,
  1113.                                 T_NS_SEPARATOR         => true,
  1114.                                 T_USE                  => true,
  1115.                                 T_NAMESPACE            => true,
  1116.                                 T_PAAMAYIM_NEKUDOTAYIM => true,
  1117.                                );
  1118.                     if (isset($context[$finalTokens[$lastNotEmptyToken]['code']]=== true{
  1119.                         // Special case for syntax like: return new self
  1120.                         // where self should not be a string.
  1121.                         if ($finalTokens[$lastNotEmptyToken]['code'=== T_NEW
  1122.                             && strtolower($token[1]=== 'self'
  1123.                         {
  1124.                             $finalTokens[$newStackPtr= array(
  1125.                                                           'content' => $token[1],
  1126.                                                           'code'    => T_SELF,
  1127.                                                           'type'    => 'T_SELF',
  1128.                                                          );
  1129.                         else {
  1130.                             $finalTokens[$newStackPtr= array(
  1131.                                                           'content' => $token[1],
  1132.                                                           'code'    => T_STRING,
  1133.                                                           'type'    => 'T_STRING',
  1134.                                                          );
  1135.                         }
  1136.  
  1137.                         $newStackPtr++;
  1138.                         continue;
  1139.                     }//end if
  1140.                 }//end if
  1141.  
  1142.                 $newToken = null;
  1143.                 if ($tokenIsArray === false{
  1144.                     if (isset(self::$resolveTokenCache[$token[0]]=== true{
  1145.                         $newToken = self::$resolveTokenCache[$token[0]];
  1146.                     }
  1147.                 else {
  1148.                     $cacheKey = null;
  1149.                     if ($token[0=== T_STRING{
  1150.                         $cacheKey strtolower($token[1]);
  1151.                     else if ($token[0!== T_CURLY_OPEN{
  1152.                         $cacheKey $token[0];
  1153.                     }
  1154.  
  1155.                     if ($cacheKey !== null && isset(self::$resolveTokenCache[$cacheKey]=== true{
  1156.                         $newToken            = self::$resolveTokenCache[$cacheKey];
  1157.                         $newToken['content'$token[1];
  1158.                     }
  1159.                 }
  1160.  
  1161.                 if ($newToken === null{
  1162.                     $newToken = self::standardiseToken($token);
  1163.                 }
  1164.  
  1165.                 // Convert colons that are actually the ELSE component of an
  1166.                 // inline IF statement.
  1167.                 if (empty($insideInlineIf=== false && $newToken['code'=== T_COLON{
  1168.                     array_pop($insideInlineIf);
  1169.                     $newToken['code'T_INLINE_ELSE;
  1170.                     $newToken['type''T_INLINE_ELSE';
  1171.                 }
  1172.  
  1173.                 // This is a special condition for T_ARRAY tokens used for
  1174.                 // type hinting function arguments as being arrays. We want to keep
  1175.                 // the parenthesis map clean, so let's tag these tokens as
  1176.                 // T_ARRAY_HINT.
  1177.                 if ($newToken['code'=== T_ARRAY{
  1178.                     for ($i $stackPtr$i $numTokens$i++{
  1179.                         if ($tokens[$i=== '('{
  1180.                             break;
  1181.                         else if ($tokens[$i][0=== T_VARIABLE{
  1182.                             $newToken['code'T_ARRAY_HINT;
  1183.                             $newToken['type''T_ARRAY_HINT';
  1184.                             break;
  1185.                         }
  1186.                     }
  1187.                 }
  1188.  
  1189.                 // This is a special case when checking PHP 5.5+ code in PHP < 5.5
  1190.                 // where "finally" should be T_FINALLY instead of T_STRING.
  1191.                 if ($newToken['code'=== T_STRING
  1192.                     && strtolower($newToken['content']=== 'finally'
  1193.                 {
  1194.                     $newToken['code'T_FINALLY;
  1195.                     $newToken['type''T_FINALLY';
  1196.                 }
  1197.  
  1198.                 // This is a special case for the PHP 5.5 classname::class syntax
  1199.                 // where "class" should be T_STRING instead of T_CLASS.
  1200.                 if (($newToken['code'=== T_CLASS
  1201.                     || $newToken['code'=== T_FUNCTION)
  1202.                     && $finalTokens[($newStackPtr - 1)]['code'=== T_DOUBLE_COLON
  1203.                 {
  1204.                     $newToken['code'= T_STRING;
  1205.                     $newToken['type''T_STRING';
  1206.                 }
  1207.  
  1208.                 // This is a special case for PHP 5.6 use function and use const
  1209.                 // where "function" and "const" should be T_STRING instead of T_FUNCTION
  1210.                 // and T_CONST.
  1211.                 if (($newToken['code'=== T_FUNCTION
  1212.                     || $newToken['code'=== T_CONST)
  1213.                     && $finalTokens[$lastNotEmptyToken]['code'=== T_USE
  1214.                 {
  1215.                     $newToken['code'= T_STRING;
  1216.                     $newToken['type''T_STRING';
  1217.                 }
  1218.  
  1219.                 // This is a special case for use groups in PHP 7+ where leaving
  1220.                 // the curly braces as their normal tokens would confuse
  1221.                 // the scope map and sniffs.
  1222.                 if ($newToken['code'=== T_OPEN_CURLY_BRACKET
  1223.                     && $finalTokens[$lastNotEmptyToken]['code'=== T_NS_SEPARATOR
  1224.                 {
  1225.                     $newToken['code'T_OPEN_USE_GROUP;
  1226.                     $newToken['type''T_OPEN_USE_GROUP';
  1227.                     $insideUseGroup   = true;
  1228.                 }
  1229.  
  1230.                 if ($insideUseGroup === true && $newToken['code'=== T_CLOSE_CURLY_BRACKET{
  1231.                     $newToken['code'T_CLOSE_USE_GROUP;
  1232.                     $newToken['type''T_CLOSE_USE_GROUP';
  1233.                     $insideUseGroup   = false;
  1234.                 }
  1235.  
  1236.                 $finalTokens[$newStackPtr$newToken;
  1237.                 $newStackPtr++;
  1238.             }//end if
  1239.         }//end for
  1240.  
  1241.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1242.             echo "\t*** END PHP TOKENIZING ***".PHP_EOL;
  1243.         }
  1244.  
  1245.         return $finalTokens;
  1246.  
  1247.     }//end tokenize()
  1248.  
  1249.  
  1250.     /**
  1251.      * Performs additional processing after main tokenizing.
  1252.      *
  1253.      * This additional processing checks for CASE statements that are using curly
  1254.      * braces for scope openers and closers. It also turns some T_FUNCTION tokens
  1255.      * into T_CLOSURE when they are not standard function definitions. It also
  1256.      * detects short array syntax and converts those square brackets into new tokens.
  1257.      * It also corrects some usage of the static and class keywords. It also
  1258.      * assigns tokens to function return types.
  1259.      *
  1260.      * @return void 
  1261.      */
  1262.     protected function processAdditional()
  1263.     {
  1264.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1265.             echo "\t*** START ADDITIONAL PHP PROCESSING ***".PHP_EOL;
  1266.         }
  1267.  
  1268.         $numTokens count($this->tokens);
  1269.         for ($i ($numTokens - 1)$i >= 0; $i--{
  1270.             // Check for any unset scope conditions due to alternate IF/ENDIF syntax.
  1271.             if (isset($this->tokens[$i]['scope_opener']=== true
  1272.                 && isset($this->tokens[$i]['scope_condition']=== false
  1273.             {
  1274.                 $this->tokens[$i]['scope_condition'$this->tokens[$this->tokens[$i]['scope_opener']]['scope_condition'];
  1275.             }
  1276.  
  1277.             if ($this->tokens[$i]['code'=== T_FUNCTION{
  1278.                 /*
  1279.                     Detect functions that are actually closures and
  1280.                     assign them a different token.
  1281.                 */
  1282.  
  1283.                 if (isset($this->tokens[$i]['scope_opener']=== true{
  1284.                     for ($x ($i + 1)$x $numTokens$x++{
  1285.                         if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false
  1286.                             && $this->tokens[$x]['code'!== T_BITWISE_AND
  1287.                         {
  1288.                             break;
  1289.                         }
  1290.                     }
  1291.  
  1292.                     if ($this->tokens[$x]['code'=== T_OPEN_PARENTHESIS{
  1293.                         $this->tokens[$i]['code'T_CLOSURE;
  1294.                         $this->tokens[$i]['type''T_CLOSURE';
  1295.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1296.                             $line $this->tokens[$i]['line'];
  1297.                             echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE".PHP_EOL;
  1298.                         }
  1299.  
  1300.                         for ($x ($this->tokens[$i]['scope_opener'+ 1)$x $this->tokens[$i]['scope_closer']$x++{
  1301.                             if (isset($this->tokens[$x]['conditions'][$i]=== false{
  1302.                                 continue;
  1303.                             }
  1304.  
  1305.                             $this->tokens[$x]['conditions'][$iT_CLOSURE;
  1306.                             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1307.                                 $type $this->tokens[$x]['type'];
  1308.                                 echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1309.                             }
  1310.                         }
  1311.                     }
  1312.  
  1313.                     $tokenAfterReturnTypeHint $this->tokens[$i]['scope_opener'];
  1314.                 else if (isset($this->tokens[$i]['parenthesis_closer']=== true{
  1315.                     $tokenAfterReturnTypeHint = null;
  1316.                     for ($x ($this->tokens[$i]['parenthesis_closer'+ 1)$x $numTokens$x++{
  1317.                         if ($this->tokens[$x]['code'=== T_SEMICOLON{
  1318.                             $tokenAfterReturnTypeHint $x;
  1319.                             break;
  1320.                         }
  1321.                     }
  1322.  
  1323.                     if ($tokenAfterReturnTypeHint === null{
  1324.                         // Probably a syntax error.
  1325.                         continue;
  1326.                     }
  1327.                 else {
  1328.                     // Probably a syntax error.
  1329.                     continue;
  1330.                 }//end if
  1331.  
  1332.                 /*
  1333.                     Detect function return values and assign them
  1334.                     a special token, because PHP doesn't.
  1335.                 */
  1336.  
  1337.                 for ($x ($tokenAfterReturnTypeHint - 1)$x $i$x--{
  1338.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1339.                         if (in_array($this->tokens[$x]['code']array(T_STRINGT_ARRAYT_ARRAY_HINTT_CALLABLET_SELFT_PARENT)true=== true{
  1340.                             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1341.                                 $line $this->tokens[$x]['line'];
  1342.                                 $type $this->tokens[$x]['type'];
  1343.                                 echo "\t* token $x on line $line changed from $type to T_RETURN_TYPE".PHP_EOL;
  1344.                             }
  1345.  
  1346.                             $this->tokens[$x]['code'T_RETURN_TYPE;
  1347.                             $this->tokens[$x]['type''T_RETURN_TYPE';
  1348.                         }
  1349.  
  1350.                         break;
  1351.                     }
  1352.                 }
  1353.  
  1354.                 continue;
  1355.             else if ($this->tokens[$i]['code'=== T_CLASS && isset($this->tokens[$i]['scope_opener']=== true{
  1356.                 /*
  1357.                     Detect anonymous classes and assign them a different token.
  1358.                 */
  1359.  
  1360.                 for ($x ($i + 1)$x $numTokens$x++{
  1361.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1362.                         break;
  1363.                     }
  1364.                 }
  1365.  
  1366.                 if ($this->tokens[$x]['code'=== T_OPEN_PARENTHESIS
  1367.                     || $this->tokens[$x]['code'=== T_OPEN_CURLY_BRACKET
  1368.                     || $this->tokens[$x]['code'=== T_EXTENDS
  1369.                     || $this->tokens[$x]['code'=== T_IMPLEMENTS
  1370.                 {
  1371.                     $this->tokens[$i]['code'T_ANON_CLASS;
  1372.                     $this->tokens[$i]['type''T_ANON_CLASS';
  1373.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1374.                         $line $this->tokens[$i]['line'];
  1375.                         echo "\t* token $i on line $line changed from T_CLASS to T_ANON_CLASS".PHP_EOL;
  1376.                     }
  1377.  
  1378.                     for ($x ($this->tokens[$i]['scope_opener'+ 1)$x $this->tokens[$i]['scope_closer']$x++{
  1379.                         if (isset($this->tokens[$x]['conditions'][$i]=== false{
  1380.                             continue;
  1381.                         }
  1382.  
  1383.                         $this->tokens[$x]['conditions'][$iT_ANON_CLASS;
  1384.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1385.                             $type $this->tokens[$x]['type'];
  1386.                             echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1387.                         }
  1388.                     }
  1389.                 }
  1390.  
  1391.                 continue;
  1392.             else if ($this->tokens[$i]['code'=== T_OPEN_SQUARE_BRACKET{
  1393.                 if (isset($this->tokens[$i]['bracket_closer']=== false{
  1394.                     continue;
  1395.                 }
  1396.  
  1397.                 // Unless there is a variable or a bracket before this token,
  1398.                 // it is the start of an array being defined using the short syntax.
  1399.                 $isShortArray = false;
  1400.                 $allowed      = array(
  1401.                                  T_CLOSE_SQUARE_BRACKET     => T_CLOSE_SQUARE_BRACKET,
  1402.                                  T_CLOSE_CURLY_BRACKET      => T_CLOSE_CURLY_BRACKET,
  1403.                                  T_CLOSE_PARENTHESIS        => T_CLOSE_PARENTHESIS,
  1404.                                  T_VARIABLE                 => T_VARIABLE,
  1405.                                  T_OBJECT_OPERATOR          => T_OBJECT_OPERATOR,
  1406.                                  T_STRING                   => T_STRING,
  1407.                                  T_CONSTANT_ENCAPSED_STRING => T_CONSTANT_ENCAPSED_STRING,
  1408.                                 );
  1409.  
  1410.                 for ($x ($i - 1)$x > 0; $x--{
  1411.                     // If we hit a scope opener, the statement has ended
  1412.                     // without finding anything, so it's probably an array
  1413.                     // using PHP 7.1 short list syntax.
  1414.                     if (isset($this->tokens[$x]['scope_opener']=== true{
  1415.                         $isShortArray = true;
  1416.                         break;
  1417.                     }
  1418.  
  1419.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1420.                         if (isset($allowed[$this->tokens[$x]['code']]=== false{
  1421.                             $isShortArray = true;
  1422.                         }
  1423.  
  1424.                         break;
  1425.                     }
  1426.                 }
  1427.  
  1428.                 if ($isShortArray === true{
  1429.                     $this->tokens[$i]['code'T_OPEN_SHORT_ARRAY;
  1430.                     $this->tokens[$i]['type''T_OPEN_SHORT_ARRAY';
  1431.  
  1432.                     $closer $this->tokens[$i]['bracket_closer'];
  1433.                     $this->tokens[$closer]['code'T_CLOSE_SHORT_ARRAY;
  1434.                     $this->tokens[$closer]['type''T_CLOSE_SHORT_ARRAY';
  1435.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1436.                         $line $this->tokens[$i]['line'];
  1437.                         echo "\t* token $i on line $line changed from T_OPEN_SQUARE_BRACKET to T_OPEN_SHORT_ARRAY".PHP_EOL;
  1438.                         $line $this->tokens[$closer]['line'];
  1439.                         echo "\t* token $closer on line $line changed from T_CLOSE_SQUARE_BRACKET to T_CLOSE_SHORT_ARRAY".PHP_EOL;
  1440.                     }
  1441.                 }
  1442.  
  1443.                 continue;
  1444.             else if ($this->tokens[$i]['code'=== T_STATIC{
  1445.                 for ($x ($i - 1)$x > 0; $x--{
  1446.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1447.                         break;
  1448.                     }
  1449.                 }
  1450.  
  1451.                 if ($this->tokens[$x]['code'=== T_INSTANCEOF{
  1452.                     $this->tokens[$i]['code'= T_STRING;
  1453.                     $this->tokens[$i]['type''T_STRING';
  1454.  
  1455.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1456.                         $line $this->tokens[$i]['line'];
  1457.                         echo "\t* token $i on line $line changed from T_STATIC to T_STRING".PHP_EOL;
  1458.                     }
  1459.                 }
  1460.  
  1461.                 continue;
  1462.             else if ($this->tokens[$i]['code'=== T_ECHO && $this->tokens[$i]['content'=== '<?='{
  1463.                 // HHVM tokenizes <?= as T_ECHO but it should be T_OPEN_TAG_WITH_ECHO.
  1464.                 $this->tokens[$i]['code'= T_OPEN_TAG_WITH_ECHO;
  1465.                 $this->tokens[$i]['type''T_OPEN_TAG_WITH_ECHO';
  1466.  
  1467.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1468.                     $line $this->tokens[$i]['line'];
  1469.                     echo "\t* token $i on line $line changed from T_ECHO to T_OPEN_TAG_WITH_ECHO".PHP_EOL;
  1470.                 }
  1471.             else if ($this->tokens[$i]['code'=== T_TRUE
  1472.                 || $this->tokens[$i]['code'=== T_FALSE
  1473.                 || $this->tokens[$i]['code'=== T_NULL
  1474.             {
  1475.                 for ($x ($i + 1)$i $numTokens$x++{
  1476.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1477.                         // Non-whitespace content.
  1478.                         break;
  1479.                     }
  1480.                 }
  1481.  
  1482.                 $context = array(
  1483.                             T_OBJECT_OPERATOR      => true,
  1484.                             T_NS_SEPARATOR         => true,
  1485.                             T_PAAMAYIM_NEKUDOTAYIM => true,
  1486.                            );
  1487.                 if (isset($context[$this->tokens[$x]['code']]=== true{
  1488.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1489.                         $line $this->tokens[$i]['line'];
  1490.                         $type $this->tokens[$i]['type'];
  1491.                         echo "\t* token $i on line $line changed from $type to T_STRING".PHP_EOL;
  1492.                     }
  1493.  
  1494.                     $this->tokens[$i]['code'= T_STRING;
  1495.                     $this->tokens[$i]['type''T_STRING';
  1496.                 }
  1497.             else if ($this->tokens[$i]['code'=== T_CONST{
  1498.                 // Context sensitive keywords support.
  1499.                 for ($x ($i + 1)$i $numTokens$x++{
  1500.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1501.                         // Non-whitespace content.
  1502.                         break;
  1503.                     }
  1504.                 }
  1505.  
  1506.                 if ($this->tokens[$x]['code'!== T_STRING{
  1507.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1508.                         $line $this->tokens[$x]['line'];
  1509.                         $type $this->tokens[$x]['type'];
  1510.                         echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL;
  1511.                     }
  1512.  
  1513.                     $this->tokens[$x]['code'= T_STRING;
  1514.                     $this->tokens[$x]['type''T_STRING';
  1515.                 }
  1516.             }//end if
  1517.  
  1518.             if (($this->tokens[$i]['code'!== T_CASE
  1519.                 && $this->tokens[$i]['code'!== T_DEFAULT)
  1520.                 || isset($this->tokens[$i]['scope_opener']=== false
  1521.             {
  1522.                 // Only interested in CASE and DEFAULT statements from here on in.
  1523.                 continue;
  1524.             }
  1525.  
  1526.             $scopeOpener $this->tokens[$i]['scope_opener'];
  1527.             $scopeCloser $this->tokens[$i]['scope_closer'];
  1528.  
  1529.             // If the first char after the opener is a curly brace
  1530.             // and that brace has been ignored, it is actually
  1531.             // opening this case statement and the opener and closer are
  1532.             // probably set incorrectly.
  1533.             for ($x ($scopeOpener + 1)$x $numTokens$x++{
  1534.                 if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1535.                     // Non-whitespace content.
  1536.                     break;
  1537.                 }
  1538.             }
  1539.  
  1540.             if ($this->tokens[$x]['code'=== T_CASE || $this->tokens[$x]['code'=== T_DEFAULT{
  1541.                 // Special case for multiple CASE statements that share the same
  1542.                 // closer. Because we are going backwards through the file, this next
  1543.                 // CASE statement is already fixed, so just use its closer and don't
  1544.                 // worry about fixing anything.
  1545.                 $newCloser $this->tokens[$x]['scope_closer'];
  1546.                 $this->tokens[$i]['scope_closer'$newCloser;
  1547.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1548.                     $oldType $this->tokens[$scopeCloser]['type'];
  1549.                     $newType $this->tokens[$newCloser]['type'];
  1550.                     $line    $this->tokens[$i]['line'];
  1551.                     echo "\t* token $i (T_CASE) on line $line closer changed from $scopeCloser ($oldType) to $newCloser ($newType)".PHP_EOL;
  1552.                 }
  1553.  
  1554.                 continue;
  1555.             }
  1556.  
  1557.             if ($this->tokens[$x]['code'!== T_OPEN_CURLY_BRACKET
  1558.                 || isset($this->tokens[$x]['scope_condition']=== true
  1559.             {
  1560.                 // Not a CASE/DEFAULT with a curly brace opener.
  1561.                 continue;
  1562.             }
  1563.  
  1564.             // The closer for this CASE/DEFAULT should be the closing curly brace and
  1565.             // not whatever it already is. The opener needs to be the opening curly
  1566.             // brace so everything matches up.
  1567.             $newCloser $this->tokens[$x]['bracket_closer'];
  1568.             foreach (array($i$x$newCloseras $index{
  1569.                 $this->tokens[$index]['scope_condition'$i;
  1570.                 $this->tokens[$index]['scope_opener']    $x;
  1571.                 $this->tokens[$index]['scope_closer']    $newCloser;
  1572.             }
  1573.  
  1574.             unset($this->tokens[$scopeOpener]['scope_condition']);
  1575.             unset($this->tokens[$scopeOpener]['scope_opener']);
  1576.             unset($this->tokens[$scopeOpener]['scope_closer']);
  1577.             unset($this->tokens[$scopeCloser]['scope_condition']);
  1578.             unset($this->tokens[$scopeCloser]['scope_opener']);
  1579.             unset($this->tokens[$scopeCloser]['scope_closer']);
  1580.             unset($this->tokens[$x]['bracket_opener']);
  1581.             unset($this->tokens[$x]['bracket_closer']);
  1582.             unset($this->tokens[$newCloser]['bracket_opener']);
  1583.             unset($this->tokens[$newCloser]['bracket_closer']);
  1584.             $this->tokens[$scopeCloser]['conditions'][$i;
  1585.  
  1586.             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1587.                 $line      $this->tokens[$i]['line'];
  1588.                 $tokenType $this->tokens[$i]['type'];
  1589.  
  1590.                 $oldType $this->tokens[$scopeOpener]['type'];
  1591.                 $newType $this->tokens[$x]['type'];
  1592.                 echo "\t* token $i ($tokenType) on line $line opener changed from $scopeOpener ($oldType) to $x ($newType)".PHP_EOL;
  1593.  
  1594.                 $oldType $this->tokens[$scopeCloser]['type'];
  1595.                 $newType $this->tokens[$newCloser]['type'];
  1596.                 echo "\t* token $i ($tokenType) on line $line closer changed from $scopeCloser ($oldType) to $newCloser ($newType)".PHP_EOL;
  1597.             }
  1598.  
  1599.             // Now fix up all the tokens that think they are
  1600.             // inside the CASE/DEFAULT statement when they are really outside.
  1601.             for ($x $newCloser$x $scopeCloser$x++{
  1602.                 foreach ($this->tokens[$x]['conditions'as $num => $oldCond{
  1603.                     if ($oldCond === $this->tokens[$i]['code']{
  1604.                         $oldConditions $this->tokens[$x]['conditions'];
  1605.                         unset($this->tokens[$x]['conditions'][$num]);
  1606.  
  1607.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1608.                             $type     $this->tokens[$x]['type'];
  1609.                             $oldConds '';
  1610.                             foreach ($oldConditions as $condition{
  1611.                                 $oldConds .= token_name($condition).',';
  1612.                             }
  1613.  
  1614.                             $oldConds rtrim($oldConds',');
  1615.  
  1616.                             $newConds '';
  1617.                             foreach ($this->tokens[$x]['conditions'as $condition{
  1618.                                 $newConds .= token_name($condition).',';
  1619.                             }
  1620.  
  1621.                             $newConds rtrim($newConds',');
  1622.  
  1623.                             echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1624.                             echo "\t\t\t=> conditions changed from $oldConds to $newConds".PHP_EOL;
  1625.                         }
  1626.  
  1627.                         break;
  1628.                     }//end if
  1629.                 }//end foreach
  1630.             }//end for
  1631.         }//end for
  1632.  
  1633.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1634.             echo "\t*** END ADDITIONAL PHP PROCESSING ***".PHP_EOL;
  1635.         }
  1636.  
  1637.     }//end processAdditional()
  1638.  
  1639.  
  1640.     /**
  1641.      * Takes a token produced from <code>token_get_all()</code> and produces a
  1642.      * more uniform token.
  1643.      *
  1644.      * @param string|array$token The token to convert.
  1645.      *
  1646.      * @return array The new token.
  1647.      */
  1648.     public static function standardiseToken($token)
  1649.     {
  1650.         if (isset($token[1]=== false{
  1651.             if (isset(self::$resolveTokenCache[$token[0]]=== true{
  1652.                 return self::$resolveTokenCache[$token[0]];
  1653.             }
  1654.         else {
  1655.             $cacheKey = null;
  1656.             if ($token[0=== T_STRING{
  1657.                 $cacheKey strtolower($token[1]);
  1658.             else if ($token[0!== T_CURLY_OPEN{
  1659.                 $cacheKey $token[0];
  1660.             }
  1661.  
  1662.             if ($cacheKey !== null && isset(self::$resolveTokenCache[$cacheKey]=== true{
  1663.                 $newToken            = self::$resolveTokenCache[$cacheKey];
  1664.                 $newToken['content'$token[1];
  1665.                 return $newToken;
  1666.             }
  1667.         }
  1668.  
  1669.         if (isset($token[1]=== false{
  1670.             return self::resolveSimpleToken($token[0]);
  1671.         }
  1672.  
  1673.         if ($token[0=== T_STRING{
  1674.             switch ($cacheKey{
  1675.             case 'false':
  1676.                 $newToken['type''T_FALSE';
  1677.                 break;
  1678.             case 'true':
  1679.                 $newToken['type''T_TRUE';
  1680.                 break;
  1681.             case 'null':
  1682.                 $newToken['type''T_NULL';
  1683.                 break;
  1684.             case 'self':
  1685.                 $newToken['type''T_SELF';
  1686.                 break;
  1687.             case 'parent':
  1688.                 $newToken['type''T_PARENT';
  1689.                 break;
  1690.             default:
  1691.                 $newToken['type''T_STRING';
  1692.                 break;
  1693.             }
  1694.  
  1695.             $newToken['code'constant($newToken['type']);
  1696.  
  1697.             self::$resolveTokenCache[$cacheKey$newToken;
  1698.         else if ($token[0=== T_CURLY_OPEN{
  1699.             $newToken = array(
  1700.                          'code' => T_OPEN_CURLY_BRACKET,
  1701.                          'type' => 'T_OPEN_CURLY_BRACKET',
  1702.                         );
  1703.         else {
  1704.             $newToken = array(
  1705.                          'code' => $token[0],
  1706.                          'type' => token_name($token[0]),
  1707.                         );
  1708.  
  1709.             self::$resolveTokenCache[$token[0]] $newToken;
  1710.         }//end if
  1711.  
  1712.         $newToken['content'$token[1];
  1713.         return $newToken;
  1714.  
  1715.     }//end standardiseToken()
  1716.  
  1717.  
  1718.     /**
  1719.      * Converts simple tokens into a format that conforms to complex tokens
  1720.      * produced by token_get_all().
  1721.      *
  1722.      * Simple tokens are tokens that are not in array form when produced from
  1723.      * token_get_all().
  1724.      *
  1725.      * @param string $token The simple token to convert.
  1726.      *
  1727.      * @return array The new token in array format.
  1728.      */
  1729.     public static function resolveSimpleToken($token)
  1730.     {
  1731.         $newToken = array();
  1732.  
  1733.         switch ($token{
  1734.         case '{':
  1735.             $newToken['type''T_OPEN_CURLY_BRACKET';
  1736.             break;
  1737.         case '}':
  1738.             $newToken['type''T_CLOSE_CURLY_BRACKET';
  1739.             break;
  1740.         case '[':
  1741.             $newToken['type''T_OPEN_SQUARE_BRACKET';
  1742.             break;
  1743.         case ']':
  1744.             $newToken['type''T_CLOSE_SQUARE_BRACKET';
  1745.             break;
  1746.         case '(':
  1747.             $newToken['type''T_OPEN_PARENTHESIS';
  1748.             break;
  1749.         case ')':
  1750.             $newToken['type''T_CLOSE_PARENTHESIS';
  1751.             break;
  1752.         case ':':
  1753.             $newToken['type''T_COLON';
  1754.             break;
  1755.         case '.':
  1756.             $newToken['type''T_STRING_CONCAT';
  1757.             break;
  1758.         case ';':
  1759.             $newToken['type''T_SEMICOLON';
  1760.             break;
  1761.         case '=':
  1762.             $newToken['type''T_EQUAL';
  1763.             break;
  1764.         case '*':
  1765.             $newToken['type''T_MULTIPLY';
  1766.             break;
  1767.         case '/':
  1768.             $newToken['type''T_DIVIDE';
  1769.             break;
  1770.         case '+':
  1771.             $newToken['type''T_PLUS';
  1772.             break;
  1773.         case '-':
  1774.             $newToken['type''T_MINUS';
  1775.             break;
  1776.         case '%':
  1777.             $newToken['type''T_MODULUS';
  1778.             break;
  1779.         case '^':
  1780.             $newToken['type''T_BITWISE_XOR';
  1781.             break;
  1782.         case '&':
  1783.             $newToken['type''T_BITWISE_AND';
  1784.             break;
  1785.         case '|':
  1786.             $newToken['type''T_BITWISE_OR';
  1787.             break;
  1788.         case '<':
  1789.             $newToken['type''T_LESS_THAN';
  1790.             break;
  1791.         case '>':
  1792.             $newToken['type''T_GREATER_THAN';
  1793.             break;
  1794.         case '!':
  1795.             $newToken['type''T_BOOLEAN_NOT';
  1796.             break;
  1797.         case ',':
  1798.             $newToken['type''T_COMMA';
  1799.             break;
  1800.         case '@':
  1801.             $newToken['type''T_ASPERAND';
  1802.             break;
  1803.         case '$':
  1804.             $newToken['type''T_DOLLAR';
  1805.             break;
  1806.         case '`':
  1807.             $newToken['type''T_BACKTICK';
  1808.             break;
  1809.         default:
  1810.             $newToken['type''T_NONE';
  1811.             break;
  1812.         }//end switch
  1813.  
  1814.         $newToken['code']    = constant($newToken['type']);
  1815.         $newToken['content'$token;
  1816.  
  1817.         self::$resolveTokenCache[$token$newToken;
  1818.         return $newToken;
  1819.  
  1820.     }//end resolveSimpleToken()
  1821.  
  1822.  
  1823. }//end class

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