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

Documentation generated on Mon, 11 Mar 2019 15:27:42 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.