comparison vendor/squizlabs/php_codesniffer/src/Files/File.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
25 * @var string 25 * @var string
26 */ 26 */
27 public $path = ''; 27 public $path = '';
28 28
29 /** 29 /**
30 * The absolute path to the file associated with this object. 30 * The content of the file.
31 * 31 *
32 * @var string 32 * @var string
33 */ 33 */
34 protected $content = ''; 34 protected $content = '';
35 35
390 $this->fixableCount = 0; 390 $this->fixableCount = 0;
391 return; 391 return;
392 } else if (substr($commentTextLower, 0, 9) === 'phpcs:set' 392 } else if (substr($commentTextLower, 0, 9) === 'phpcs:set'
393 || substr($commentTextLower, 0, 10) === '@phpcs:set' 393 || substr($commentTextLower, 0, 10) === '@phpcs:set'
394 ) { 394 ) {
395 // If the @phpcs: syntax is being used, strip the @ to make 395 if (isset($token['sniffCode']) === true) {
396 // comparisons easier. 396 $listenerCode = $token['sniffCode'];
397 if ($commentText[0] === '@') { 397 if (isset($this->ruleset->sniffCodes[$listenerCode]) === true) {
398 $commentText = substr($commentText, 1); 398 $propertyCode = $token['sniffProperty'];
399 } 399 $propertyValue = $token['sniffPropertyValue'];
400 400 $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
401 // Need to maintain case here, to get the correct sniff code. 401 $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
402 $parts = explode(' ', substr($commentText, 10));
403 if (count($parts) >= 2) {
404 $sniffParts = explode('.', $parts[0]);
405 if (count($sniffParts) >= 3) {
406 // If the sniff code is not known to us, it has not been registered in this run.
407 // But don't throw an error as it could be there for a different standard to use.
408 if (isset($this->ruleset->sniffCodes[$parts[0]]) === true) {
409 $listenerCode = array_shift($parts);
410 $propertyCode = array_shift($parts);
411 $propertyValue = rtrim(implode(' ', $parts), " */\r\n");
412 $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
413 $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
414 }
415 } 402 }
416 } 403 }
417 }//end if 404 }//end if
418 }//end if 405 }//end if
419 406
906 893
907 // Filter out any messages for sniffs that shouldn't have run 894 // Filter out any messages for sniffs that shouldn't have run
908 // due to the use of the --sniffs command line argument. 895 // due to the use of the --sniffs command line argument.
909 if ($includeAll === false 896 if ($includeAll === false
910 && ((empty($this->configCache['sniffs']) === false 897 && ((empty($this->configCache['sniffs']) === false
911 && in_array(strtolower($listenerCode), $this->configCache['sniffs']) === false) 898 && in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
912 || (empty($this->configCache['exclude']) === false 899 || (empty($this->configCache['exclude']) === false
913 && in_array(strtolower($listenerCode), $this->configCache['exclude']) === true)) 900 && in_array(strtolower($listenerCode), $this->configCache['exclude'], true) === true))
914 ) { 901 ) {
915 return false; 902 return false;
916 } 903 }
917 904
918 // If we know this sniff code is being ignored for this file, return early. 905 // If we know this sniff code is being ignored for this file, return early.
1129 public function getWarningCount() 1116 public function getWarningCount()
1130 { 1117 {
1131 return $this->warningCount; 1118 return $this->warningCount;
1132 1119
1133 }//end getWarningCount() 1120 }//end getWarningCount()
1134
1135
1136 /**
1137 * Returns the number of successes recorded.
1138 *
1139 * @return int
1140 */
1141 public function getSuccessCount()
1142 {
1143 return $this->successCount;
1144
1145 }//end getSuccessCount()
1146 1121
1147 1122
1148 /** 1123 /**
1149 * Returns the number of fixable errors/warnings raised. 1124 * Returns the number of fixable errors/warnings raised.
1150 * 1125 *
1989 * If a value is specified, the previous token of the specified type(s) 1964 * If a value is specified, the previous token of the specified type(s)
1990 * containing the specified value will be returned. 1965 * containing the specified value will be returned.
1991 * 1966 *
1992 * Returns false if no token can be found. 1967 * Returns false if no token can be found.
1993 * 1968 *
1994 * @param int|array $types The type(s) of tokens to search for. 1969 * @param int|string|array $types The type(s) of tokens to search for.
1995 * @param int $start The position to start searching from in the 1970 * @param int $start The position to start searching from in the
1996 * token stack. 1971 * token stack.
1997 * @param int $end The end position to fail if no token is found. 1972 * @param int $end The end position to fail if no token is found.
1998 * if not specified or null, end will default to 1973 * if not specified or null, end will default to
1999 * the start of the token stack. 1974 * the start of the token stack.
2000 * @param bool $exclude If true, find the previous token that is NOT of 1975 * @param bool $exclude If true, find the previous token that is NOT of
2001 * the types specified in $types. 1976 * the types specified in $types.
2002 * @param string $value The value that the token(s) must be equal to. 1977 * @param string $value The value that the token(s) must be equal to.
2003 * If value is omitted, tokens with any value will 1978 * If value is omitted, tokens with any value will
2004 * be returned. 1979 * be returned.
2005 * @param bool $local If true, tokens outside the current statement 1980 * @param bool $local If true, tokens outside the current statement
2006 * will not be checked. IE. checking will stop 1981 * will not be checked. IE. checking will stop
2007 * at the previous semi-colon found. 1982 * at the previous semi-colon found.
2008 * 1983 *
2009 * @return int|bool 1984 * @return int|bool
2010 * @see findNext() 1985 * @see findNext()
2011 */ 1986 */
2012 public function findPrevious( 1987 public function findPrevious(
2070 * If a value is specified, the next token of the specified type(s) 2045 * If a value is specified, the next token of the specified type(s)
2071 * containing the specified value will be returned. 2046 * containing the specified value will be returned.
2072 * 2047 *
2073 * Returns false if no token can be found. 2048 * Returns false if no token can be found.
2074 * 2049 *
2075 * @param int|array $types The type(s) of tokens to search for. 2050 * @param int|string|array $types The type(s) of tokens to search for.
2076 * @param int $start The position to start searching from in the 2051 * @param int $start The position to start searching from in the
2077 * token stack. 2052 * token stack.
2078 * @param int $end The end position to fail if no token is found. 2053 * @param int $end The end position to fail if no token is found.
2079 * if not specified or null, end will default to 2054 * if not specified or null, end will default to
2080 * the end of the token stack. 2055 * the end of the token stack.
2081 * @param bool $exclude If true, find the next token that is NOT of 2056 * @param bool $exclude If true, find the next token that is NOT of
2082 * a type specified in $types. 2057 * a type specified in $types.
2083 * @param string $value The value that the token(s) must be equal to. 2058 * @param string $value The value that the token(s) must be equal to.
2084 * If value is omitted, tokens with any value will 2059 * If value is omitted, tokens with any value will
2085 * be returned. 2060 * be returned.
2086 * @param bool $local If true, tokens outside the current statement 2061 * @param bool $local If true, tokens outside the current statement
2087 * will not be checked. i.e., checking will stop 2062 * will not be checked. i.e., checking will stop
2088 * at the next semi-colon found. 2063 * at the next semi-colon found.
2089 * 2064 *
2090 * @return int|bool 2065 * @return int|bool
2091 * @see findPrevious() 2066 * @see findPrevious()
2092 */ 2067 */
2093 public function findNext( 2068 public function findNext(
2152 $endTokens[T_OPEN_SHORT_ARRAY] = true; 2127 $endTokens[T_OPEN_SHORT_ARRAY] = true;
2153 2128
2154 if ($ignore !== null) { 2129 if ($ignore !== null) {
2155 $ignore = (array) $ignore; 2130 $ignore = (array) $ignore;
2156 foreach ($ignore as $code) { 2131 foreach ($ignore as $code) {
2157 if (isset($endTokens[$code]) === true) { 2132 unset($endTokens[$code]);
2158 unset($endTokens[$code]);
2159 }
2160 } 2133 }
2161 } 2134 }
2162 2135
2163 $lastNotEmpty = $start; 2136 $lastNotEmpty = $start;
2164 2137
2220 ]; 2193 ];
2221 2194
2222 if ($ignore !== null) { 2195 if ($ignore !== null) {
2223 $ignore = (array) $ignore; 2196 $ignore = (array) $ignore;
2224 foreach ($ignore as $code) { 2197 foreach ($ignore as $code) {
2225 if (isset($endTokens[$code]) === true) { 2198 unset($endTokens[$code]);
2226 unset($endTokens[$code]);
2227 }
2228 } 2199 }
2229 } 2200 }
2230 2201
2231 $lastNotEmpty = $start; 2202 $lastNotEmpty = $start;
2232 2203
2279 /** 2250 /**
2280 * Returns the position of the first token on a line, matching given type. 2251 * Returns the position of the first token on a line, matching given type.
2281 * 2252 *
2282 * Returns false if no token can be found. 2253 * Returns false if no token can be found.
2283 * 2254 *
2284 * @param int|array $types The type(s) of tokens to search for. 2255 * @param int|string|array $types The type(s) of tokens to search for.
2285 * @param int $start The position to start searching from in the 2256 * @param int $start The position to start searching from in the
2286 * token stack. The first token matching on 2257 * token stack. The first token matching on
2287 * this line before this token will be returned. 2258 * this line before this token will be returned.
2288 * @param bool $exclude If true, find the token that is NOT of 2259 * @param bool $exclude If true, find the token that is NOT of
2289 * the types specified in $types. 2260 * the types specified in $types.
2290 * @param string $value The value that the token must be equal to. 2261 * @param string $value The value that the token must be equal to.
2291 * If value is omitted, tokens with any value will 2262 * If value is omitted, tokens with any value will
2292 * be returned. 2263 * be returned.
2293 * 2264 *
2294 * @return int | bool 2265 * @return int | bool
2295 */ 2266 */
2296 public function findFirstOnLine($types, $start, $exclude=false, $value=null) 2267 public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2297 { 2268 {
2336 2307
2337 2308
2338 /** 2309 /**
2339 * Determine if the passed token has a condition of one of the passed types. 2310 * Determine if the passed token has a condition of one of the passed types.
2340 * 2311 *
2341 * @param int $stackPtr The position of the token we are checking. 2312 * @param int $stackPtr The position of the token we are checking.
2342 * @param int|array $types The type(s) of tokens to search for. 2313 * @param int|string|array $types The type(s) of tokens to search for.
2343 * 2314 *
2344 * @return boolean 2315 * @return boolean
2345 */ 2316 */
2346 public function hasCondition($stackPtr, $types) 2317 public function hasCondition($stackPtr, $types)
2347 { 2318 {
2357 2328
2358 $types = (array) $types; 2329 $types = (array) $types;
2359 $conditions = $this->tokens[$stackPtr]['conditions']; 2330 $conditions = $this->tokens[$stackPtr]['conditions'];
2360 2331
2361 foreach ($types as $type) { 2332 foreach ($types as $type) {
2362 if (in_array($type, $conditions) === true) { 2333 if (in_array($type, $conditions, true) === true) {
2363 // We found a token with the required type. 2334 // We found a token with the required type.
2364 return true; 2335 return true;
2365 } 2336 }
2366 } 2337 }
2367 2338
2373 /** 2344 /**
2374 * Return the position of the condition for the passed token. 2345 * Return the position of the condition for the passed token.
2375 * 2346 *
2376 * Returns FALSE if the token does not have the condition. 2347 * Returns FALSE if the token does not have the condition.
2377 * 2348 *
2378 * @param int $stackPtr The position of the token we are checking. 2349 * @param int $stackPtr The position of the token we are checking.
2379 * @param int $type The type of token to search for. 2350 * @param int|string $type The type of token to search for.
2380 * 2351 *
2381 * @return int 2352 * @return int
2382 */ 2353 */
2383 public function getCondition($stackPtr, $type) 2354 public function getCondition($stackPtr, $type)
2384 { 2355 {