SimpleFixer.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\Test\AbstractProxyFixerTest;
  13. use PhpCsFixer\Fixer\FixerInterface;
  14. use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
  15. use PhpCsFixer\Tokenizer\Tokens;
  16. /**
  17. * @internal
  18. */
  19. final class SimpleFixer implements FixerInterface
  20. {
  21. private bool $isCandidate;
  22. private bool $isRisky;
  23. private bool $supports;
  24. private int $priority;
  25. private int $fixCalled = 0;
  26. private static int $callCount = 1;
  27. public function __construct(
  28. bool $isCandidate,
  29. bool $isRisky = false,
  30. bool $supports = false,
  31. int $priority = 999
  32. ) {
  33. $this->isCandidate = $isCandidate;
  34. $this->isRisky = $isRisky;
  35. $this->supports = $supports;
  36. $this->priority = $priority;
  37. }
  38. public function fix(\SplFileInfo $file, Tokens $tokens): void
  39. {
  40. if (0 !== $this->fixCalled) {
  41. throw new \RuntimeException('Fixer called multiple times.');
  42. }
  43. $this->fixCalled = self::$callCount;
  44. ++self::$callCount;
  45. }
  46. public function getDefinition(): FixerDefinitionInterface
  47. {
  48. throw new \BadMethodCallException('Not implemented.');
  49. }
  50. public function getName(): string
  51. {
  52. return uniqid('abstract_proxy_test_');
  53. }
  54. public function getPriority(): int
  55. {
  56. return $this->priority;
  57. }
  58. public function isCandidate(Tokens $tokens): bool
  59. {
  60. return $this->isCandidate;
  61. }
  62. public function isFixCalled(): int
  63. {
  64. return $this->fixCalled;
  65. }
  66. public function isRisky(): bool
  67. {
  68. return $this->isRisky;
  69. }
  70. public function supports(\SplFileInfo $file): bool
  71. {
  72. return $this->supports;
  73. }
  74. }