@@ -890,26 +890,26 @@ |
||
890 | 890 | $nestedBraces = 0; |
891 | 891 | for ($start = $from; $start >= 0; $start--) { |
892 | 892 | switch ($pattern[$start]) { |
893 | - case '(': |
|
894 | - if ($nestedParenthesis === 0) { |
|
895 | - $skip['to'] = 'parenthesis_closer'; |
|
896 | - } |
|
893 | + case '(': |
|
894 | + if ($nestedParenthesis === 0) { |
|
895 | + $skip['to'] = 'parenthesis_closer'; |
|
896 | + } |
|
897 | 897 | |
898 | - $nestedParenthesis--; |
|
899 | - break; |
|
900 | - case '{': |
|
901 | - if ($nestedBraces === 0) { |
|
902 | - $skip['to'] = 'scope_closer'; |
|
903 | - } |
|
898 | + $nestedParenthesis--; |
|
899 | + break; |
|
900 | + case '{': |
|
901 | + if ($nestedBraces === 0) { |
|
902 | + $skip['to'] = 'scope_closer'; |
|
903 | + } |
|
904 | 904 | |
905 | - $nestedBraces--; |
|
906 | - break; |
|
907 | - case '}': |
|
908 | - $nestedBraces++; |
|
909 | - break; |
|
910 | - case ')': |
|
911 | - $nestedParenthesis++; |
|
912 | - break; |
|
905 | + $nestedBraces--; |
|
906 | + break; |
|
907 | + case '}': |
|
908 | + $nestedBraces++; |
|
909 | + break; |
|
910 | + case ')': |
|
911 | + $nestedParenthesis++; |
|
912 | + break; |
|
913 | 913 | }//end switch |
914 | 914 | |
915 | 915 | if (isset($skip['to']) === true) { |
@@ -1209,88 +1209,88 @@ discard block |
||
1209 | 1209 | } |
1210 | 1210 | |
1211 | 1211 | switch ($this->tokens[$i]['code']) { |
1212 | - case T_BITWISE_AND: |
|
1213 | - $passByReference = true; |
|
1214 | - break; |
|
1215 | - case T_VARIABLE: |
|
1216 | - $currVar = $i; |
|
1217 | - break; |
|
1218 | - case T_ELLIPSIS: |
|
1219 | - $variableLength = true; |
|
1220 | - break; |
|
1221 | - case T_ARRAY_HINT: |
|
1222 | - case T_CALLABLE: |
|
1223 | - $typeHint = $this->tokens[$i]['content']; |
|
1224 | - break; |
|
1225 | - case T_STRING: |
|
1226 | - // This is a string, so it may be a type hint, but it could |
|
1227 | - // also be a constant used as a default value. |
|
1228 | - $prevComma = false; |
|
1229 | - for ($t = $i; $t >= $opener; $t--) { |
|
1230 | - if ($this->tokens[$t]['code'] === T_COMMA) { |
|
1231 | - $prevComma = $t; |
|
1232 | - break; |
|
1212 | + case T_BITWISE_AND: |
|
1213 | + $passByReference = true; |
|
1214 | + break; |
|
1215 | + case T_VARIABLE: |
|
1216 | + $currVar = $i; |
|
1217 | + break; |
|
1218 | + case T_ELLIPSIS: |
|
1219 | + $variableLength = true; |
|
1220 | + break; |
|
1221 | + case T_ARRAY_HINT: |
|
1222 | + case T_CALLABLE: |
|
1223 | + $typeHint = $this->tokens[$i]['content']; |
|
1224 | + break; |
|
1225 | + case T_STRING: |
|
1226 | + // This is a string, so it may be a type hint, but it could |
|
1227 | + // also be a constant used as a default value. |
|
1228 | + $prevComma = false; |
|
1229 | + for ($t = $i; $t >= $opener; $t--) { |
|
1230 | + if ($this->tokens[$t]['code'] === T_COMMA) { |
|
1231 | + $prevComma = $t; |
|
1232 | + break; |
|
1233 | + } |
|
1233 | 1234 | } |
1234 | - } |
|
1235 | 1235 | |
1236 | - if ($prevComma !== false) { |
|
1237 | - $nextEquals = false; |
|
1238 | - for ($t = $prevComma; $t < $i; $t++) { |
|
1239 | - if ($this->tokens[$t]['code'] === T_EQUAL) { |
|
1240 | - $nextEquals = $t; |
|
1236 | + if ($prevComma !== false) { |
|
1237 | + $nextEquals = false; |
|
1238 | + for ($t = $prevComma; $t < $i; $t++) { |
|
1239 | + if ($this->tokens[$t]['code'] === T_EQUAL) { |
|
1240 | + $nextEquals = $t; |
|
1241 | + break; |
|
1242 | + } |
|
1243 | + } |
|
1244 | + |
|
1245 | + if ($nextEquals !== false) { |
|
1241 | 1246 | break; |
1242 | 1247 | } |
1243 | 1248 | } |
1244 | 1249 | |
1245 | - if ($nextEquals !== false) { |
|
1246 | - break; |
|
1250 | + if ($defaultStart === null) { |
|
1251 | + $typeHint .= $this->tokens[$i]['content']; |
|
1252 | + } |
|
1253 | + break; |
|
1254 | + case T_NS_SEPARATOR: |
|
1255 | + // Part of a type hint or default value. |
|
1256 | + if ($defaultStart === null) { |
|
1257 | + $typeHint .= $this->tokens[$i]['content']; |
|
1258 | + } |
|
1259 | + break; |
|
1260 | + case T_CLOSE_PARENTHESIS: |
|
1261 | + case T_COMMA: |
|
1262 | + // If it's null, then there must be no parameters for this |
|
1263 | + // method. |
|
1264 | + if ($currVar === null) { |
|
1265 | + continue; |
|
1247 | 1266 | } |
1248 | - } |
|
1249 | - |
|
1250 | - if ($defaultStart === null) { |
|
1251 | - $typeHint .= $this->tokens[$i]['content']; |
|
1252 | - } |
|
1253 | - break; |
|
1254 | - case T_NS_SEPARATOR: |
|
1255 | - // Part of a type hint or default value. |
|
1256 | - if ($defaultStart === null) { |
|
1257 | - $typeHint .= $this->tokens[$i]['content']; |
|
1258 | - } |
|
1259 | - break; |
|
1260 | - case T_CLOSE_PARENTHESIS: |
|
1261 | - case T_COMMA: |
|
1262 | - // If it's null, then there must be no parameters for this |
|
1263 | - // method. |
|
1264 | - if ($currVar === null) { |
|
1265 | - continue; |
|
1266 | - } |
|
1267 | 1267 | |
1268 | - $vars[$paramCount] = array(); |
|
1269 | - $vars[$paramCount]['name'] = $this->tokens[$currVar]['content']; |
|
1268 | + $vars[$paramCount] = array(); |
|
1269 | + $vars[$paramCount]['name'] = $this->tokens[$currVar]['content']; |
|
1270 | 1270 | |
1271 | - if ($defaultStart !== null) { |
|
1272 | - $vars[$paramCount]['default'] |
|
1273 | - = $this->getTokensAsString( |
|
1274 | - $defaultStart, |
|
1275 | - ($i - $defaultStart) |
|
1276 | - ); |
|
1277 | - } |
|
1271 | + if ($defaultStart !== null) { |
|
1272 | + $vars[$paramCount]['default'] |
|
1273 | + = $this->getTokensAsString( |
|
1274 | + $defaultStart, |
|
1275 | + ($i - $defaultStart) |
|
1276 | + ); |
|
1277 | + } |
|
1278 | 1278 | |
1279 | - $vars[$paramCount]['pass_by_reference'] = $passByReference; |
|
1280 | - $vars[$paramCount]['variable_length'] = $variableLength; |
|
1281 | - $vars[$paramCount]['type_hint'] = $typeHint; |
|
1279 | + $vars[$paramCount]['pass_by_reference'] = $passByReference; |
|
1280 | + $vars[$paramCount]['variable_length'] = $variableLength; |
|
1281 | + $vars[$paramCount]['type_hint'] = $typeHint; |
|
1282 | 1282 | |
1283 | - // Reset the vars, as we are about to process the next parameter. |
|
1284 | - $defaultStart = null; |
|
1285 | - $passByReference = false; |
|
1286 | - $variableLength = false; |
|
1287 | - $typeHint = ''; |
|
1283 | + // Reset the vars, as we are about to process the next parameter. |
|
1284 | + $defaultStart = null; |
|
1285 | + $passByReference = false; |
|
1286 | + $variableLength = false; |
|
1287 | + $typeHint = ''; |
|
1288 | 1288 | |
1289 | - $paramCount++; |
|
1290 | - break; |
|
1291 | - case T_EQUAL: |
|
1292 | - $defaultStart = ($i + 1); |
|
1293 | - break; |
|
1289 | + $paramCount++; |
|
1290 | + break; |
|
1291 | + case T_EQUAL: |
|
1292 | + $defaultStart = ($i + 1); |
|
1293 | + break; |
|
1294 | 1294 | }//end switch |
1295 | 1295 | }//end for |
1296 | 1296 | |
@@ -1352,27 +1352,27 @@ discard block |
||
1352 | 1352 | } |
1353 | 1353 | |
1354 | 1354 | switch ($this->tokens[$i]['code']) { |
1355 | - case T_PUBLIC: |
|
1356 | - $scope = 'public'; |
|
1357 | - $scopeSpecified = true; |
|
1358 | - break; |
|
1359 | - case T_PRIVATE: |
|
1360 | - $scope = 'private'; |
|
1361 | - $scopeSpecified = true; |
|
1362 | - break; |
|
1363 | - case T_PROTECTED: |
|
1364 | - $scope = 'protected'; |
|
1365 | - $scopeSpecified = true; |
|
1366 | - break; |
|
1367 | - case T_ABSTRACT: |
|
1368 | - $isAbstract = true; |
|
1369 | - break; |
|
1370 | - case T_FINAL: |
|
1371 | - $isFinal = true; |
|
1372 | - break; |
|
1373 | - case T_STATIC: |
|
1374 | - $isStatic = true; |
|
1375 | - break; |
|
1355 | + case T_PUBLIC: |
|
1356 | + $scope = 'public'; |
|
1357 | + $scopeSpecified = true; |
|
1358 | + break; |
|
1359 | + case T_PRIVATE: |
|
1360 | + $scope = 'private'; |
|
1361 | + $scopeSpecified = true; |
|
1362 | + break; |
|
1363 | + case T_PROTECTED: |
|
1364 | + $scope = 'protected'; |
|
1365 | + $scopeSpecified = true; |
|
1366 | + break; |
|
1367 | + case T_ABSTRACT: |
|
1368 | + $isAbstract = true; |
|
1369 | + break; |
|
1370 | + case T_FINAL: |
|
1371 | + $isFinal = true; |
|
1372 | + break; |
|
1373 | + case T_STATIC: |
|
1374 | + $isStatic = true; |
|
1375 | + break; |
|
1376 | 1376 | }//end switch |
1377 | 1377 | }//end for |
1378 | 1378 | |
@@ -1462,21 +1462,21 @@ discard block |
||
1462 | 1462 | } |
1463 | 1463 | |
1464 | 1464 | switch ($this->tokens[$i]['code']) { |
1465 | - case T_PUBLIC: |
|
1466 | - $scope = 'public'; |
|
1467 | - $scopeSpecified = true; |
|
1468 | - break; |
|
1469 | - case T_PRIVATE: |
|
1470 | - $scope = 'private'; |
|
1471 | - $scopeSpecified = true; |
|
1472 | - break; |
|
1473 | - case T_PROTECTED: |
|
1474 | - $scope = 'protected'; |
|
1475 | - $scopeSpecified = true; |
|
1476 | - break; |
|
1477 | - case T_STATIC: |
|
1478 | - $isStatic = true; |
|
1479 | - break; |
|
1465 | + case T_PUBLIC: |
|
1466 | + $scope = 'public'; |
|
1467 | + $scopeSpecified = true; |
|
1468 | + break; |
|
1469 | + case T_PRIVATE: |
|
1470 | + $scope = 'private'; |
|
1471 | + $scopeSpecified = true; |
|
1472 | + break; |
|
1473 | + case T_PROTECTED: |
|
1474 | + $scope = 'protected'; |
|
1475 | + $scopeSpecified = true; |
|
1476 | + break; |
|
1477 | + case T_STATIC: |
|
1478 | + $isStatic = true; |
|
1479 | + break; |
|
1480 | 1480 | } |
1481 | 1481 | }//end for |
1482 | 1482 | |
@@ -1530,13 +1530,13 @@ discard block |
||
1530 | 1530 | } |
1531 | 1531 | |
1532 | 1532 | switch ($this->tokens[$i]['code']) { |
1533 | - case T_ABSTRACT: |
|
1534 | - $isAbstract = true; |
|
1535 | - break; |
|
1533 | + case T_ABSTRACT: |
|
1534 | + $isAbstract = true; |
|
1535 | + break; |
|
1536 | 1536 | |
1537 | - case T_FINAL: |
|
1538 | - $isFinal = true; |
|
1539 | - break; |
|
1537 | + case T_FINAL: |
|
1538 | + $isFinal = true; |
|
1539 | + break; |
|
1540 | 1540 | } |
1541 | 1541 | }//end for |
1542 | 1542 |
@@ -607,19 +607,19 @@ |
||
607 | 607 | $input = trim($input); |
608 | 608 | |
609 | 609 | switch ($input) { |
610 | - case 's': |
|
611 | - break(2); |
|
612 | - case 'q': |
|
613 | - exit(0); |
|
614 | - default: |
|
615 | - // Repopulate the sniffs because some of them save their state |
|
616 | - // and only clear it when the file changes, but we are rechecking |
|
617 | - // the same file. |
|
618 | - $file->ruleset->populateTokenListeners(); |
|
619 | - $file->reloadContent(); |
|
620 | - $file->process(); |
|
621 | - $this->reporter->cacheFileReport($file, $this->config); |
|
622 | - break; |
|
610 | + case 's': |
|
611 | + break(2); |
|
612 | + case 'q': |
|
613 | + exit(0); |
|
614 | + default: |
|
615 | + // Repopulate the sniffs because some of them save their state |
|
616 | + // and only clear it when the file changes, but we are rechecking |
|
617 | + // the same file. |
|
618 | + $file->ruleset->populateTokenListeners(); |
|
619 | + $file->reloadContent(); |
|
620 | + $file->process(); |
|
621 | + $this->reporter->cacheFileReport($file, $this->config); |
|
622 | + break; |
|
623 | 623 | } |
624 | 624 | }//end while |
625 | 625 | }//end if |
@@ -343,15 +343,15 @@ |
||
343 | 343 | } else { |
344 | 344 | $lowerVarType = strtolower($varType); |
345 | 345 | switch ($lowerVarType) { |
346 | - case 'bool': |
|
347 | - return 'boolean'; |
|
348 | - case 'double': |
|
349 | - case 'real': |
|
350 | - return 'float'; |
|
351 | - case 'int': |
|
352 | - return 'integer'; |
|
353 | - case 'array()': |
|
354 | - return 'array'; |
|
346 | + case 'bool': |
|
347 | + return 'boolean'; |
|
348 | + case 'double': |
|
349 | + case 'real': |
|
350 | + return 'float'; |
|
351 | + case 'int': |
|
352 | + return 'integer'; |
|
353 | + case 'array()': |
|
354 | + return 'array'; |
|
355 | 355 | }//end switch |
356 | 356 | |
357 | 357 | if (strpos($lowerVarType, 'array(') !== false) { |
@@ -283,14 +283,14 @@ |
||
283 | 283 | foreach ($diffLines as $line) { |
284 | 284 | if (isset($line[0]) === true) { |
285 | 285 | switch ($line[0]) { |
286 | - case '-': |
|
287 | - $diff[] = "\033[31m$line\033[0m"; |
|
288 | - break; |
|
289 | - case '+': |
|
290 | - $diff[] = "\033[32m$line\033[0m"; |
|
291 | - break; |
|
292 | - default: |
|
293 | - $diff[] = $line; |
|
286 | + case '-': |
|
287 | + $diff[] = "\033[31m$line\033[0m"; |
|
288 | + break; |
|
289 | + case '+': |
|
290 | + $diff[] = "\033[32m$line\033[0m"; |
|
291 | + break; |
|
292 | + default: |
|
293 | + $diff[] = $line; |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |
@@ -204,35 +204,35 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | switch ($name) { |
207 | - case 'reportWidth' : |
|
208 | - // Support auto terminal width. |
|
209 | - if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) { |
|
210 | - $value = (int) $matches[1]; |
|
211 | - } else { |
|
212 | - $value = (int) $value; |
|
213 | - } |
|
214 | - break; |
|
215 | - case 'standards' : |
|
216 | - $cleaned = array(); |
|
217 | - |
|
218 | - // Check if the standard name is valid, or if the case is invalid. |
|
219 | - $installedStandards = Util\Standards::getInstalledStandards(); |
|
220 | - foreach ($value as $standard) { |
|
221 | - foreach ($installedStandards as $validStandard) { |
|
222 | - if (strtolower($standard) === strtolower($validStandard)) { |
|
223 | - $standard = $validStandard; |
|
224 | - break; |
|
225 | - } |
|
207 | + case 'reportWidth' : |
|
208 | + // Support auto terminal width. |
|
209 | + if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) { |
|
210 | + $value = (int) $matches[1]; |
|
211 | + } else { |
|
212 | + $value = (int) $value; |
|
226 | 213 | } |
214 | + break; |
|
215 | + case 'standards' : |
|
216 | + $cleaned = array(); |
|
217 | + |
|
218 | + // Check if the standard name is valid, or if the case is invalid. |
|
219 | + $installedStandards = Util\Standards::getInstalledStandards(); |
|
220 | + foreach ($value as $standard) { |
|
221 | + foreach ($installedStandards as $validStandard) { |
|
222 | + if (strtolower($standard) === strtolower($validStandard)) { |
|
223 | + $standard = $validStandard; |
|
224 | + break; |
|
225 | + } |
|
226 | + } |
|
227 | 227 | |
228 | - $cleaned[] = $standard; |
|
229 | - } |
|
228 | + $cleaned[] = $standard; |
|
229 | + } |
|
230 | 230 | |
231 | - $value = $cleaned; |
|
232 | - break; |
|
233 | - default : |
|
234 | - // No validation required. |
|
235 | - break; |
|
231 | + $value = $cleaned; |
|
232 | + break; |
|
233 | + default : |
|
234 | + // No validation required. |
|
235 | + break; |
|
236 | 236 | }//end switch |
237 | 237 | |
238 | 238 | $this->settings[$name] = $value; |
@@ -523,68 +523,68 @@ discard block |
||
523 | 523 | public function processShortArgument($arg, $pos) |
524 | 524 | { |
525 | 525 | switch ($arg) { |
526 | - case 'h': |
|
527 | - case '?': |
|
528 | - $this->printUsage(); |
|
529 | - exit(0); |
|
530 | - case 'i' : |
|
531 | - Util\Standards::printInstalledStandards(); |
|
532 | - exit(0); |
|
533 | - case 'v' : |
|
534 | - $this->verbosity++; |
|
535 | - $this->overriddenDefaults['verbosity'] = true; |
|
536 | - break; |
|
537 | - case 'l' : |
|
538 | - $this->local = true; |
|
539 | - $this->overriddenDefaults['local'] = true; |
|
540 | - break; |
|
541 | - case 's' : |
|
542 | - $this->showSources = true; |
|
543 | - $this->overriddenDefaults['showSources'] = true; |
|
544 | - break; |
|
545 | - case 'a' : |
|
546 | - $this->interactive = true; |
|
547 | - $this->overriddenDefaults['interactive'] = true; |
|
548 | - break; |
|
549 | - case 'e': |
|
550 | - $this->explain = true; |
|
551 | - $this->overriddenDefaults['explain'] = true; |
|
552 | - break; |
|
553 | - case 'p' : |
|
554 | - $this->showProgress = true; |
|
555 | - $this->overriddenDefaults['showProgress'] = true; |
|
556 | - break; |
|
557 | - case 'm' : |
|
558 | - $this->recordErrors = false; |
|
559 | - $this->overriddenDefaults['recordErrors'] = true; |
|
560 | - break; |
|
561 | - case 'd' : |
|
562 | - $ini = explode('=', $this->cliArgs[($pos + 1)]); |
|
563 | - $this->cliArgs[($pos + 1)] = ''; |
|
564 | - if (isset($ini[1]) === true) { |
|
565 | - ini_set($ini[0], $ini[1]); |
|
566 | - } else { |
|
567 | - ini_set($ini[0], true); |
|
568 | - } |
|
569 | - break; |
|
570 | - case 'n' : |
|
571 | - if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
572 | - $this->warningSeverity = 0; |
|
573 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
574 | - } |
|
575 | - break; |
|
576 | - case 'w' : |
|
577 | - if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
578 | - $this->warningSeverity = $this->errorSeverity; |
|
579 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
580 | - } |
|
581 | - break; |
|
582 | - default: |
|
583 | - if ($this->dieOnUnknownArg === false) { |
|
584 | - $this->values[$arg] = $arg; |
|
585 | - } else { |
|
586 | - $this->processUnknownArgument('-'.$arg, $pos); |
|
587 | - } |
|
526 | + case 'h': |
|
527 | + case '?': |
|
528 | + $this->printUsage(); |
|
529 | + exit(0); |
|
530 | + case 'i' : |
|
531 | + Util\Standards::printInstalledStandards(); |
|
532 | + exit(0); |
|
533 | + case 'v' : |
|
534 | + $this->verbosity++; |
|
535 | + $this->overriddenDefaults['verbosity'] = true; |
|
536 | + break; |
|
537 | + case 'l' : |
|
538 | + $this->local = true; |
|
539 | + $this->overriddenDefaults['local'] = true; |
|
540 | + break; |
|
541 | + case 's' : |
|
542 | + $this->showSources = true; |
|
543 | + $this->overriddenDefaults['showSources'] = true; |
|
544 | + break; |
|
545 | + case 'a' : |
|
546 | + $this->interactive = true; |
|
547 | + $this->overriddenDefaults['interactive'] = true; |
|
548 | + break; |
|
549 | + case 'e': |
|
550 | + $this->explain = true; |
|
551 | + $this->overriddenDefaults['explain'] = true; |
|
552 | + break; |
|
553 | + case 'p' : |
|
554 | + $this->showProgress = true; |
|
555 | + $this->overriddenDefaults['showProgress'] = true; |
|
556 | + break; |
|
557 | + case 'm' : |
|
558 | + $this->recordErrors = false; |
|
559 | + $this->overriddenDefaults['recordErrors'] = true; |
|
560 | + break; |
|
561 | + case 'd' : |
|
562 | + $ini = explode('=', $this->cliArgs[($pos + 1)]); |
|
563 | + $this->cliArgs[($pos + 1)] = ''; |
|
564 | + if (isset($ini[1]) === true) { |
|
565 | + ini_set($ini[0], $ini[1]); |
|
566 | + } else { |
|
567 | + ini_set($ini[0], true); |
|
568 | + } |
|
569 | + break; |
|
570 | + case 'n' : |
|
571 | + if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
572 | + $this->warningSeverity = 0; |
|
573 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
574 | + } |
|
575 | + break; |
|
576 | + case 'w' : |
|
577 | + if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
578 | + $this->warningSeverity = $this->errorSeverity; |
|
579 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
580 | + } |
|
581 | + break; |
|
582 | + default: |
|
583 | + if ($this->dieOnUnknownArg === false) { |
|
584 | + $this->values[$arg] = $arg; |
|
585 | + } else { |
|
586 | + $this->processUnknownArgument('-'.$arg, $pos); |
|
587 | + } |
|
588 | 588 | }//end switch |
589 | 589 | |
590 | 590 | }//end processShortArgument() |
@@ -601,383 +601,383 @@ discard block |
||
601 | 601 | public function processLongArgument($arg, $pos) |
602 | 602 | { |
603 | 603 | switch ($arg) { |
604 | - case 'help': |
|
605 | - $this->printUsage(); |
|
606 | - exit(0); |
|
607 | - case 'version': |
|
608 | - echo 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') '; |
|
609 | - echo 'by Squiz (http://www.squiz.net)'.PHP_EOL; |
|
610 | - exit(0); |
|
611 | - case 'colors': |
|
612 | - $this->colors = true; |
|
613 | - $this->overriddenDefaults['colors'] = true; |
|
614 | - break; |
|
615 | - case 'no-colors': |
|
616 | - $this->colors = false; |
|
617 | - $this->overriddenDefaults['colors'] = true; |
|
618 | - break; |
|
619 | - case 'cache': |
|
620 | - if (defined('PHP_CODESNIFFER_IN_TESTS') === false) { |
|
621 | - $this->cache = true; |
|
622 | - $this->overriddenDefaults['cache'] = true; |
|
623 | - } |
|
624 | - break; |
|
625 | - case 'no-cache': |
|
626 | - $this->cache = false; |
|
627 | - $this->overriddenDefaults['cache'] = true; |
|
628 | - break; |
|
629 | - case 'config-set': |
|
630 | - if (isset($this->cliArgs[($pos + 1)]) === false |
|
631 | - || isset($this->cliArgs[($pos + 2)]) === false |
|
632 | - ) { |
|
633 | - echo 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL; |
|
604 | + case 'help': |
|
634 | 605 | $this->printUsage(); |
635 | 606 | exit(0); |
636 | - } |
|
637 | - |
|
638 | - $key = $this->cliArgs[($pos + 1)]; |
|
639 | - $value = $this->cliArgs[($pos + 2)]; |
|
640 | - $current = self::getConfigData($key); |
|
641 | - |
|
642 | - try { |
|
643 | - $this->setConfigData($key, $value); |
|
644 | - } catch (Exception $e) { |
|
645 | - echo $e->getMessage().PHP_EOL; |
|
646 | - exit(2); |
|
647 | - } |
|
648 | - |
|
649 | - if ($current === null) { |
|
650 | - echo "Config value \"$key\" added successfully".PHP_EOL; |
|
651 | - } else { |
|
652 | - echo "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL; |
|
653 | - } |
|
654 | - exit(0); |
|
655 | - case 'config-delete': |
|
656 | - if (isset($this->cliArgs[($pos + 1)]) === false) { |
|
657 | - echo 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL; |
|
658 | - $this->printUsage(); |
|
607 | + case 'version': |
|
608 | + echo 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') '; |
|
609 | + echo 'by Squiz (http://www.squiz.net)'.PHP_EOL; |
|
659 | 610 | exit(0); |
660 | - } |
|
611 | + case 'colors': |
|
612 | + $this->colors = true; |
|
613 | + $this->overriddenDefaults['colors'] = true; |
|
614 | + break; |
|
615 | + case 'no-colors': |
|
616 | + $this->colors = false; |
|
617 | + $this->overriddenDefaults['colors'] = true; |
|
618 | + break; |
|
619 | + case 'cache': |
|
620 | + if (defined('PHP_CODESNIFFER_IN_TESTS') === false) { |
|
621 | + $this->cache = true; |
|
622 | + $this->overriddenDefaults['cache'] = true; |
|
623 | + } |
|
624 | + break; |
|
625 | + case 'no-cache': |
|
626 | + $this->cache = false; |
|
627 | + $this->overriddenDefaults['cache'] = true; |
|
628 | + break; |
|
629 | + case 'config-set': |
|
630 | + if (isset($this->cliArgs[($pos + 1)]) === false |
|
631 | + || isset($this->cliArgs[($pos + 2)]) === false |
|
632 | + ) { |
|
633 | + echo 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL; |
|
634 | + $this->printUsage(); |
|
635 | + exit(0); |
|
636 | + } |
|
637 | + |
|
638 | + $key = $this->cliArgs[($pos + 1)]; |
|
639 | + $value = $this->cliArgs[($pos + 2)]; |
|
640 | + $current = self::getConfigData($key); |
|
661 | 641 | |
662 | - $key = $this->cliArgs[($pos + 1)]; |
|
663 | - $current = self::getConfigData($key); |
|
664 | - if ($current === null) { |
|
665 | - echo "Config value \"$key\" has not been set".PHP_EOL; |
|
666 | - } else { |
|
667 | 642 | try { |
668 | - $this->setConfigData($key, null); |
|
643 | + $this->setConfigData($key, $value); |
|
669 | 644 | } catch (Exception $e) { |
670 | 645 | echo $e->getMessage().PHP_EOL; |
671 | 646 | exit(2); |
672 | 647 | } |
673 | 648 | |
674 | - echo "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL; |
|
675 | - } |
|
676 | - exit(0); |
|
677 | - case 'config-show': |
|
678 | - $data = self::getAllConfigData(); |
|
679 | - $this->printConfigData($data); |
|
680 | - exit(0); |
|
681 | - case 'runtime-set': |
|
682 | - if (isset($this->cliArgs[($pos + 1)]) === false |
|
683 | - || isset($this->cliArgs[($pos + 2)]) === false |
|
684 | - ) { |
|
685 | - echo 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL; |
|
686 | - $this->printUsage(); |
|
649 | + if ($current === null) { |
|
650 | + echo "Config value \"$key\" added successfully".PHP_EOL; |
|
651 | + } else { |
|
652 | + echo "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL; |
|
653 | + } |
|
687 | 654 | exit(0); |
688 | - } |
|
655 | + case 'config-delete': |
|
656 | + if (isset($this->cliArgs[($pos + 1)]) === false) { |
|
657 | + echo 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL; |
|
658 | + $this->printUsage(); |
|
659 | + exit(0); |
|
660 | + } |
|
689 | 661 | |
690 | - $key = $this->cliArgs[($pos + 1)]; |
|
691 | - $value = $this->cliArgs[($pos + 2)]; |
|
692 | - $this->cliArgs[($pos + 1)] = ''; |
|
693 | - $this->cliArgs[($pos + 2)] = ''; |
|
694 | - self::setConfigData($key, $value, true); |
|
695 | - break; |
|
696 | - default: |
|
697 | - if (substr($arg, 0, 7) === 'sniffs=') { |
|
698 | - $sniffs = explode(',', substr($arg, 7)); |
|
699 | - foreach ($sniffs as $sniff) { |
|
700 | - if (substr_count($sniff, '.') !== 2) { |
|
701 | - echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL; |
|
702 | - $this->printUsage(); |
|
662 | + $key = $this->cliArgs[($pos + 1)]; |
|
663 | + $current = self::getConfigData($key); |
|
664 | + if ($current === null) { |
|
665 | + echo "Config value \"$key\" has not been set".PHP_EOL; |
|
666 | + } else { |
|
667 | + try { |
|
668 | + $this->setConfigData($key, null); |
|
669 | + } catch (Exception $e) { |
|
670 | + echo $e->getMessage().PHP_EOL; |
|
703 | 671 | exit(2); |
704 | 672 | } |
673 | + |
|
674 | + echo "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL; |
|
675 | + } |
|
676 | + exit(0); |
|
677 | + case 'config-show': |
|
678 | + $data = self::getAllConfigData(); |
|
679 | + $this->printConfigData($data); |
|
680 | + exit(0); |
|
681 | + case 'runtime-set': |
|
682 | + if (isset($this->cliArgs[($pos + 1)]) === false |
|
683 | + || isset($this->cliArgs[($pos + 2)]) === false |
|
684 | + ) { |
|
685 | + echo 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL; |
|
686 | + $this->printUsage(); |
|
687 | + exit(0); |
|
705 | 688 | } |
706 | 689 | |
707 | - $this->sniffs = $sniffs; |
|
708 | - $this->overriddenDefaults['sniffs'] = true; |
|
709 | - } else if (defined('PHP_CODESNIFFER_IN_TESTS') === false |
|
710 | - && substr($arg, 0, 6) === 'cache=' |
|
711 | - ) { |
|
712 | - // Turn caching on. |
|
713 | - $this->cache = true; |
|
714 | - $this->overriddenDefaults['cache'] = true; |
|
690 | + $key = $this->cliArgs[($pos + 1)]; |
|
691 | + $value = $this->cliArgs[($pos + 2)]; |
|
692 | + $this->cliArgs[($pos + 1)] = ''; |
|
693 | + $this->cliArgs[($pos + 2)] = ''; |
|
694 | + self::setConfigData($key, $value, true); |
|
695 | + break; |
|
696 | + default: |
|
697 | + if (substr($arg, 0, 7) === 'sniffs=') { |
|
698 | + $sniffs = explode(',', substr($arg, 7)); |
|
699 | + foreach ($sniffs as $sniff) { |
|
700 | + if (substr_count($sniff, '.') !== 2) { |
|
701 | + echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL; |
|
702 | + $this->printUsage(); |
|
703 | + exit(2); |
|
704 | + } |
|
705 | + } |
|
715 | 706 | |
716 | - $this->cacheFile = Util\Common::realpath(substr($arg, 6)); |
|
707 | + $this->sniffs = $sniffs; |
|
708 | + $this->overriddenDefaults['sniffs'] = true; |
|
709 | + } else if (defined('PHP_CODESNIFFER_IN_TESTS') === false |
|
710 | + && substr($arg, 0, 6) === 'cache=' |
|
711 | + ) { |
|
712 | + // Turn caching on. |
|
713 | + $this->cache = true; |
|
714 | + $this->overriddenDefaults['cache'] = true; |
|
715 | + |
|
716 | + $this->cacheFile = Util\Common::realpath(substr($arg, 6)); |
|
717 | + |
|
718 | + // It may not exist and return false instead. |
|
719 | + if ($this->cacheFile === false) { |
|
720 | + $this->cacheFile = substr($arg, 6); |
|
721 | + |
|
722 | + $dir = dirname($this->cacheFile); |
|
723 | + if (is_dir($dir) === false) { |
|
724 | + echo 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
725 | + $this->printUsage(); |
|
726 | + exit(2); |
|
727 | + } |
|
717 | 728 | |
718 | - // It may not exist and return false instead. |
|
719 | - if ($this->cacheFile === false) { |
|
720 | - $this->cacheFile = substr($arg, 6); |
|
729 | + if ($dir === '.') { |
|
730 | + // Passed report file is a file in the current directory. |
|
731 | + $this->cacheFile = getcwd().'/'.basename($this->cacheFile); |
|
732 | + } else { |
|
733 | + $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
734 | + if ($dir !== false) { |
|
735 | + // Report file path is relative. |
|
736 | + $this->cacheFile = $dir.'/'.basename($this->cacheFile); |
|
737 | + } |
|
738 | + } |
|
739 | + }//end if |
|
721 | 740 | |
722 | - $dir = dirname($this->cacheFile); |
|
723 | - if (is_dir($dir) === false) { |
|
724 | - echo 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
741 | + $this->overriddenDefaults['cacheFile'] = true; |
|
742 | + |
|
743 | + if (is_dir($this->cacheFile) === true) { |
|
744 | + echo 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL; |
|
725 | 745 | $this->printUsage(); |
726 | 746 | exit(2); |
727 | 747 | } |
728 | - |
|
729 | - if ($dir === '.') { |
|
730 | - // Passed report file is a file in the current directory. |
|
731 | - $this->cacheFile = getcwd().'/'.basename($this->cacheFile); |
|
732 | - } else { |
|
733 | - $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
734 | - if ($dir !== false) { |
|
735 | - // Report file path is relative. |
|
736 | - $this->cacheFile = $dir.'/'.basename($this->cacheFile); |
|
748 | + } else if (substr($arg, 0, 10) === 'bootstrap=') { |
|
749 | + $files = explode(',', substr($arg, 10)); |
|
750 | + $bootstrap = array(); |
|
751 | + foreach ($files as $file) { |
|
752 | + $path = Util\Common::realpath($file); |
|
753 | + if ($path === false) { |
|
754 | + echo 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL; |
|
755 | + $this->printUsage(); |
|
756 | + exit(2); |
|
737 | 757 | } |
758 | + |
|
759 | + $bootstrap[] = $path; |
|
738 | 760 | } |
739 | - }//end if |
|
740 | 761 | |
741 | - $this->overriddenDefaults['cacheFile'] = true; |
|
762 | + $this->bootstrap = array_merge($this->bootstrap, $bootstrap); |
|
763 | + $this->overriddenDefaults['bootstrap'] = true; |
|
764 | + } else if (substr($arg, 0, 11) === 'stdin-path=') { |
|
765 | + $this->stdinPath = Util\Common::realpath(substr($arg, 11)); |
|
742 | 766 | |
743 | - if (is_dir($this->cacheFile) === true) { |
|
744 | - echo 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL; |
|
745 | - $this->printUsage(); |
|
746 | - exit(2); |
|
747 | - } |
|
748 | - } else if (substr($arg, 0, 10) === 'bootstrap=') { |
|
749 | - $files = explode(',', substr($arg, 10)); |
|
750 | - $bootstrap = array(); |
|
751 | - foreach ($files as $file) { |
|
752 | - $path = Util\Common::realpath($file); |
|
753 | - if ($path === false) { |
|
754 | - echo 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL; |
|
755 | - $this->printUsage(); |
|
756 | - exit(2); |
|
767 | + // It may not exist and return false instead, so use whatever they gave us. |
|
768 | + if ($this->stdinPath === false) { |
|
769 | + $this->stdinPath = trim(substr($arg, 11)); |
|
757 | 770 | } |
758 | 771 | |
759 | - $bootstrap[] = $path; |
|
760 | - } |
|
772 | + $this->overriddenDefaults['stdinPath'] = true; |
|
773 | + } else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') { |
|
774 | + $this->reportFile = Util\Common::realpath(substr($arg, 12)); |
|
761 | 775 | |
762 | - $this->bootstrap = array_merge($this->bootstrap, $bootstrap); |
|
763 | - $this->overriddenDefaults['bootstrap'] = true; |
|
764 | - } else if (substr($arg, 0, 11) === 'stdin-path=') { |
|
765 | - $this->stdinPath = Util\Common::realpath(substr($arg, 11)); |
|
776 | + // It may not exist and return false instead. |
|
777 | + if ($this->reportFile === false) { |
|
778 | + $this->reportFile = substr($arg, 12); |
|
766 | 779 | |
767 | - // It may not exist and return false instead, so use whatever they gave us. |
|
768 | - if ($this->stdinPath === false) { |
|
769 | - $this->stdinPath = trim(substr($arg, 11)); |
|
770 | - } |
|
780 | + $dir = dirname($this->reportFile); |
|
781 | + if (is_dir($dir) === false) { |
|
782 | + echo 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
783 | + $this->printUsage(); |
|
784 | + exit(2); |
|
785 | + } |
|
771 | 786 | |
772 | - $this->overriddenDefaults['stdinPath'] = true; |
|
773 | - } else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') { |
|
774 | - $this->reportFile = Util\Common::realpath(substr($arg, 12)); |
|
787 | + if ($dir === '.') { |
|
788 | + // Passed report file is a file in the current directory. |
|
789 | + $this->reportFile = getcwd().'/'.basename($this->reportFile); |
|
790 | + } else { |
|
791 | + $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
792 | + if ($dir !== false) { |
|
793 | + // Report file path is relative. |
|
794 | + $this->reportFile = $dir.'/'.basename($this->reportFile); |
|
795 | + } |
|
796 | + } |
|
797 | + }//end if |
|
775 | 798 | |
776 | - // It may not exist and return false instead. |
|
777 | - if ($this->reportFile === false) { |
|
778 | - $this->reportFile = substr($arg, 12); |
|
799 | + $this->overriddenDefaults['reportFile'] = true; |
|
779 | 800 | |
780 | - $dir = dirname($this->reportFile); |
|
781 | - if (is_dir($dir) === false) { |
|
782 | - echo 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
801 | + if (is_dir($this->reportFile) === true) { |
|
802 | + echo 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL; |
|
783 | 803 | $this->printUsage(); |
784 | 804 | exit(2); |
785 | 805 | } |
786 | - |
|
787 | - if ($dir === '.') { |
|
788 | - // Passed report file is a file in the current directory. |
|
789 | - $this->reportFile = getcwd().'/'.basename($this->reportFile); |
|
790 | - } else { |
|
791 | - $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
792 | - if ($dir !== false) { |
|
793 | - // Report file path is relative. |
|
794 | - $this->reportFile = $dir.'/'.basename($this->reportFile); |
|
795 | - } |
|
806 | + } else if (substr($arg, 0, 13) === 'report-width=') { |
|
807 | + if (isset($this->overriddenDefaults['reportWidth']) === true) { |
|
808 | + break; |
|
796 | 809 | } |
797 | - }//end if |
|
798 | - |
|
799 | - $this->overriddenDefaults['reportFile'] = true; |
|
800 | 810 | |
801 | - if (is_dir($this->reportFile) === true) { |
|
802 | - echo 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL; |
|
803 | - $this->printUsage(); |
|
804 | - exit(2); |
|
805 | - } |
|
806 | - } else if (substr($arg, 0, 13) === 'report-width=') { |
|
807 | - if (isset($this->overriddenDefaults['reportWidth']) === true) { |
|
808 | - break; |
|
809 | - } |
|
810 | - |
|
811 | - $this->reportWidth = substr($arg, 13); |
|
812 | - $this->overriddenDefaults['reportWidth'] = true; |
|
813 | - } else if (substr($arg, 0, 9) === 'basepath=') { |
|
814 | - if (isset($this->overriddenDefaults['basepath']) === true) { |
|
815 | - break; |
|
816 | - } |
|
811 | + $this->reportWidth = substr($arg, 13); |
|
812 | + $this->overriddenDefaults['reportWidth'] = true; |
|
813 | + } else if (substr($arg, 0, 9) === 'basepath=') { |
|
814 | + if (isset($this->overriddenDefaults['basepath']) === true) { |
|
815 | + break; |
|
816 | + } |
|
817 | 817 | |
818 | - $this->basepath = Util\Common::realpath(substr($arg, 9)); |
|
818 | + $this->basepath = Util\Common::realpath(substr($arg, 9)); |
|
819 | 819 | |
820 | - // It may not exist and return false instead. |
|
821 | - if ($this->basepath === false) { |
|
822 | - $this->basepath = substr($arg, 9); |
|
823 | - } |
|
820 | + // It may not exist and return false instead. |
|
821 | + if ($this->basepath === false) { |
|
822 | + $this->basepath = substr($arg, 9); |
|
823 | + } |
|
824 | 824 | |
825 | - $this->overriddenDefaults['basepath'] = true; |
|
825 | + $this->overriddenDefaults['basepath'] = true; |
|
826 | 826 | |
827 | - if (is_dir($this->basepath) === false) { |
|
828 | - echo 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
829 | - $this->printUsage(); |
|
830 | - exit(2); |
|
831 | - } |
|
832 | - } else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) { |
|
833 | - $reports = array(); |
|
834 | - |
|
835 | - if ($arg[6] === '-') { |
|
836 | - // This is a report with file output. |
|
837 | - $split = strpos($arg, '='); |
|
838 | - if ($split === false) { |
|
839 | - $report = substr($arg, 7); |
|
840 | - $output = null; |
|
841 | - } else { |
|
842 | - $report = substr($arg, 7, ($split - 7)); |
|
843 | - $output = substr($arg, ($split + 1)); |
|
844 | - if ($output === false) { |
|
827 | + if (is_dir($this->basepath) === false) { |
|
828 | + echo 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
829 | + $this->printUsage(); |
|
830 | + exit(2); |
|
831 | + } |
|
832 | + } else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) { |
|
833 | + $reports = array(); |
|
834 | + |
|
835 | + if ($arg[6] === '-') { |
|
836 | + // This is a report with file output. |
|
837 | + $split = strpos($arg, '='); |
|
838 | + if ($split === false) { |
|
839 | + $report = substr($arg, 7); |
|
845 | 840 | $output = null; |
846 | 841 | } else { |
847 | - $dir = dirname($output); |
|
848 | - if ($dir === '.') { |
|
849 | - // Passed report file is a filename in the current directory. |
|
850 | - $output = getcwd().'/'.basename($output); |
|
842 | + $report = substr($arg, 7, ($split - 7)); |
|
843 | + $output = substr($arg, ($split + 1)); |
|
844 | + if ($output === false) { |
|
845 | + $output = null; |
|
851 | 846 | } else { |
852 | - $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
853 | - if ($dir !== false) { |
|
854 | - // Report file path is relative. |
|
855 | - $output = $dir.'/'.basename($output); |
|
847 | + $dir = dirname($output); |
|
848 | + if ($dir === '.') { |
|
849 | + // Passed report file is a filename in the current directory. |
|
850 | + $output = getcwd().'/'.basename($output); |
|
851 | + } else { |
|
852 | + $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
853 | + if ($dir !== false) { |
|
854 | + // Report file path is relative. |
|
855 | + $output = $dir.'/'.basename($output); |
|
856 | + } |
|
856 | 857 | } |
857 | - } |
|
858 | + }//end if |
|
858 | 859 | }//end if |
860 | + |
|
861 | + $reports[$report] = $output; |
|
862 | + } else { |
|
863 | + // This is a single report. |
|
864 | + if (isset($this->overriddenDefaults['reports']) === true) { |
|
865 | + break; |
|
866 | + } |
|
867 | + |
|
868 | + $reportNames = explode(',', substr($arg, 7)); |
|
869 | + foreach ($reportNames as $report) { |
|
870 | + $reports[$report] = null; |
|
871 | + } |
|
859 | 872 | }//end if |
860 | 873 | |
861 | - $reports[$report] = $output; |
|
862 | - } else { |
|
863 | - // This is a single report. |
|
864 | - if (isset($this->overriddenDefaults['reports']) === true) { |
|
865 | - break; |
|
874 | + // Remove the default value so the CLI value overrides it. |
|
875 | + if (isset($this->overriddenDefaults['reports']) === false) { |
|
876 | + $this->reports = $reports; |
|
877 | + } else { |
|
878 | + $this->reports = array_merge($this->reports, $reports); |
|
866 | 879 | } |
867 | 880 | |
868 | - $reportNames = explode(',', substr($arg, 7)); |
|
869 | - foreach ($reportNames as $report) { |
|
870 | - $reports[$report] = null; |
|
881 | + $this->overriddenDefaults['reports'] = true; |
|
882 | + } else if (substr($arg, 0, 7) === 'filter=') { |
|
883 | + if (isset($this->overriddenDefaults['filter']) === true) { |
|
884 | + break; |
|
871 | 885 | } |
872 | - }//end if |
|
873 | 886 | |
874 | - // Remove the default value so the CLI value overrides it. |
|
875 | - if (isset($this->overriddenDefaults['reports']) === false) { |
|
876 | - $this->reports = $reports; |
|
877 | - } else { |
|
878 | - $this->reports = array_merge($this->reports, $reports); |
|
879 | - } |
|
880 | - |
|
881 | - $this->overriddenDefaults['reports'] = true; |
|
882 | - } else if (substr($arg, 0, 7) === 'filter=') { |
|
883 | - if (isset($this->overriddenDefaults['filter']) === true) { |
|
884 | - break; |
|
885 | - } |
|
887 | + $this->filter = substr($arg, 7); |
|
888 | + $this->overriddenDefaults['filter'] = true; |
|
889 | + } else if (substr($arg, 0, 9) === 'standard=') { |
|
890 | + $standards = trim(substr($arg, 9)); |
|
891 | + if ($standards !== '') { |
|
892 | + $this->standards = explode(',', $standards); |
|
893 | + } |
|
886 | 894 | |
887 | - $this->filter = substr($arg, 7); |
|
888 | - $this->overriddenDefaults['filter'] = true; |
|
889 | - } else if (substr($arg, 0, 9) === 'standard=') { |
|
890 | - $standards = trim(substr($arg, 9)); |
|
891 | - if ($standards !== '') { |
|
892 | - $this->standards = explode(',', $standards); |
|
893 | - } |
|
895 | + $this->overriddenDefaults['standards'] = true; |
|
896 | + } else if (substr($arg, 0, 11) === 'extensions=') { |
|
897 | + $extensions = explode(',', substr($arg, 11)); |
|
898 | + $newExtensions = array(); |
|
899 | + foreach ($extensions as $ext) { |
|
900 | + $slash = strpos($ext, '/'); |
|
901 | + if ($slash !== false) { |
|
902 | + // They specified the tokenizer too. |
|
903 | + list($ext, $tokenizer) = explode('/', $ext); |
|
904 | + $newExtensions[$ext] = strtoupper($tokenizer); |
|
905 | + continue; |
|
906 | + } |
|
894 | 907 | |
895 | - $this->overriddenDefaults['standards'] = true; |
|
896 | - } else if (substr($arg, 0, 11) === 'extensions=') { |
|
897 | - $extensions = explode(',', substr($arg, 11)); |
|
898 | - $newExtensions = array(); |
|
899 | - foreach ($extensions as $ext) { |
|
900 | - $slash = strpos($ext, '/'); |
|
901 | - if ($slash !== false) { |
|
902 | - // They specified the tokenizer too. |
|
903 | - list($ext, $tokenizer) = explode('/', $ext); |
|
904 | - $newExtensions[$ext] = strtoupper($tokenizer); |
|
905 | - continue; |
|
908 | + if (isset($this->extensions[$ext]) === true) { |
|
909 | + $newExtensions[$ext] = $this->extensions[$ext]; |
|
910 | + } else { |
|
911 | + $newExtensions[$ext] = 'PHP'; |
|
912 | + } |
|
906 | 913 | } |
907 | 914 | |
908 | - if (isset($this->extensions[$ext]) === true) { |
|
909 | - $newExtensions[$ext] = $this->extensions[$ext]; |
|
910 | - } else { |
|
911 | - $newExtensions[$ext] = 'PHP'; |
|
912 | - } |
|
913 | - } |
|
915 | + $this->extensions = $newExtensions; |
|
916 | + $this->overriddenDefaults['extensions'] = true; |
|
917 | + } else if (substr($arg, 0, 7) === 'suffix=') { |
|
918 | + $this->suffix = explode(',', substr($arg, 7)); |
|
919 | + $this->overriddenDefaults['suffix'] = true; |
|
920 | + } else if (substr($arg, 0, 9) === 'parallel=') { |
|
921 | + $this->parallel = max((int) substr($arg, 9), 1); |
|
922 | + $this->overriddenDefaults['parallel'] = true; |
|
923 | + } else if (substr($arg, 0, 9) === 'severity=') { |
|
924 | + $this->errorSeverity = (int) substr($arg, 9); |
|
925 | + $this->warningSeverity = $this->errorSeverity; |
|
926 | + $this->overriddenDefaults['errorSeverity'] = true; |
|
927 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
928 | + } else if (substr($arg, 0, 15) === 'error-severity=') { |
|
929 | + $this->errorSeverity = (int) substr($arg, 15); |
|
930 | + $this->overriddenDefaults['errorSeverity'] = true; |
|
931 | + } else if (substr($arg, 0, 17) === 'warning-severity=') { |
|
932 | + $this->warningSeverity = (int) substr($arg, 17); |
|
933 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
934 | + } else if (substr($arg, 0, 7) === 'ignore=') { |
|
935 | + // Split the ignore string on commas, unless the comma is escaped |
|
936 | + // using 1 or 3 slashes (\, or \\\,). |
|
937 | + $patterns = preg_split( |
|
938 | + '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', |
|
939 | + substr($arg, 7) |
|
940 | + ); |
|
941 | + |
|
942 | + $ignored = array(); |
|
943 | + foreach ($patterns as $pattern) { |
|
944 | + $pattern = trim($pattern); |
|
945 | + if ($pattern === '') { |
|
946 | + continue; |
|
947 | + } |
|
914 | 948 | |
915 | - $this->extensions = $newExtensions; |
|
916 | - $this->overriddenDefaults['extensions'] = true; |
|
917 | - } else if (substr($arg, 0, 7) === 'suffix=') { |
|
918 | - $this->suffix = explode(',', substr($arg, 7)); |
|
919 | - $this->overriddenDefaults['suffix'] = true; |
|
920 | - } else if (substr($arg, 0, 9) === 'parallel=') { |
|
921 | - $this->parallel = max((int) substr($arg, 9), 1); |
|
922 | - $this->overriddenDefaults['parallel'] = true; |
|
923 | - } else if (substr($arg, 0, 9) === 'severity=') { |
|
924 | - $this->errorSeverity = (int) substr($arg, 9); |
|
925 | - $this->warningSeverity = $this->errorSeverity; |
|
926 | - $this->overriddenDefaults['errorSeverity'] = true; |
|
927 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
928 | - } else if (substr($arg, 0, 15) === 'error-severity=') { |
|
929 | - $this->errorSeverity = (int) substr($arg, 15); |
|
930 | - $this->overriddenDefaults['errorSeverity'] = true; |
|
931 | - } else if (substr($arg, 0, 17) === 'warning-severity=') { |
|
932 | - $this->warningSeverity = (int) substr($arg, 17); |
|
933 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
934 | - } else if (substr($arg, 0, 7) === 'ignore=') { |
|
935 | - // Split the ignore string on commas, unless the comma is escaped |
|
936 | - // using 1 or 3 slashes (\, or \\\,). |
|
937 | - $patterns = preg_split( |
|
938 | - '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', |
|
939 | - substr($arg, 7) |
|
940 | - ); |
|
941 | - |
|
942 | - $ignored = array(); |
|
943 | - foreach ($patterns as $pattern) { |
|
944 | - $pattern = trim($pattern); |
|
945 | - if ($pattern === '') { |
|
946 | - continue; |
|
949 | + $ignored[$pattern] = 'absolute'; |
|
947 | 950 | } |
948 | 951 | |
949 | - $ignored[$pattern] = 'absolute'; |
|
950 | - } |
|
951 | - |
|
952 | - $this->ignored = $ignored; |
|
953 | - $this->overriddenDefaults['ignored'] = true; |
|
954 | - } else if (substr($arg, 0, 10) === 'generator=' |
|
955 | - && PHP_CODESNIFFER_CBF === false |
|
956 | - ) { |
|
957 | - $this->generator = substr($arg, 10); |
|
958 | - $this->overriddenDefaults['generator'] = true; |
|
959 | - } else if (substr($arg, 0, 9) === 'encoding=') { |
|
960 | - $this->encoding = strtolower(substr($arg, 9)); |
|
961 | - $this->overriddenDefaults['encoding'] = true; |
|
962 | - } else if (substr($arg, 0, 10) === 'tab-width=') { |
|
963 | - $this->tabWidth = (int) substr($arg, 10); |
|
964 | - $this->overriddenDefaults['tabWidth'] = true; |
|
965 | - } else { |
|
966 | - if ($this->dieOnUnknownArg === false) { |
|
967 | - $eqPos = strpos($arg, '='); |
|
968 | - if ($eqPos === false) { |
|
969 | - $this->values[$arg] = $arg; |
|
952 | + $this->ignored = $ignored; |
|
953 | + $this->overriddenDefaults['ignored'] = true; |
|
954 | + } else if (substr($arg, 0, 10) === 'generator=' |
|
955 | + && PHP_CODESNIFFER_CBF === false |
|
956 | + ) { |
|
957 | + $this->generator = substr($arg, 10); |
|
958 | + $this->overriddenDefaults['generator'] = true; |
|
959 | + } else if (substr($arg, 0, 9) === 'encoding=') { |
|
960 | + $this->encoding = strtolower(substr($arg, 9)); |
|
961 | + $this->overriddenDefaults['encoding'] = true; |
|
962 | + } else if (substr($arg, 0, 10) === 'tab-width=') { |
|
963 | + $this->tabWidth = (int) substr($arg, 10); |
|
964 | + $this->overriddenDefaults['tabWidth'] = true; |
|
965 | + } else { |
|
966 | + if ($this->dieOnUnknownArg === false) { |
|
967 | + $eqPos = strpos($arg, '='); |
|
968 | + if ($eqPos === false) { |
|
969 | + $this->values[$arg] = $arg; |
|
970 | + } else { |
|
971 | + $value = substr($arg, ($eqPos + 1)); |
|
972 | + $arg = substr($arg, 0, $eqPos); |
|
973 | + $this->values[$arg] = $value; |
|
974 | + } |
|
970 | 975 | } else { |
971 | - $value = substr($arg, ($eqPos + 1)); |
|
972 | - $arg = substr($arg, 0, $eqPos); |
|
973 | - $this->values[$arg] = $value; |
|
976 | + $this->processUnknownArgument('--'.$arg, $pos); |
|
974 | 977 | } |
975 | - } else { |
|
976 | - $this->processUnknownArgument('--'.$arg, $pos); |
|
977 | - } |
|
978 | - }//end if |
|
978 | + }//end if |
|
979 | 979 | |
980 | - break; |
|
980 | + break; |
|
981 | 981 | }//end switch |
982 | 982 | |
983 | 983 | }//end processLongArgument() |
@@ -406,60 +406,60 @@ |
||
406 | 406 | */ |
407 | 407 | |
408 | 408 | switch ($this->tokens[$i]['code']) { |
409 | - case T_OPEN_SQUARE_BRACKET: |
|
410 | - $squareOpeners[] = $i; |
|
411 | - |
|
412 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
413 | - echo str_repeat("\t", count($squareOpeners)); |
|
414 | - echo str_repeat("\t", count($curlyOpeners)); |
|
415 | - echo "=> Found square bracket opener at $i".PHP_EOL; |
|
416 | - } |
|
417 | - break; |
|
418 | - case T_OPEN_CURLY_BRACKET: |
|
419 | - if (isset($this->tokens[$i]['scope_closer']) === false) { |
|
420 | - $curlyOpeners[] = $i; |
|
409 | + case T_OPEN_SQUARE_BRACKET: |
|
410 | + $squareOpeners[] = $i; |
|
421 | 411 | |
422 | 412 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
423 | 413 | echo str_repeat("\t", count($squareOpeners)); |
424 | 414 | echo str_repeat("\t", count($curlyOpeners)); |
425 | - echo "=> Found curly bracket opener at $i".PHP_EOL; |
|
415 | + echo "=> Found square bracket opener at $i".PHP_EOL; |
|
426 | 416 | } |
427 | - } |
|
428 | - break; |
|
429 | - case T_CLOSE_SQUARE_BRACKET: |
|
430 | - if (empty($squareOpeners) === false) { |
|
431 | - $opener = array_pop($squareOpeners); |
|
432 | - $this->tokens[$i]['bracket_opener'] = $opener; |
|
433 | - $this->tokens[$i]['bracket_closer'] = $i; |
|
434 | - $this->tokens[$opener]['bracket_opener'] = $opener; |
|
435 | - $this->tokens[$opener]['bracket_closer'] = $i; |
|
417 | + break; |
|
418 | + case T_OPEN_CURLY_BRACKET: |
|
419 | + if (isset($this->tokens[$i]['scope_closer']) === false) { |
|
420 | + $curlyOpeners[] = $i; |
|
436 | 421 | |
437 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
438 | - echo str_repeat("\t", count($squareOpeners)); |
|
439 | - echo str_repeat("\t", count($curlyOpeners)); |
|
440 | - echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL; |
|
422 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
423 | + echo str_repeat("\t", count($squareOpeners)); |
|
424 | + echo str_repeat("\t", count($curlyOpeners)); |
|
425 | + echo "=> Found curly bracket opener at $i".PHP_EOL; |
|
426 | + } |
|
441 | 427 | } |
442 | - } |
|
443 | - break; |
|
444 | - case T_CLOSE_CURLY_BRACKET: |
|
445 | - if (empty($curlyOpeners) === false |
|
446 | - && isset($this->tokens[$i]['scope_opener']) === false |
|
447 | - ) { |
|
448 | - $opener = array_pop($curlyOpeners); |
|
449 | - $this->tokens[$i]['bracket_opener'] = $opener; |
|
450 | - $this->tokens[$i]['bracket_closer'] = $i; |
|
451 | - $this->tokens[$opener]['bracket_opener'] = $opener; |
|
452 | - $this->tokens[$opener]['bracket_closer'] = $i; |
|
428 | + break; |
|
429 | + case T_CLOSE_SQUARE_BRACKET: |
|
430 | + if (empty($squareOpeners) === false) { |
|
431 | + $opener = array_pop($squareOpeners); |
|
432 | + $this->tokens[$i]['bracket_opener'] = $opener; |
|
433 | + $this->tokens[$i]['bracket_closer'] = $i; |
|
434 | + $this->tokens[$opener]['bracket_opener'] = $opener; |
|
435 | + $this->tokens[$opener]['bracket_closer'] = $i; |
|
453 | 436 | |
454 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
455 | - echo str_repeat("\t", count($squareOpeners)); |
|
456 | - echo str_repeat("\t", count($curlyOpeners)); |
|
457 | - echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL; |
|
437 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
438 | + echo str_repeat("\t", count($squareOpeners)); |
|
439 | + echo str_repeat("\t", count($curlyOpeners)); |
|
440 | + echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL; |
|
441 | + } |
|
458 | 442 | } |
459 | - } |
|
460 | - break; |
|
461 | - default: |
|
462 | - continue; |
|
443 | + break; |
|
444 | + case T_CLOSE_CURLY_BRACKET: |
|
445 | + if (empty($curlyOpeners) === false |
|
446 | + && isset($this->tokens[$i]['scope_opener']) === false |
|
447 | + ) { |
|
448 | + $opener = array_pop($curlyOpeners); |
|
449 | + $this->tokens[$i]['bracket_opener'] = $opener; |
|
450 | + $this->tokens[$i]['bracket_closer'] = $i; |
|
451 | + $this->tokens[$opener]['bracket_opener'] = $opener; |
|
452 | + $this->tokens[$opener]['bracket_closer'] = $i; |
|
453 | + |
|
454 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
455 | + echo str_repeat("\t", count($squareOpeners)); |
|
456 | + echo str_repeat("\t", count($curlyOpeners)); |
|
457 | + echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL; |
|
458 | + } |
|
459 | + } |
|
460 | + break; |
|
461 | + default: |
|
462 | + continue; |
|
463 | 463 | }//end switch |
464 | 464 | }//end for |
465 | 465 |
@@ -1450,24 +1450,24 @@ discard block |
||
1450 | 1450 | |
1451 | 1451 | if ($token[0] === T_STRING) { |
1452 | 1452 | switch ($cacheKey) { |
1453 | - case 'false': |
|
1454 | - $newToken['type'] = 'T_FALSE'; |
|
1455 | - break; |
|
1456 | - case 'true': |
|
1457 | - $newToken['type'] = 'T_TRUE'; |
|
1458 | - break; |
|
1459 | - case 'null': |
|
1460 | - $newToken['type'] = 'T_NULL'; |
|
1461 | - break; |
|
1462 | - case 'self': |
|
1463 | - $newToken['type'] = 'T_SELF'; |
|
1464 | - break; |
|
1465 | - case 'parent': |
|
1466 | - $newToken['type'] = 'T_PARENT'; |
|
1467 | - break; |
|
1468 | - default: |
|
1469 | - $newToken['type'] = 'T_STRING'; |
|
1470 | - break; |
|
1453 | + case 'false': |
|
1454 | + $newToken['type'] = 'T_FALSE'; |
|
1455 | + break; |
|
1456 | + case 'true': |
|
1457 | + $newToken['type'] = 'T_TRUE'; |
|
1458 | + break; |
|
1459 | + case 'null': |
|
1460 | + $newToken['type'] = 'T_NULL'; |
|
1461 | + break; |
|
1462 | + case 'self': |
|
1463 | + $newToken['type'] = 'T_SELF'; |
|
1464 | + break; |
|
1465 | + case 'parent': |
|
1466 | + $newToken['type'] = 'T_PARENT'; |
|
1467 | + break; |
|
1468 | + default: |
|
1469 | + $newToken['type'] = 'T_STRING'; |
|
1470 | + break; |
|
1471 | 1471 | } |
1472 | 1472 | |
1473 | 1473 | $newToken['code'] = constant($newToken['type']); |
@@ -1509,87 +1509,87 @@ discard block |
||
1509 | 1509 | $newToken = array(); |
1510 | 1510 | |
1511 | 1511 | switch ($token) { |
1512 | - case '{': |
|
1513 | - $newToken['type'] = 'T_OPEN_CURLY_BRACKET'; |
|
1514 | - break; |
|
1515 | - case '}': |
|
1516 | - $newToken['type'] = 'T_CLOSE_CURLY_BRACKET'; |
|
1517 | - break; |
|
1518 | - case '[': |
|
1519 | - $newToken['type'] = 'T_OPEN_SQUARE_BRACKET'; |
|
1520 | - break; |
|
1521 | - case ']': |
|
1522 | - $newToken['type'] = 'T_CLOSE_SQUARE_BRACKET'; |
|
1523 | - break; |
|
1524 | - case '(': |
|
1525 | - $newToken['type'] = 'T_OPEN_PARENTHESIS'; |
|
1526 | - break; |
|
1527 | - case ')': |
|
1528 | - $newToken['type'] = 'T_CLOSE_PARENTHESIS'; |
|
1529 | - break; |
|
1530 | - case ':': |
|
1531 | - $newToken['type'] = 'T_COLON'; |
|
1532 | - break; |
|
1533 | - case '.': |
|
1534 | - $newToken['type'] = 'T_STRING_CONCAT'; |
|
1535 | - break; |
|
1536 | - case '?': |
|
1537 | - $newToken['type'] = 'T_INLINE_THEN'; |
|
1538 | - break; |
|
1539 | - case ';': |
|
1540 | - $newToken['type'] = 'T_SEMICOLON'; |
|
1541 | - break; |
|
1542 | - case '=': |
|
1543 | - $newToken['type'] = 'T_EQUAL'; |
|
1544 | - break; |
|
1545 | - case '*': |
|
1546 | - $newToken['type'] = 'T_MULTIPLY'; |
|
1547 | - break; |
|
1548 | - case '/': |
|
1549 | - $newToken['type'] = 'T_DIVIDE'; |
|
1550 | - break; |
|
1551 | - case '+': |
|
1552 | - $newToken['type'] = 'T_PLUS'; |
|
1553 | - break; |
|
1554 | - case '-': |
|
1555 | - $newToken['type'] = 'T_MINUS'; |
|
1556 | - break; |
|
1557 | - case '%': |
|
1558 | - $newToken['type'] = 'T_MODULUS'; |
|
1559 | - break; |
|
1560 | - case '^': |
|
1561 | - $newToken['type'] = 'T_BITWISE_XOR'; |
|
1562 | - break; |
|
1563 | - case '&': |
|
1564 | - $newToken['type'] = 'T_BITWISE_AND'; |
|
1565 | - break; |
|
1566 | - case '|': |
|
1567 | - $newToken['type'] = 'T_BITWISE_OR'; |
|
1568 | - break; |
|
1569 | - case '<': |
|
1570 | - $newToken['type'] = 'T_LESS_THAN'; |
|
1571 | - break; |
|
1572 | - case '>': |
|
1573 | - $newToken['type'] = 'T_GREATER_THAN'; |
|
1574 | - break; |
|
1575 | - case '!': |
|
1576 | - $newToken['type'] = 'T_BOOLEAN_NOT'; |
|
1577 | - break; |
|
1578 | - case ',': |
|
1579 | - $newToken['type'] = 'T_COMMA'; |
|
1580 | - break; |
|
1581 | - case '@': |
|
1582 | - $newToken['type'] = 'T_ASPERAND'; |
|
1583 | - break; |
|
1584 | - case '$': |
|
1585 | - $newToken['type'] = 'T_DOLLAR'; |
|
1586 | - break; |
|
1587 | - case '`': |
|
1588 | - $newToken['type'] = 'T_BACKTICK'; |
|
1589 | - break; |
|
1590 | - default: |
|
1591 | - $newToken['type'] = 'T_NONE'; |
|
1592 | - break; |
|
1512 | + case '{': |
|
1513 | + $newToken['type'] = 'T_OPEN_CURLY_BRACKET'; |
|
1514 | + break; |
|
1515 | + case '}': |
|
1516 | + $newToken['type'] = 'T_CLOSE_CURLY_BRACKET'; |
|
1517 | + break; |
|
1518 | + case '[': |
|
1519 | + $newToken['type'] = 'T_OPEN_SQUARE_BRACKET'; |
|
1520 | + break; |
|
1521 | + case ']': |
|
1522 | + $newToken['type'] = 'T_CLOSE_SQUARE_BRACKET'; |
|
1523 | + break; |
|
1524 | + case '(': |
|
1525 | + $newToken['type'] = 'T_OPEN_PARENTHESIS'; |
|
1526 | + break; |
|
1527 | + case ')': |
|
1528 | + $newToken['type'] = 'T_CLOSE_PARENTHESIS'; |
|
1529 | + break; |
|
1530 | + case ':': |
|
1531 | + $newToken['type'] = 'T_COLON'; |
|
1532 | + break; |
|
1533 | + case '.': |
|
1534 | + $newToken['type'] = 'T_STRING_CONCAT'; |
|
1535 | + break; |
|
1536 | + case '?': |
|
1537 | + $newToken['type'] = 'T_INLINE_THEN'; |
|
1538 | + break; |
|
1539 | + case ';': |
|
1540 | + $newToken['type'] = 'T_SEMICOLON'; |
|
1541 | + break; |
|
1542 | + case '=': |
|
1543 | + $newToken['type'] = 'T_EQUAL'; |
|
1544 | + break; |
|
1545 | + case '*': |
|
1546 | + $newToken['type'] = 'T_MULTIPLY'; |
|
1547 | + break; |
|
1548 | + case '/': |
|
1549 | + $newToken['type'] = 'T_DIVIDE'; |
|
1550 | + break; |
|
1551 | + case '+': |
|
1552 | + $newToken['type'] = 'T_PLUS'; |
|
1553 | + break; |
|
1554 | + case '-': |
|
1555 | + $newToken['type'] = 'T_MINUS'; |
|
1556 | + break; |
|
1557 | + case '%': |
|
1558 | + $newToken['type'] = 'T_MODULUS'; |
|
1559 | + break; |
|
1560 | + case '^': |
|
1561 | + $newToken['type'] = 'T_BITWISE_XOR'; |
|
1562 | + break; |
|
1563 | + case '&': |
|
1564 | + $newToken['type'] = 'T_BITWISE_AND'; |
|
1565 | + break; |
|
1566 | + case '|': |
|
1567 | + $newToken['type'] = 'T_BITWISE_OR'; |
|
1568 | + break; |
|
1569 | + case '<': |
|
1570 | + $newToken['type'] = 'T_LESS_THAN'; |
|
1571 | + break; |
|
1572 | + case '>': |
|
1573 | + $newToken['type'] = 'T_GREATER_THAN'; |
|
1574 | + break; |
|
1575 | + case '!': |
|
1576 | + $newToken['type'] = 'T_BOOLEAN_NOT'; |
|
1577 | + break; |
|
1578 | + case ',': |
|
1579 | + $newToken['type'] = 'T_COMMA'; |
|
1580 | + break; |
|
1581 | + case '@': |
|
1582 | + $newToken['type'] = 'T_ASPERAND'; |
|
1583 | + break; |
|
1584 | + case '$': |
|
1585 | + $newToken['type'] = 'T_DOLLAR'; |
|
1586 | + break; |
|
1587 | + case '`': |
|
1588 | + $newToken['type'] = 'T_BACKTICK'; |
|
1589 | + break; |
|
1590 | + default: |
|
1591 | + $newToken['type'] = 'T_NONE'; |
|
1592 | + break; |
|
1593 | 1593 | }//end switch |
1594 | 1594 | |
1595 | 1595 | $newToken['code'] = constant($newToken['type']); |
@@ -284,12 +284,32 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | switch ($token['code']) { |
287 | - case T_OPEN_CURLY_BRACKET: |
|
288 | - // Opening curly brackets for an At-rule do not start a style |
|
289 | - // definition. We also reset the asperand flag here because the next |
|
290 | - // opening curly bracket could be indeed the start of a style |
|
291 | - // definition. |
|
292 | - if ($asperandStart === true) { |
|
287 | + case T_OPEN_CURLY_BRACKET: |
|
288 | + // Opening curly brackets for an At-rule do not start a style |
|
289 | + // definition. We also reset the asperand flag here because the next |
|
290 | + // opening curly bracket could be indeed the start of a style |
|
291 | + // definition. |
|
292 | + if ($asperandStart === true) { |
|
293 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
294 | + if ($inStyleDef === true) { |
|
295 | + echo "\t\t* style definition closed *".PHP_EOL; |
|
296 | + } |
|
297 | + |
|
298 | + if ($asperandStart === true) { |
|
299 | + echo "\t\t* at-rule definition closed *".PHP_EOL; |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + $inStyleDef = false; |
|
304 | + $asperandStart = false; |
|
305 | + } else { |
|
306 | + $inStyleDef = true; |
|
307 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
308 | + echo "\t\t* style definition opened *".PHP_EOL; |
|
309 | + } |
|
310 | + } |
|
311 | + break; |
|
312 | + case T_CLOSE_CURLY_BRACKET: |
|
293 | 313 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
294 | 314 | if ($inStyleDef === true) { |
295 | 315 | echo "\t\t* style definition closed *".PHP_EOL; |
@@ -302,162 +322,142 @@ discard block |
||
302 | 322 | |
303 | 323 | $inStyleDef = false; |
304 | 324 | $asperandStart = false; |
305 | - } else { |
|
306 | - $inStyleDef = true; |
|
307 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
308 | - echo "\t\t* style definition opened *".PHP_EOL; |
|
309 | - } |
|
310 | - } |
|
311 | - break; |
|
312 | - case T_CLOSE_CURLY_BRACKET: |
|
313 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
314 | - if ($inStyleDef === true) { |
|
315 | - echo "\t\t* style definition closed *".PHP_EOL; |
|
316 | - } |
|
317 | - |
|
318 | - if ($asperandStart === true) { |
|
319 | - echo "\t\t* at-rule definition closed *".PHP_EOL; |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - $inStyleDef = false; |
|
324 | - $asperandStart = false; |
|
325 | - break; |
|
326 | - case T_MINUS: |
|
327 | - // Minus signs are often used instead of spaces inside |
|
328 | - // class names, IDs and styles. |
|
329 | - if ($finalTokens[($stackPtr + 1)]['code'] === T_STRING) { |
|
330 | - if ($finalTokens[($stackPtr - 1)]['code'] === T_STRING) { |
|
331 | - $newContent = $finalTokens[($stackPtr - 1)]['content'].'-'.$finalTokens[($stackPtr + 1)]['content']; |
|
332 | - |
|
325 | + break; |
|
326 | + case T_MINUS: |
|
327 | + // Minus signs are often used instead of spaces inside |
|
328 | + // class names, IDs and styles. |
|
329 | + if ($finalTokens[($stackPtr + 1)]['code'] === T_STRING) { |
|
330 | + if ($finalTokens[($stackPtr - 1)]['code'] === T_STRING) { |
|
331 | + $newContent = $finalTokens[($stackPtr - 1)]['content'].'-'.$finalTokens[($stackPtr + 1)]['content']; |
|
332 | + |
|
333 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
334 | + echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL; |
|
335 | + $old = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); |
|
336 | + $new = Util\Common::prepareForOutput($newContent); |
|
337 | + echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL; |
|
338 | + } |
|
339 | + |
|
340 | + $finalTokens[($stackPtr + 1)]['content'] = $newContent; |
|
341 | + unset($finalTokens[$stackPtr]); |
|
342 | + unset($finalTokens[($stackPtr - 1)]); |
|
343 | + } else { |
|
344 | + $newContent = '-'.$finalTokens[($stackPtr + 1)]['content']; |
|
345 | + |
|
346 | + $finalTokens[($stackPtr + 1)]['content'] = $newContent; |
|
347 | + unset($finalTokens[$stackPtr]); |
|
348 | + } |
|
349 | + } else if ($finalTokens[($stackPtr + 1)]['code'] === T_LNUMBER) { |
|
350 | + // They can also be used to provide negative numbers. |
|
333 | 351 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
334 | - echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL; |
|
335 | - $old = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); |
|
336 | - $new = Util\Common::prepareForOutput($newContent); |
|
337 | - echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL; |
|
352 | + echo "\t\t* token is part of a negative number; adding content to next token and ignoring *".PHP_EOL; |
|
353 | + $content = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); |
|
354 | + echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$content\" to \"-$content\"".PHP_EOL; |
|
338 | 355 | } |
339 | 356 | |
340 | - $finalTokens[($stackPtr + 1)]['content'] = $newContent; |
|
357 | + $finalTokens[($stackPtr + 1)]['content'] = '-'.$finalTokens[($stackPtr + 1)]['content']; |
|
341 | 358 | unset($finalTokens[$stackPtr]); |
342 | - unset($finalTokens[($stackPtr - 1)]); |
|
343 | - } else { |
|
344 | - $newContent = '-'.$finalTokens[($stackPtr + 1)]['content']; |
|
359 | + }//end if |
|
345 | 360 | |
346 | - $finalTokens[($stackPtr + 1)]['content'] = $newContent; |
|
347 | - unset($finalTokens[$stackPtr]); |
|
348 | - } |
|
349 | - } else if ($finalTokens[($stackPtr + 1)]['code'] === T_LNUMBER) { |
|
350 | - // They can also be used to provide negative numbers. |
|
351 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
352 | - echo "\t\t* token is part of a negative number; adding content to next token and ignoring *".PHP_EOL; |
|
353 | - $content = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); |
|
354 | - echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$content\" to \"-$content\"".PHP_EOL; |
|
355 | - } |
|
356 | - |
|
357 | - $finalTokens[($stackPtr + 1)]['content'] = '-'.$finalTokens[($stackPtr + 1)]['content']; |
|
358 | - unset($finalTokens[$stackPtr]); |
|
359 | - }//end if |
|
360 | - |
|
361 | - break; |
|
362 | - case T_COLON: |
|
363 | - // Only interested in colons that are defining styles. |
|
364 | - if ($inStyleDef === false) { |
|
365 | 361 | break; |
366 | - } |
|
367 | - |
|
368 | - for ($x = ($stackPtr - 1); $x >= 0; $x--) { |
|
369 | - if (isset(Util\Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) { |
|
362 | + case T_COLON: |
|
363 | + // Only interested in colons that are defining styles. |
|
364 | + if ($inStyleDef === false) { |
|
370 | 365 | break; |
371 | 366 | } |
372 | - } |
|
373 | 367 | |
374 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
375 | - $type = $finalTokens[$x]['type']; |
|
376 | - echo "\t\t=> token $x changed from $type to T_STYLE".PHP_EOL; |
|
377 | - } |
|
378 | - |
|
379 | - $finalTokens[$x]['type'] = 'T_STYLE'; |
|
380 | - $finalTokens[$x]['code'] = T_STYLE; |
|
381 | - break; |
|
382 | - case T_STRING: |
|
383 | - if (strtolower($token['content']) === 'url') { |
|
384 | - // Find the next content. |
|
385 | - for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { |
|
368 | + for ($x = ($stackPtr - 1); $x >= 0; $x--) { |
|
386 | 369 | if (isset(Util\Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) { |
387 | 370 | break; |
388 | 371 | } |
389 | 372 | } |
390 | 373 | |
391 | - // Needs to be in the format "url(" for it to be a URL. |
|
392 | - if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) { |
|
393 | - continue; |
|
374 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
375 | + $type = $finalTokens[$x]['type']; |
|
376 | + echo "\t\t=> token $x changed from $type to T_STYLE".PHP_EOL; |
|
394 | 377 | } |
395 | 378 | |
396 | - // Make sure the content isn't empty. |
|
397 | - for ($y = ($x + 1); $y < $numTokens; $y++) { |
|
398 | - if (isset(Util\Tokens::$emptyTokens[$finalTokens[$y]['code']]) === false) { |
|
399 | - break; |
|
379 | + $finalTokens[$x]['type'] = 'T_STYLE'; |
|
380 | + $finalTokens[$x]['code'] = T_STYLE; |
|
381 | + break; |
|
382 | + case T_STRING: |
|
383 | + if (strtolower($token['content']) === 'url') { |
|
384 | + // Find the next content. |
|
385 | + for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { |
|
386 | + if (isset(Util\Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) { |
|
387 | + break; |
|
388 | + } |
|
400 | 389 | } |
401 | - } |
|
402 | 390 | |
403 | - if ($finalTokens[$y]['code'] === T_CLOSE_PARENTHESIS) { |
|
404 | - continue; |
|
405 | - } |
|
406 | - |
|
407 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
408 | - for ($i = ($stackPtr + 1); $i <= $y; $i++) { |
|
409 | - $type = $finalTokens[$i]['type']; |
|
410 | - $content = Util\Common::prepareForOutput($finalTokens[$i]['content']); |
|
411 | - echo "\tProcess token $i: $type => $content".PHP_EOL; |
|
391 | + // Needs to be in the format "url(" for it to be a URL. |
|
392 | + if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) { |
|
393 | + continue; |
|
412 | 394 | } |
413 | 395 | |
414 | - echo "\t\t* token starts a URL *".PHP_EOL; |
|
415 | - } |
|
396 | + // Make sure the content isn't empty. |
|
397 | + for ($y = ($x + 1); $y < $numTokens; $y++) { |
|
398 | + if (isset(Util\Tokens::$emptyTokens[$finalTokens[$y]['code']]) === false) { |
|
399 | + break; |
|
400 | + } |
|
401 | + } |
|
416 | 402 | |
417 | - // Join all the content together inside the url() statement. |
|
418 | - $newContent = ''; |
|
419 | - for ($i = ($x + 2); $i < $numTokens; $i++) { |
|
420 | - if ($finalTokens[$i]['code'] === T_CLOSE_PARENTHESIS) { |
|
421 | - break; |
|
403 | + if ($finalTokens[$y]['code'] === T_CLOSE_PARENTHESIS) { |
|
404 | + continue; |
|
422 | 405 | } |
423 | 406 | |
424 | - $newContent .= $finalTokens[$i]['content']; |
|
425 | 407 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
426 | - $content = Util\Common::prepareForOutput($finalTokens[$i]['content']); |
|
427 | - echo "\t\t=> token $i added to URL string and ignored: $content".PHP_EOL; |
|
408 | + for ($i = ($stackPtr + 1); $i <= $y; $i++) { |
|
409 | + $type = $finalTokens[$i]['type']; |
|
410 | + $content = Util\Common::prepareForOutput($finalTokens[$i]['content']); |
|
411 | + echo "\tProcess token $i: $type => $content".PHP_EOL; |
|
412 | + } |
|
413 | + |
|
414 | + echo "\t\t* token starts a URL *".PHP_EOL; |
|
428 | 415 | } |
429 | 416 | |
430 | - unset($finalTokens[$i]); |
|
431 | - } |
|
417 | + // Join all the content together inside the url() statement. |
|
418 | + $newContent = ''; |
|
419 | + for ($i = ($x + 2); $i < $numTokens; $i++) { |
|
420 | + if ($finalTokens[$i]['code'] === T_CLOSE_PARENTHESIS) { |
|
421 | + break; |
|
422 | + } |
|
432 | 423 | |
433 | - $stackPtr = $i; |
|
424 | + $newContent .= $finalTokens[$i]['content']; |
|
425 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
426 | + $content = Util\Common::prepareForOutput($finalTokens[$i]['content']); |
|
427 | + echo "\t\t=> token $i added to URL string and ignored: $content".PHP_EOL; |
|
428 | + } |
|
434 | 429 | |
435 | - // If the content inside the "url()" is in double quotes |
|
436 | - // there will only be one token and so we don't have to do |
|
437 | - // anything except change its type. If it is not empty, |
|
438 | - // we need to do some token merging. |
|
439 | - $finalTokens[($x + 1)]['type'] = 'T_URL'; |
|
440 | - $finalTokens[($x + 1)]['code'] = T_URL; |
|
430 | + unset($finalTokens[$i]); |
|
431 | + } |
|
441 | 432 | |
442 | - if ($newContent !== '') { |
|
443 | - $finalTokens[($x + 1)]['content'] .= $newContent; |
|
444 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
445 | - $content = Util\Common::prepareForOutput($finalTokens[($x + 1)]['content']); |
|
446 | - echo "\t\t=> token content changed to: $content".PHP_EOL; |
|
433 | + $stackPtr = $i; |
|
434 | + |
|
435 | + // If the content inside the "url()" is in double quotes |
|
436 | + // there will only be one token and so we don't have to do |
|
437 | + // anything except change its type. If it is not empty, |
|
438 | + // we need to do some token merging. |
|
439 | + $finalTokens[($x + 1)]['type'] = 'T_URL'; |
|
440 | + $finalTokens[($x + 1)]['code'] = T_URL; |
|
441 | + |
|
442 | + if ($newContent !== '') { |
|
443 | + $finalTokens[($x + 1)]['content'] .= $newContent; |
|
444 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
445 | + $content = Util\Common::prepareForOutput($finalTokens[($x + 1)]['content']); |
|
446 | + echo "\t\t=> token content changed to: $content".PHP_EOL; |
|
447 | + } |
|
447 | 448 | } |
448 | - } |
|
449 | - }//end if |
|
449 | + }//end if |
|
450 | 450 | |
451 | - break; |
|
452 | - case T_ASPERAND: |
|
453 | - $asperandStart = true; |
|
454 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
455 | - echo "\t\t* at-rule definition opened *".PHP_EOL; |
|
456 | - } |
|
457 | - break; |
|
458 | - default: |
|
459 | - // Nothing special to be done with this token. |
|
460 | - break; |
|
451 | + break; |
|
452 | + case T_ASPERAND: |
|
453 | + $asperandStart = true; |
|
454 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
455 | + echo "\t\t* at-rule definition opened *".PHP_EOL; |
|
456 | + } |
|
457 | + break; |
|
458 | + default: |
|
459 | + // Nothing special to be done with this token. |
|
460 | + break; |
|
461 | 461 | }//end switch |
462 | 462 | }//end for |
463 | 463 |