DescribeFixtureFixer.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixtures\DescribeCommand;
  13. use PhpCsFixer\AbstractFixer;
  14. use PhpCsFixer\FixerDefinition\CodeSample;
  15. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16. use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
  17. use PhpCsFixer\Tokenizer\Token;
  18. use PhpCsFixer\Tokenizer\Tokens;
  19. final class DescribeFixtureFixer extends AbstractFixer
  20. {
  21. public function getName(): string
  22. {
  23. return 'Vendor/describe_fixture';
  24. }
  25. public function isCandidate(Tokens $tokens): bool
  26. {
  27. return $tokens->isTokenKindFound(T_CONSTANT_ENCAPSED_STRING);
  28. }
  29. public function getDefinition(): FixerDefinitionInterface
  30. {
  31. return new FixerDefinition(
  32. 'Fixture for describe command.',
  33. [
  34. new CodeSample(
  35. "<?php\necho 'describe fixture';\n"
  36. ),
  37. ],
  38. );
  39. }
  40. protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
  41. {
  42. for ($index = $tokens->count() - 1; $index > 0; --$index) {
  43. if (!$tokens[$index]->isGivenKind(T_CONSTANT_ENCAPSED_STRING)) {
  44. continue;
  45. }
  46. if ('\'describe fixture\'' !== strtolower($tokens[$index]->getContent())) {
  47. continue;
  48. }
  49. $tokens[$index] = new Token([T_CONSTANT_ENCAPSED_STRING, '\'fixture for describe\'']);
  50. }
  51. }
  52. }