comparison vendor/squizlabs/php_codesniffer/CodeSniffer/File.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
1537 if (str_replace("\t", '', $tokens[$i]['content']) === '') { 1537 if (str_replace("\t", '', $tokens[$i]['content']) === '') {
1538 // String only contains tabs, so we can shortcut the process. 1538 // String only contains tabs, so we can shortcut the process.
1539 $numTabs = strlen($tokens[$i]['content']); 1539 $numTabs = strlen($tokens[$i]['content']);
1540 1540
1541 $newContent = ''; 1541 $newContent = '';
1542 $firstTabSize = ($tabWidth - ($currColumn % $tabWidth) + 1); 1542 $firstTabSize = ($tabWidth - (($currColumn - 1) % $tabWidth));
1543 $length = ($firstTabSize + ($tabWidth * ($numTabs - 1))); 1543 $length = ($firstTabSize + ($tabWidth * ($numTabs - 1)));
1544 $currColumn += $length; 1544 $currColumn += $length;
1545 $newContent = str_repeat(' ', $length); 1545 $newContent = str_repeat(' ', $length);
1546 } else { 1546 } else {
1547 // We need to determine the length of each tab. 1547 // We need to determine the length of each tab.
2256 ) { 2256 ) {
2257 // We found a curly brace inside the condition of the 2257 // We found a curly brace inside the condition of the
2258 // current scope opener, so it must be a string offset. 2258 // current scope opener, so it must be a string offset.
2259 if (PHP_CODESNIFFER_VERBOSITY > 1) { 2259 if (PHP_CODESNIFFER_VERBOSITY > 1) {
2260 echo str_repeat("\t", $depth); 2260 echo str_repeat("\t", $depth);
2261 echo '* ignoring curly brace *'.PHP_EOL; 2261 echo '* ignoring curly brace inside condition *'.PHP_EOL;
2262 } 2262 }
2263 2263
2264 $ignore++; 2264 $ignore++;
2265 } else { 2265 } else {
2266 // Make sure this is actually an opener and not a 2266 // Make sure this is actually an opener and not a
2267 // string offset (e.g., $var{0}). 2267 // string offset (e.g., $var{0}).
2268 for ($x = ($i - 1); $x > 0; $x--) { 2268 for ($x = ($i - 1); $x > 0; $x--) {
2269 if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === true) { 2269 if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === true) {
2270 continue; 2270 continue;
2271 } else { 2271 } else {
2272 // If the first non-whitespace/comment token is a 2272 // If the first non-whitespace/comment token looks like this
2273 // variable or object operator then this is an opener 2273 // brace is a string offset, or this brace is mid-way through
2274 // for a string offset and not a scope. 2274 // a new statement, it isn't a scope opener.
2275 if ($tokens[$x]['code'] === T_VARIABLE 2275 $disallowed = PHP_CodeSniffer_Tokens::$assignmentTokens;
2276 || $tokens[$x]['code'] === T_OBJECT_OPERATOR 2276 $disallowed += array(
2277 ) { 2277 T_VARIABLE => true,
2278 T_OBJECT_OPERATOR => true,
2279 T_COMMA => true,
2280 T_OPEN_PARENTHESIS => true,
2281 );
2282
2283 if (isset($disallowed[$tokens[$x]['code']]) === true) {
2278 if (PHP_CODESNIFFER_VERBOSITY > 1) { 2284 if (PHP_CODESNIFFER_VERBOSITY > 1) {
2279 echo str_repeat("\t", $depth); 2285 echo str_repeat("\t", $depth);
2280 echo '* ignoring curly brace *'.PHP_EOL; 2286 echo '* ignoring curly brace after condition *'.PHP_EOL;
2281 } 2287 }
2282 2288
2283 $ignore++; 2289 $ignore++;
2284 }//end if 2290 }//end if
2285 2291
2651 2657
2652 /** 2658 /**
2653 * Returns the declaration names for classes, interfaces, and functions. 2659 * Returns the declaration names for classes, interfaces, and functions.
2654 * 2660 *
2655 * @param int $stackPtr The position of the declaration token which 2661 * @param int $stackPtr The position of the declaration token which
2656 * declared the class, interface or function. 2662 * declared the class, interface, trait or function.
2657 * 2663 *
2658 * @return string|null The name of the class, interface or function. 2664 * @return string|null The name of the class, interface or function.
2659 * or NULL if the function or class is anonymous. 2665 * or NULL if the function or class is anonymous.
2660 * @throws PHP_CodeSniffer_Exception If the specified token is not of type 2666 * @throws PHP_CodeSniffer_Exception If the specified token is not of type
2661 * T_FUNCTION, T_CLASS, T_ANON_CLASS, 2667 * T_FUNCTION, T_CLASS, T_ANON_CLASS,
2662 * or T_INTERFACE. 2668 * T_TRAIT or T_INTERFACE.
2663 */ 2669 */
2664 public function getDeclarationName($stackPtr) 2670 public function getDeclarationName($stackPtr)
2665 { 2671 {
2666 $tokenCode = $this->_tokens[$stackPtr]['code']; 2672 $tokenCode = $this->_tokens[$stackPtr]['code'];
2667 2673
2668 if ($tokenCode === T_ANON_CLASS) { 2674 if ($tokenCode === T_ANON_CLASS) {
2669 return null; 2675 return null;
2670 } 2676 }
2671 2677
2672 if ($tokenCode === T_FUNCTION 2678 if ($tokenCode === T_CLOSURE) {
2673 && $this->isAnonymousFunction($stackPtr) === true
2674 ) {
2675 return null; 2679 return null;
2676 } 2680 }
2677 2681
2678 if ($tokenCode !== T_FUNCTION 2682 if ($tokenCode !== T_FUNCTION
2679 && $tokenCode !== T_CLASS 2683 && $tokenCode !== T_CLASS
2750 * 0 => array( 2754 * 0 => array(
2751 * 'token' => int, // The position of the var in the token stack. 2755 * 'token' => int, // The position of the var in the token stack.
2752 * 'name' => '$var', // The variable name. 2756 * 'name' => '$var', // The variable name.
2753 * 'content' => string, // The full content of the variable definition. 2757 * 'content' => string, // The full content of the variable definition.
2754 * 'pass_by_reference' => boolean, // Is the variable passed by reference? 2758 * 'pass_by_reference' => boolean, // Is the variable passed by reference?
2759 * 'variable_length' => boolean, // Is the param of variable length through use of `...` ?
2755 * 'type_hint' => string, // The type hint for the variable. 2760 * 'type_hint' => string, // The type hint for the variable.
2756 * 'nullable_type' => boolean, // Is the variable using a nullable type? 2761 * 'nullable_type' => boolean, // Is the variable using a nullable type?
2757 * ) 2762 * )
2758 * </code> 2763 * </code>
2759 * 2764 *