TokenizerLintingResult.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\Linter;
  13. /**
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. *
  16. * @internal
  17. */
  18. final class TokenizerLintingResult implements LintingResultInterface
  19. {
  20. private ?\Error $error;
  21. public function __construct(?\Error $error = null)
  22. {
  23. $this->error = $error;
  24. }
  25. public function check(): void
  26. {
  27. if (null !== $this->error) {
  28. throw new LintingException(
  29. sprintf('%s: %s on line %d.', $this->getMessagePrefix(), $this->error->getMessage(), $this->error->getLine()),
  30. $this->error->getCode(),
  31. $this->error
  32. );
  33. }
  34. }
  35. private function getMessagePrefix(): string
  36. {
  37. return $this->error instanceof \ParseError ? 'Parse error' : 'Fatal error';
  38. }
  39. }