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.                 for ($i ($stackPtr - 1)$i >= 0; $i--{
  860.                     if (is_array($tokens[$i]=== true{
  861.                         $tokenType $tokens[$i][0];
  862.                     else {
  863.                         $tokenType $tokens[$i];
  864.                     }
  865.  
  866.                     if ($tokenType === T_FUNCTION{
  867.                         $newToken['code'T_NULLABLE;
  868.                         $newToken['type''T_NULLABLE';
  869.                         break;
  870.                     else if (in_array($tokenTypearray(T_OPEN_TAGT_OPEN_TAG_WITH_ECHO'=''{'';')) === true{
  871.                         $newToken['code'T_INLINE_THEN;
  872.                         $newToken['type''T_INLINE_THEN';
  873.  
  874.                         $insideInlineIf[$stackPtr;
  875.                         break;
  876.                     }
  877.                 }
  878.  
  879.                 $finalTokens[$newStackPtr$newToken;
  880.                 $newStackPtr++;
  881.                 continue;
  882.             }//end if
  883.  
  884.             /*
  885.                 Tokens after a double colon may be look like scope openers,
  886.                 such as when writing code like Foo::NAMESPACE, but they are
  887.                 only ever variables or strings.
  888.             */
  889.  
  890.             if ($stackPtr > 1
  891.                 && (is_array($tokens[($stackPtr - 1)]=== true
  892.                 && $tokens[($stackPtr - 1)][0=== T_PAAMAYIM_NEKUDOTAYIM)
  893.                 && $tokenIsArray === true
  894.                 && $token[0!== T_STRING
  895.                 && $token[0!== T_VARIABLE
  896.                 && $token[0!== T_DOLLAR
  897.                 && isset(Util\Tokens::$emptyTokens[$token[0]]=== false
  898.             {
  899.                 $newToken            = array();
  900.                 $newToken['code']    = T_STRING;
  901.                 $newToken['type']    'T_STRING';
  902.                 $newToken['content'$token[1];
  903.                 $finalTokens[$newStackPtr$newToken;
  904.  
  905.                 $newStackPtr++;
  906.                 continue;
  907.             }
  908.  
  909.             /*
  910.                 The string-like token after a function keyword should always be
  911.                 tokenized as T_STRING even if it appears to be a different token,
  912.                 such as when writing code like: function default(): foo
  913.                 so go forward and change the token type before it is processed.
  914.             */
  915.  
  916.             if ($tokenIsArray === true && $token[0=== T_FUNCTION{
  917.                 for ($x ($stackPtr + 1)$x $numTokens$x++{
  918.                     if (is_array($tokens[$x]=== false
  919.                         || isset(Util\Tokens::$emptyTokens[$tokens[$x][0]]=== false
  920.                     {
  921.                         // Non-empty content.
  922.                         break;
  923.                     }
  924.                 }
  925.  
  926.                 if ($x $numTokens && is_array($tokens[$x]=== true{
  927.                     $tokens[$x][0= T_STRING;
  928.                 }
  929.             }
  930.  
  931.             /*
  932.                 Before PHP 7, the <=> operator was tokenized as
  933.                 T_IS_SMALLER_OR_EQUAL followed by T_GREATER_THAN.
  934.                 So look for and combine these tokens in earlier versions.
  935.             */
  936.  
  937.             if ($tokenIsArray === true
  938.                 && $token[0=== T_IS_SMALLER_OR_EQUAL
  939.                 && isset($tokens[($stackPtr + 1)]=== true
  940.                 && $tokens[($stackPtr + 1)][0=== '>'
  941.             {
  942.                 $newToken            = array();
  943.                 $newToken['code']    T_SPACESHIP;
  944.                 $newToken['type']    'T_SPACESHIP';
  945.                 $newToken['content''<=>';
  946.                 $finalTokens[$newStackPtr$newToken;
  947.  
  948.                 $newStackPtr++;
  949.                 $stackPtr++;
  950.                 continue;
  951.             }
  952.  
  953.             /*
  954.                 PHP doesn't assign a token to goto labels, so we have to.
  955.                 These are just string tokens with a single colon after them. Double
  956.                 colons are already tokenized and so don't interfere with this check.
  957.                 But we do have to account for CASE statements, that look just like
  958.                 goto labels.
  959.             */
  960.  
  961.             if ($tokenIsArray === true
  962.                 && $token[0=== T_STRING
  963.                 && isset($tokens[($stackPtr + 1)]=== true
  964.                 && $tokens[($stackPtr + 1)=== ':'
  965.                 && $tokens[($stackPtr - 1)][0!== T_PAAMAYIM_NEKUDOTAYIM
  966.             {
  967.                 $stopTokens = array(
  968.                                T_CASE               => true,
  969.                                T_SEMICOLON          => true,
  970.                                T_OPEN_CURLY_BRACKET => true,
  971.                                T_INLINE_THEN        => true,
  972.                               );
  973.  
  974.                 for ($x ($newStackPtr - 1)$x > 0; $x--{
  975.                     if (isset($stopTokens[$finalTokens[$x]['code']]=== true{
  976.                         break;
  977.                     }
  978.                 }
  979.  
  980.                 if ($finalTokens[$x]['code'!== T_CASE
  981.                     && $finalTokens[$x]['code'!== T_INLINE_THEN
  982.                 {
  983.                     $finalTokens[$newStackPtr= array(
  984.                                                   'content' => $token[1].':',
  985.                                                   'code'    => T_GOTO_LABEL,
  986.                                                   'type'    => 'T_GOTO_LABEL',
  987.                                                  );
  988.  
  989.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  990.                         echo "\t\t* token $stackPtr changed from T_STRING to T_GOTO_LABEL".PHP_EOL;
  991.                         echo "\t\t* skipping T_COLON token ".($stackPtr + 1).PHP_EOL;
  992.                     }
  993.  
  994.                     $newStackPtr++;
  995.                     $stackPtr++;
  996.                     continue;
  997.                 }
  998.             }//end if
  999.  
  1000.             /*
  1001.                 HHVM 3.5 tokenizes "else[\s]+if" as a T_ELSEIF token while PHP
  1002.                 proper only tokenizes "elseif" as a T_ELSEIF token. So split
  1003.                 up the HHVM token to make it looks like proper PHP.
  1004.             */
  1005.  
  1006.             if ($tokenIsArray === true
  1007.                 && $token[0=== T_ELSEIF
  1008.                 && strtolower($token[1]!== 'elseif'
  1009.             {
  1010.                 $finalTokens[$newStackPtr= array(
  1011.                                               'content' => substr($token[1]04),
  1012.                                               'code'    => T_ELSE,
  1013.                                               'type'    => 'T_ELSE',
  1014.                                              );
  1015.  
  1016.                 $newStackPtr++;
  1017.                 $finalTokens[$newStackPtr= array(
  1018.                                               'content' => substr($token[1]4-2),
  1019.                                               'code'    => T_WHITESPACE,
  1020.                                               'type'    => 'T_WHITESPACE',
  1021.                                              );
  1022.  
  1023.                 $newStackPtr++;
  1024.                 $finalTokens[$newStackPtr= array(
  1025.                                               'content' => substr($token[1]-2),
  1026.                                               'code'    => T_IF,
  1027.                                               'type'    => 'T_IF',
  1028.                                              );
  1029.  
  1030.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1031.                     echo "\t\t* token $stackPtr changed from T_ELSEIF to T_ELSE/T_WHITESPACE/T_IF".PHP_EOL;
  1032.                 }
  1033.  
  1034.                 $newStackPtr++;
  1035.                 continue;
  1036.             }//end if
  1037.  
  1038.             /*
  1039.                 HHVM 3.5 and 3.6 tokenizes a hashbang line such as #!/usr/bin/php
  1040.                 as T_HASHBANG while PHP proper uses T_INLINE_HTML.
  1041.             */
  1042.  
  1043.             if ($tokenIsArray === true && token_name($token[0]=== 'T_HASHBANG'{
  1044.                 $finalTokens[$newStackPtr= array(
  1045.                                               'content' => $token[1],
  1046.                                               'code'    => T_INLINE_HTML,
  1047.                                               'type'    => 'T_INLINE_HTML',
  1048.                                              );
  1049.  
  1050.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1051.                     echo "\t\t* token $stackPtr changed from T_HASHBANG to T_INLINE_HTML".PHP_EOL;
  1052.                 }
  1053.  
  1054.                 $newStackPtr++;
  1055.                 continue;
  1056.             }//end if
  1057.  
  1058.             /*
  1059.                 If this token has newlines in its content, split each line up
  1060.                 and create a new token for each line. We do this so it's easier
  1061.                 to ascertain where errors occur on a line.
  1062.                 Note that $token[1] is the token's content.
  1063.             */
  1064.  
  1065.             if ($tokenIsArray === true && strpos($token[1]$this->eolChar!== false{
  1066.                 $tokenLines explode($this->eolChar$token[1]);
  1067.                 $numLines   count($tokenLines);
  1068.                 $newToken   = array(
  1069.                                'type'    => token_name($token[0]),
  1070.                                'code'    => $token[0],
  1071.                                'content' => '',
  1072.                               );
  1073.  
  1074.                 for ($i = 0; $i $numLines$i++{
  1075.                     $newToken['content'$tokenLines[$i];
  1076.                     if ($i === ($numLines - 1)) {
  1077.                         if ($tokenLines[$i=== ''{
  1078.                             break;
  1079.                         }
  1080.                     else {
  1081.                         $newToken['content'.= $this->eolChar;
  1082.                     }
  1083.  
  1084.                     $finalTokens[$newStackPtr$newToken;
  1085.                     $newStackPtr++;
  1086.                 }
  1087.             else {
  1088.                 if ($tokenIsArray === true && $token[0=== T_STRING{
  1089.                     // Some T_STRING tokens should remain that way
  1090.                     // due to their context.
  1091.                     $context = array(
  1092.                                 T_OBJECT_OPERATOR      => true,
  1093.                                 T_FUNCTION             => true,
  1094.                                 T_CLASS                => true,
  1095.                                 T_EXTENDS              => true,
  1096.                                 T_IMPLEMENTS           => true,
  1097.                                 T_NEW                  => true,
  1098.                                 T_CONST                => true,
  1099.                                 T_NS_SEPARATOR         => true,
  1100.                                 T_USE                  => true,
  1101.                                 T_NAMESPACE            => true,
  1102.                                 T_PAAMAYIM_NEKUDOTAYIM => true,
  1103.                                );
  1104.                     if (isset($context[$finalTokens[$lastNotEmptyToken]['code']]=== true{
  1105.                         // Special case for syntax like: return new self
  1106.                         // where self should not be a string.
  1107.                         if ($finalTokens[$lastNotEmptyToken]['code'=== T_NEW
  1108.                             && strtolower($token[1]=== 'self'
  1109.                         {
  1110.                             $finalTokens[$newStackPtr= array(
  1111.                                                           'content' => $token[1],
  1112.                                                           'code'    => T_SELF,
  1113.                                                           'type'    => 'T_SELF',
  1114.                                                          );
  1115.                         else {
  1116.                             $finalTokens[$newStackPtr= array(
  1117.                                                           'content' => $token[1],
  1118.                                                           'code'    => T_STRING,
  1119.                                                           'type'    => 'T_STRING',
  1120.                                                          );
  1121.                         }
  1122.  
  1123.                         $newStackPtr++;
  1124.                         continue;
  1125.                     }//end if
  1126.                 }//end if
  1127.  
  1128.                 $newToken = null;
  1129.                 if ($tokenIsArray === false{
  1130.                     if (isset(self::$resolveTokenCache[$token[0]]=== true{
  1131.                         $newToken = self::$resolveTokenCache[$token[0]];
  1132.                     }
  1133.                 else {
  1134.                     $cacheKey = null;
  1135.                     if ($token[0=== T_STRING{
  1136.                         $cacheKey strtolower($token[1]);
  1137.                     else if ($token[0!== T_CURLY_OPEN{
  1138.                         $cacheKey $token[0];
  1139.                     }
  1140.  
  1141.                     if ($cacheKey !== null && isset(self::$resolveTokenCache[$cacheKey]=== true{
  1142.                         $newToken            = self::$resolveTokenCache[$cacheKey];
  1143.                         $newToken['content'$token[1];
  1144.                     }
  1145.                 }
  1146.  
  1147.                 if ($newToken === null{
  1148.                     $newToken = self::standardiseToken($token);
  1149.                 }
  1150.  
  1151.                 // Convert colons that are actually the ELSE component of an
  1152.                 // inline IF statement.
  1153.                 if (empty($insideInlineIf=== false && $newToken['code'=== T_COLON{
  1154.                     array_pop($insideInlineIf);
  1155.                     $newToken['code'T_INLINE_ELSE;
  1156.                     $newToken['type''T_INLINE_ELSE';
  1157.                 }
  1158.  
  1159.                 // This is a special condition for T_ARRAY tokens used for
  1160.                 // type hinting function arguments as being arrays. We want to keep
  1161.                 // the parenthesis map clean, so let's tag these tokens as
  1162.                 // T_ARRAY_HINT.
  1163.                 if ($newToken['code'=== T_ARRAY{
  1164.                     for ($i $stackPtr$i $numTokens$i++{
  1165.                         if ($tokens[$i=== '('{
  1166.                             break;
  1167.                         else if ($tokens[$i][0=== T_VARIABLE{
  1168.                             $newToken['code'T_ARRAY_HINT;
  1169.                             $newToken['type''T_ARRAY_HINT';
  1170.                             break;
  1171.                         }
  1172.                     }
  1173.                 }
  1174.  
  1175.                 // This is a special case when checking PHP 5.5+ code in PHP < 5.5
  1176.                 // where "finally" should be T_FINALLY instead of T_STRING.
  1177.                 if ($newToken['code'=== T_STRING
  1178.                     && strtolower($newToken['content']=== 'finally'
  1179.                 {
  1180.                     $newToken['code'T_FINALLY;
  1181.                     $newToken['type''T_FINALLY';
  1182.                 }
  1183.  
  1184.                 // This is a special case for the PHP 5.5 classname::class syntax
  1185.                 // where "class" should be T_STRING instead of T_CLASS.
  1186.                 if (($newToken['code'=== T_CLASS
  1187.                     || $newToken['code'=== T_FUNCTION)
  1188.                     && $finalTokens[($newStackPtr - 1)]['code'=== T_DOUBLE_COLON
  1189.                 {
  1190.                     $newToken['code'= T_STRING;
  1191.                     $newToken['type''T_STRING';
  1192.                 }
  1193.  
  1194.                 // This is a special case for PHP 5.6 use function and use const
  1195.                 // where "function" and "const" should be T_STRING instead of T_FUNCTION
  1196.                 // and T_CONST.
  1197.                 if (($newToken['code'=== T_FUNCTION
  1198.                     || $newToken['code'=== T_CONST)
  1199.                     && $finalTokens[$lastNotEmptyToken]['code'=== T_USE
  1200.                 {
  1201.                     $newToken['code'= T_STRING;
  1202.                     $newToken['type''T_STRING';
  1203.                 }
  1204.  
  1205.                 // This is a special case for use groups in PHP 7+ where leaving
  1206.                 // the curly braces as their normal tokens would confuse
  1207.                 // the scope map and sniffs.
  1208.                 if ($newToken['code'=== T_OPEN_CURLY_BRACKET
  1209.                     && $finalTokens[$lastNotEmptyToken]['code'=== T_NS_SEPARATOR
  1210.                 {
  1211.                     $newToken['code'T_OPEN_USE_GROUP;
  1212.                     $newToken['type''T_OPEN_USE_GROUP';
  1213.                     $insideUseGroup   = true;
  1214.                 }
  1215.  
  1216.                 if ($insideUseGroup === true && $newToken['code'=== T_CLOSE_CURLY_BRACKET{
  1217.                     $newToken['code'T_CLOSE_USE_GROUP;
  1218.                     $newToken['type''T_CLOSE_USE_GROUP';
  1219.                     $insideUseGroup   = false;
  1220.                 }
  1221.  
  1222.                 $finalTokens[$newStackPtr$newToken;
  1223.                 $newStackPtr++;
  1224.             }//end if
  1225.         }//end for
  1226.  
  1227.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1228.             echo "\t*** END PHP TOKENIZING ***".PHP_EOL;
  1229.         }
  1230.  
  1231.         return $finalTokens;
  1232.  
  1233.     }//end tokenize()
  1234.  
  1235.  
  1236.     /**
  1237.      * Performs additional processing after main tokenizing.
  1238.      *
  1239.      * This additional processing checks for CASE statements that are using curly
  1240.      * braces for scope openers and closers. It also turns some T_FUNCTION tokens
  1241.      * into T_CLOSURE when they are not standard function definitions. It also
  1242.      * detects short array syntax and converts those square brackets into new tokens.
  1243.      * It also corrects some usage of the static and class keywords. It also
  1244.      * assigns tokens to function return types.
  1245.      *
  1246.      * @return void 
  1247.      */
  1248.     protected function processAdditional()
  1249.     {
  1250.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1251.             echo "\t*** START ADDITIONAL PHP PROCESSING ***".PHP_EOL;
  1252.         }
  1253.  
  1254.         $numTokens count($this->tokens);
  1255.         for ($i ($numTokens - 1)$i >= 0; $i--{
  1256.             // Check for any unset scope conditions due to alternate IF/ENDIF syntax.
  1257.             if (isset($this->tokens[$i]['scope_opener']=== true
  1258.                 && isset($this->tokens[$i]['scope_condition']=== false
  1259.             {
  1260.                 $this->tokens[$i]['scope_condition'$this->tokens[$this->tokens[$i]['scope_opener']]['scope_condition'];
  1261.             }
  1262.  
  1263.             if ($this->tokens[$i]['code'=== T_FUNCTION{
  1264.                 /*
  1265.                     Detect functions that are actually closures and
  1266.                     assign them a different token.
  1267.                 */
  1268.  
  1269.                 if (isset($this->tokens[$i]['scope_opener']=== true{
  1270.                     for ($x ($i + 1)$x $numTokens$x++{
  1271.                         if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false
  1272.                             && $this->tokens[$x]['code'!== T_BITWISE_AND
  1273.                         {
  1274.                             break;
  1275.                         }
  1276.                     }
  1277.  
  1278.                     if ($this->tokens[$x]['code'=== T_OPEN_PARENTHESIS{
  1279.                         $this->tokens[$i]['code'T_CLOSURE;
  1280.                         $this->tokens[$i]['type''T_CLOSURE';
  1281.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1282.                             $line $this->tokens[$i]['line'];
  1283.                             echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE".PHP_EOL;
  1284.                         }
  1285.  
  1286.                         for ($x ($this->tokens[$i]['scope_opener'+ 1)$x $this->tokens[$i]['scope_closer']$x++{
  1287.                             if (isset($this->tokens[$x]['conditions'][$i]=== false{
  1288.                                 continue;
  1289.                             }
  1290.  
  1291.                             $this->tokens[$x]['conditions'][$iT_CLOSURE;
  1292.                             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1293.                                 $type $this->tokens[$x]['type'];
  1294.                                 echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1295.                             }
  1296.                         }
  1297.                     }
  1298.  
  1299.                     $tokenAfterReturnTypeHint $this->tokens[$i]['scope_opener'];
  1300.                 else if (isset($this->tokens[$i]['parenthesis_closer']=== true{
  1301.                     $tokenAfterReturnTypeHint = null;
  1302.                     for ($x ($this->tokens[$i]['parenthesis_closer'+ 1)$x $numTokens$x++{
  1303.                         if ($this->tokens[$x]['code'=== T_SEMICOLON{
  1304.                             $tokenAfterReturnTypeHint $x;
  1305.                             break;
  1306.                         }
  1307.                     }
  1308.  
  1309.                     if ($tokenAfterReturnTypeHint === null{
  1310.                         // Probably a syntax error.
  1311.                         continue;
  1312.                     }
  1313.                 else {
  1314.                     // Probably a syntax error.
  1315.                     continue;
  1316.                 }//end if
  1317.  
  1318.                 /*
  1319.                     Detect function return values and assign them
  1320.                     a special token, because PHP doesn't.
  1321.                 */
  1322.  
  1323.                 for ($x ($tokenAfterReturnTypeHint - 1)$x $i$x--{
  1324.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1325.                         if (in_array($this->tokens[$x]['code']array(T_STRINGT_ARRAYT_ARRAY_HINTT_CALLABLET_SELFT_PARENT)true=== true{
  1326.                             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1327.                                 $line $this->tokens[$x]['line'];
  1328.                                 $type $this->tokens[$x]['type'];
  1329.                                 echo "\t* token $x on line $line changed from $type to T_RETURN_TYPE".PHP_EOL;
  1330.                             }
  1331.  
  1332.                             $this->tokens[$x]['code'T_RETURN_TYPE;
  1333.                             $this->tokens[$x]['type''T_RETURN_TYPE';
  1334.                         }
  1335.  
  1336.                         break;
  1337.                     }
  1338.                 }
  1339.  
  1340.                 continue;
  1341.             else if ($this->tokens[$i]['code'=== T_CLASS && isset($this->tokens[$i]['scope_opener']=== true{
  1342.                 /*
  1343.                     Detect anonymous classes and assign them a different token.
  1344.                 */
  1345.  
  1346.                 for ($x ($i + 1)$x $numTokens$x++{
  1347.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1348.                         break;
  1349.                     }
  1350.                 }
  1351.  
  1352.                 if ($this->tokens[$x]['code'=== T_OPEN_PARENTHESIS
  1353.                     || $this->tokens[$x]['code'=== T_OPEN_CURLY_BRACKET
  1354.                     || $this->tokens[$x]['code'=== T_EXTENDS
  1355.                     || $this->tokens[$x]['code'=== T_IMPLEMENTS
  1356.                 {
  1357.                     $this->tokens[$i]['code'T_ANON_CLASS;
  1358.                     $this->tokens[$i]['type''T_ANON_CLASS';
  1359.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1360.                         $line $this->tokens[$i]['line'];
  1361.                         echo "\t* token $i on line $line changed from T_CLASS to T_ANON_CLASS".PHP_EOL;
  1362.                     }
  1363.  
  1364.                     for ($x ($this->tokens[$i]['scope_opener'+ 1)$x $this->tokens[$i]['scope_closer']$x++{
  1365.                         if (isset($this->tokens[$x]['conditions'][$i]=== false{
  1366.                             continue;
  1367.                         }
  1368.  
  1369.                         $this->tokens[$x]['conditions'][$iT_ANON_CLASS;
  1370.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1371.                             $type $this->tokens[$x]['type'];
  1372.                             echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1373.                         }
  1374.                     }
  1375.                 }
  1376.  
  1377.                 continue;
  1378.             else if ($this->tokens[$i]['code'=== T_OPEN_SQUARE_BRACKET{
  1379.                 if (isset($this->tokens[$i]['bracket_closer']=== false{
  1380.                     continue;
  1381.                 }
  1382.  
  1383.                 // Unless there is a variable or a bracket before this token,
  1384.                 // it is the start of an array being defined using the short syntax.
  1385.                 $isShortArray = false;
  1386.                 $allowed      = array(
  1387.                                  T_CLOSE_SQUARE_BRACKET     => T_CLOSE_SQUARE_BRACKET,
  1388.                                  T_CLOSE_CURLY_BRACKET      => T_CLOSE_CURLY_BRACKET,
  1389.                                  T_CLOSE_PARENTHESIS        => T_CLOSE_PARENTHESIS,
  1390.                                  T_VARIABLE                 => T_VARIABLE,
  1391.                                  T_OBJECT_OPERATOR          => T_OBJECT_OPERATOR,
  1392.                                  T_STRING                   => T_STRING,
  1393.                                  T_CONSTANT_ENCAPSED_STRING => T_CONSTANT_ENCAPSED_STRING,
  1394.                                 );
  1395.  
  1396.                 for ($x ($i - 1)$x > 0; $x--{
  1397.                     // If we hit a scope opener, the statement has ended
  1398.                     // without finding anything, so it's probably an array
  1399.                     // using PHP 7.1 short list syntax.
  1400.                     if (isset($this->tokens[$x]['scope_opener']=== true{
  1401.                         $isShortArray = true;
  1402.                         break;
  1403.                     }
  1404.  
  1405.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1406.                         if (isset($allowed[$this->tokens[$x]['code']]=== false{
  1407.                             $isShortArray = true;
  1408.                         }
  1409.  
  1410.                         break;
  1411.                     }
  1412.                 }
  1413.  
  1414.                 if ($isShortArray === true{
  1415.                     $this->tokens[$i]['code'T_OPEN_SHORT_ARRAY;
  1416.                     $this->tokens[$i]['type''T_OPEN_SHORT_ARRAY';
  1417.  
  1418.                     $closer $this->tokens[$i]['bracket_closer'];
  1419.                     $this->tokens[$closer]['code'T_CLOSE_SHORT_ARRAY;
  1420.                     $this->tokens[$closer]['type''T_CLOSE_SHORT_ARRAY';
  1421.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1422.                         $line $this->tokens[$i]['line'];
  1423.                         echo "\t* token $i on line $line changed from T_OPEN_SQUARE_BRACKET to T_OPEN_SHORT_ARRAY".PHP_EOL;
  1424.                         $line $this->tokens[$closer]['line'];
  1425.                         echo "\t* token $closer on line $line changed from T_CLOSE_SQUARE_BRACKET to T_CLOSE_SHORT_ARRAY".PHP_EOL;
  1426.                     }
  1427.                 }
  1428.  
  1429.                 continue;
  1430.             else if ($this->tokens[$i]['code'=== T_STATIC{
  1431.                 for ($x ($i - 1)$x > 0; $x--{
  1432.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1433.                         break;
  1434.                     }
  1435.                 }
  1436.  
  1437.                 if ($this->tokens[$x]['code'=== T_INSTANCEOF{
  1438.                     $this->tokens[$i]['code'= T_STRING;
  1439.                     $this->tokens[$i]['type''T_STRING';
  1440.  
  1441.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1442.                         $line $this->tokens[$i]['line'];
  1443.                         echo "\t* token $i on line $line changed from T_STATIC to T_STRING".PHP_EOL;
  1444.                     }
  1445.                 }
  1446.  
  1447.                 continue;
  1448.             else if ($this->tokens[$i]['code'=== T_ECHO && $this->tokens[$i]['content'=== '<?='{
  1449.                 // HHVM tokenizes <?= as T_ECHO but it should be T_OPEN_TAG_WITH_ECHO.
  1450.                 $this->tokens[$i]['code'= T_OPEN_TAG_WITH_ECHO;
  1451.                 $this->tokens[$i]['type''T_OPEN_TAG_WITH_ECHO';
  1452.  
  1453.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1454.                     $line $this->tokens[$i]['line'];
  1455.                     echo "\t* token $i on line $line changed from T_ECHO to T_OPEN_TAG_WITH_ECHO".PHP_EOL;
  1456.                 }
  1457.             else if ($this->tokens[$i]['code'=== T_TRUE
  1458.                 || $this->tokens[$i]['code'=== T_FALSE
  1459.                 || $this->tokens[$i]['code'=== T_NULL
  1460.             {
  1461.                 for ($x ($i + 1)$i $numTokens$x++{
  1462.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1463.                         // Non-whitespace content.
  1464.                         break;
  1465.                     }
  1466.                 }
  1467.  
  1468.                 $context = array(
  1469.                             T_OBJECT_OPERATOR      => true,
  1470.                             T_NS_SEPARATOR         => true,
  1471.                             T_PAAMAYIM_NEKUDOTAYIM => true,
  1472.                            );
  1473.                 if (isset($context[$this->tokens[$x]['code']]=== true{
  1474.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1475.                         $line $this->tokens[$i]['line'];
  1476.                         $type $this->tokens[$i]['type'];
  1477.                         echo "\t* token $i on line $line changed from $type to T_STRING".PHP_EOL;
  1478.                     }
  1479.  
  1480.                     $this->tokens[$i]['code'= T_STRING;
  1481.                     $this->tokens[$i]['type''T_STRING';
  1482.                 }
  1483.             else if ($this->tokens[$i]['code'=== T_CONST{
  1484.                 // Context sensitive keywords support.
  1485.                 for ($x ($i + 1)$i $numTokens$x++{
  1486.                     if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1487.                         // Non-whitespace content.
  1488.                         break;
  1489.                     }
  1490.                 }
  1491.  
  1492.                 if ($this->tokens[$x]['code'!== T_STRING{
  1493.                     if (PHP_CODESNIFFER_VERBOSITY > 1{
  1494.                         $line $this->tokens[$x]['line'];
  1495.                         $type $this->tokens[$x]['type'];
  1496.                         echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL;
  1497.                     }
  1498.  
  1499.                     $this->tokens[$x]['code'= T_STRING;
  1500.                     $this->tokens[$x]['type''T_STRING';
  1501.                 }
  1502.             }//end if
  1503.  
  1504.             if (($this->tokens[$i]['code'!== T_CASE
  1505.                 && $this->tokens[$i]['code'!== T_DEFAULT)
  1506.                 || isset($this->tokens[$i]['scope_opener']=== false
  1507.             {
  1508.                 // Only interested in CASE and DEFAULT statements from here on in.
  1509.                 continue;
  1510.             }
  1511.  
  1512.             $scopeOpener $this->tokens[$i]['scope_opener'];
  1513.             $scopeCloser $this->tokens[$i]['scope_closer'];
  1514.  
  1515.             // If the first char after the opener is a curly brace
  1516.             // and that brace has been ignored, it is actually
  1517.             // opening this case statement and the opener and closer are
  1518.             // probably set incorrectly.
  1519.             for ($x ($scopeOpener + 1)$x $numTokens$x++{
  1520.                 if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]=== false{
  1521.                     // Non-whitespace content.
  1522.                     break;
  1523.                 }
  1524.             }
  1525.  
  1526.             if ($this->tokens[$x]['code'=== T_CASE || $this->tokens[$x]['code'=== T_DEFAULT{
  1527.                 // Special case for multiple CASE statements that share the same
  1528.                 // closer. Because we are going backwards through the file, this next
  1529.                 // CASE statement is already fixed, so just use its closer and don't
  1530.                 // worry about fixing anything.
  1531.                 $newCloser $this->tokens[$x]['scope_closer'];
  1532.                 $this->tokens[$i]['scope_closer'$newCloser;
  1533.                 if (PHP_CODESNIFFER_VERBOSITY > 1{
  1534.                     $oldType $this->tokens[$scopeCloser]['type'];
  1535.                     $newType $this->tokens[$newCloser]['type'];
  1536.                     $line    $this->tokens[$i]['line'];
  1537.                     echo "\t* token $i (T_CASE) on line $line closer changed from $scopeCloser ($oldType) to $newCloser ($newType)".PHP_EOL;
  1538.                 }
  1539.  
  1540.                 continue;
  1541.             }
  1542.  
  1543.             if ($this->tokens[$x]['code'!== T_OPEN_CURLY_BRACKET
  1544.                 || isset($this->tokens[$x]['scope_condition']=== true
  1545.             {
  1546.                 // Not a CASE/DEFAULT with a curly brace opener.
  1547.                 continue;
  1548.             }
  1549.  
  1550.             // The closer for this CASE/DEFAULT should be the closing curly brace and
  1551.             // not whatever it already is. The opener needs to be the opening curly
  1552.             // brace so everything matches up.
  1553.             $newCloser $this->tokens[$x]['bracket_closer'];
  1554.             foreach (array($i$x$newCloseras $index{
  1555.                 $this->tokens[$index]['scope_condition'$i;
  1556.                 $this->tokens[$index]['scope_opener']    $x;
  1557.                 $this->tokens[$index]['scope_closer']    $newCloser;
  1558.             }
  1559.  
  1560.             unset($this->tokens[$scopeOpener]['scope_condition']);
  1561.             unset($this->tokens[$scopeOpener]['scope_opener']);
  1562.             unset($this->tokens[$scopeOpener]['scope_closer']);
  1563.             unset($this->tokens[$scopeCloser]['scope_condition']);
  1564.             unset($this->tokens[$scopeCloser]['scope_opener']);
  1565.             unset($this->tokens[$scopeCloser]['scope_closer']);
  1566.             unset($this->tokens[$x]['bracket_opener']);
  1567.             unset($this->tokens[$x]['bracket_closer']);
  1568.             unset($this->tokens[$newCloser]['bracket_opener']);
  1569.             unset($this->tokens[$newCloser]['bracket_closer']);
  1570.             $this->tokens[$scopeCloser]['conditions'][$i;
  1571.  
  1572.             if (PHP_CODESNIFFER_VERBOSITY > 1{
  1573.                 $line      $this->tokens[$i]['line'];
  1574.                 $tokenType $this->tokens[$i]['type'];
  1575.  
  1576.                 $oldType $this->tokens[$scopeOpener]['type'];
  1577.                 $newType $this->tokens[$x]['type'];
  1578.                 echo "\t* token $i ($tokenType) on line $line opener changed from $scopeOpener ($oldType) to $x ($newType)".PHP_EOL;
  1579.  
  1580.                 $oldType $this->tokens[$scopeCloser]['type'];
  1581.                 $newType $this->tokens[$newCloser]['type'];
  1582.                 echo "\t* token $i ($tokenType) on line $line closer changed from $scopeCloser ($oldType) to $newCloser ($newType)".PHP_EOL;
  1583.             }
  1584.  
  1585.             // Now fix up all the tokens that think they are
  1586.             // inside the CASE/DEFAULT statement when they are really outside.
  1587.             for ($x $newCloser$x $scopeCloser$x++{
  1588.                 foreach ($this->tokens[$x]['conditions'as $num => $oldCond{
  1589.                     if ($oldCond === $this->tokens[$i]['code']{
  1590.                         $oldConditions $this->tokens[$x]['conditions'];
  1591.                         unset($this->tokens[$x]['conditions'][$num]);
  1592.  
  1593.                         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1594.                             $type     $this->tokens[$x]['type'];
  1595.                             $oldConds '';
  1596.                             foreach ($oldConditions as $condition{
  1597.                                 $oldConds .= token_name($condition).',';
  1598.                             }
  1599.  
  1600.                             $oldConds rtrim($oldConds',');
  1601.  
  1602.                             $newConds '';
  1603.                             foreach ($this->tokens[$x]['conditions'as $condition{
  1604.                                 $newConds .= token_name($condition).',';
  1605.                             }
  1606.  
  1607.                             $newConds rtrim($newConds',');
  1608.  
  1609.                             echo "\t\t* cleaned $x ($type) *".PHP_EOL;
  1610.                             echo "\t\t\t=> conditions changed from $oldConds to $newConds".PHP_EOL;
  1611.                         }
  1612.  
  1613.                         break;
  1614.                     }//end if
  1615.                 }//end foreach
  1616.             }//end for
  1617.         }//end for
  1618.  
  1619.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  1620.             echo "\t*** END ADDITIONAL PHP PROCESSING ***".PHP_EOL;
  1621.         }
  1622.  
  1623.     }//end processAdditional()
  1624.  
  1625.  
  1626.     /**
  1627.      * Takes a token produced from <code>token_get_all()</code> and produces a
  1628.      * more uniform token.
  1629.      *
  1630.      * @param string|array$token The token to convert.
  1631.      *
  1632.      * @return array The new token.
  1633.      */
  1634.     public static function standardiseToken($token)
  1635.     {
  1636.         if (isset($token[1]=== false{
  1637.             if (isset(self::$resolveTokenCache[$token[0]]=== true{
  1638.                 return self::$resolveTokenCache[$token[0]];
  1639.             }
  1640.         else {
  1641.             $cacheKey = null;
  1642.             if ($token[0=== T_STRING{
  1643.                 $cacheKey strtolower($token[1]);
  1644.             else if ($token[0!== T_CURLY_OPEN{
  1645.                 $cacheKey $token[0];
  1646.             }
  1647.  
  1648.             if ($cacheKey !== null && isset(self::$resolveTokenCache[$cacheKey]=== true{
  1649.                 $newToken            = self::$resolveTokenCache[$cacheKey];
  1650.                 $newToken['content'$token[1];
  1651.                 return $newToken;
  1652.             }
  1653.         }
  1654.  
  1655.         if (isset($token[1]=== false{
  1656.             return self::resolveSimpleToken($token[0]);
  1657.         }
  1658.  
  1659.         if ($token[0=== T_STRING{
  1660.             switch ($cacheKey{
  1661.             case 'false':
  1662.                 $newToken['type''T_FALSE';
  1663.                 break;
  1664.             case 'true':
  1665.                 $newToken['type''T_TRUE';
  1666.                 break;
  1667.             case 'null':
  1668.                 $newToken['type''T_NULL';
  1669.                 break;
  1670.             case 'self':
  1671.                 $newToken['type''T_SELF';
  1672.                 break;
  1673.             case 'parent':
  1674.                 $newToken['type''T_PARENT';
  1675.                 break;
  1676.             default:
  1677.                 $newToken['type''T_STRING';
  1678.                 break;
  1679.             }
  1680.  
  1681.             $newToken['code'constant($newToken['type']);
  1682.  
  1683.             self::$resolveTokenCache[$cacheKey$newToken;
  1684.         else if ($token[0=== T_CURLY_OPEN{
  1685.             $newToken = array(
  1686.                          'code' => T_OPEN_CURLY_BRACKET,
  1687.                          'type' => 'T_OPEN_CURLY_BRACKET',
  1688.                         );
  1689.         else {
  1690.             $newToken = array(
  1691.                          'code' => $token[0],
  1692.                          'type' => token_name($token[0]),
  1693.                         );
  1694.  
  1695.             self::$resolveTokenCache[$token[0]] $newToken;
  1696.         }//end if
  1697.  
  1698.         $newToken['content'$token[1];
  1699.         return $newToken;
  1700.  
  1701.     }//end standardiseToken()
  1702.  
  1703.  
  1704.     /**
  1705.      * Converts simple tokens into a format that conforms to complex tokens
  1706.      * produced by token_get_all().
  1707.      *
  1708.      * Simple tokens are tokens that are not in array form when produced from
  1709.      * token_get_all().
  1710.      *
  1711.      * @param string $token The simple token to convert.
  1712.      *
  1713.      * @return array The new token in array format.
  1714.      */
  1715.     public static function resolveSimpleToken($token)
  1716.     {
  1717.         $newToken = array();
  1718.  
  1719.         switch ($token{
  1720.         case '{':
  1721.             $newToken['type''T_OPEN_CURLY_BRACKET';
  1722.             break;
  1723.         case '}':
  1724.             $newToken['type''T_CLOSE_CURLY_BRACKET';
  1725.             break;
  1726.         case '[':
  1727.             $newToken['type''T_OPEN_SQUARE_BRACKET';
  1728.             break;
  1729.         case ']':
  1730.             $newToken['type''T_CLOSE_SQUARE_BRACKET';
  1731.             break;
  1732.         case '(':
  1733.             $newToken['type''T_OPEN_PARENTHESIS';
  1734.             break;
  1735.         case ')':
  1736.             $newToken['type''T_CLOSE_PARENTHESIS';
  1737.             break;
  1738.         case ':':
  1739.             $newToken['type''T_COLON';
  1740.             break;
  1741.         case '.':
  1742.             $newToken['type''T_STRING_CONCAT';
  1743.             break;
  1744.         case ';':
  1745.             $newToken['type''T_SEMICOLON';
  1746.             break;
  1747.         case '=':
  1748.             $newToken['type''T_EQUAL';
  1749.             break;
  1750.         case '*':
  1751.             $newToken['type''T_MULTIPLY';
  1752.             break;
  1753.         case '/':
  1754.             $newToken['type''T_DIVIDE';
  1755.             break;
  1756.         case '+':
  1757.             $newToken['type''T_PLUS';
  1758.             break;
  1759.         case '-':
  1760.             $newToken['type''T_MINUS';
  1761.             break;
  1762.         case '%':
  1763.             $newToken['type''T_MODULUS';
  1764.             break;
  1765.         case '^':
  1766.             $newToken['type''T_BITWISE_XOR';
  1767.             break;
  1768.         case '&':
  1769.             $newToken['type''T_BITWISE_AND';
  1770.             break;
  1771.         case '|':
  1772.             $newToken['type''T_BITWISE_OR';
  1773.             break;
  1774.         case '<':
  1775.             $newToken['type''T_LESS_THAN';
  1776.             break;
  1777.         case '>':
  1778.             $newToken['type''T_GREATER_THAN';
  1779.             break;
  1780.         case '!':
  1781.             $newToken['type''T_BOOLEAN_NOT';
  1782.             break;
  1783.         case ',':
  1784.             $newToken['type''T_COMMA';
  1785.             break;
  1786.         case '@':
  1787.             $newToken['type''T_ASPERAND';
  1788.             break;
  1789.         case '$':
  1790.             $newToken['type''T_DOLLAR';
  1791.             break;
  1792.         case '`':
  1793.             $newToken['type''T_BACKTICK';
  1794.             break;
  1795.         default:
  1796.             $newToken['type''T_NONE';
  1797.             break;
  1798.         }//end switch
  1799.  
  1800.         $newToken['code']    = constant($newToken['type']);
  1801.         $newToken['content'$token;
  1802.  
  1803.         self::$resolveTokenCache[$token$newToken;
  1804.         return $newToken;
  1805.  
  1806.     }//end resolveSimpleToken()
  1807.  
  1808.  
  1809. }//end class

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