@@ -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 |
@@ -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 |
@@ -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 'Symplify\PHP7_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('Symplify\PHP7_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 'Symplify\PHP7_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('Symplify\PHP7_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('Symplify\PHP7_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('Symplify\PHP7_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() |