ParseErrorException.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * This file is part of the Carbon package.
  4. *
  5. * (c) Brian Nesbitt <brian@nesbot.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Carbon\Exceptions;
  11. use InvalidArgumentException as BaseInvalidArgumentException;
  12. use Throwable;
  13. class ParseErrorException extends BaseInvalidArgumentException implements InvalidArgumentException
  14. {
  15. /**
  16. * The expected.
  17. *
  18. * @var string
  19. */
  20. protected $expected;
  21. /**
  22. * The actual.
  23. *
  24. * @var string
  25. */
  26. protected $actual;
  27. /**
  28. * The help message.
  29. *
  30. * @var string
  31. */
  32. protected $help;
  33. /**
  34. * Constructor.
  35. *
  36. * @param string $expected
  37. * @param string $actual
  38. * @param int $code
  39. * @param Throwable|null $previous
  40. */
  41. public function __construct($expected, $actual, $help = '', $code = 0, Throwable $previous = null)
  42. {
  43. $this->expected = $expected;
  44. $this->actual = $actual;
  45. $this->help = $help;
  46. $actual = $actual === '' ? 'data is missing' : "get '$actual'";
  47. parent::__construct(trim("Format expected $expected but $actual\n$help"), $code, $previous);
  48. }
  49. /**
  50. * Get the expected.
  51. *
  52. * @return string
  53. */
  54. public function getExpected(): string
  55. {
  56. return $this->expected;
  57. }
  58. /**
  59. * Get the actual.
  60. *
  61. * @return string
  62. */
  63. public function getActual(): string
  64. {
  65. return $this->actual;
  66. }
  67. /**
  68. * Get the help message.
  69. *
  70. * @return string
  71. */
  72. public function getHelp(): string
  73. {
  74. return $this->help;
  75. }
  76. }