NumberFormatException.php 799 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. namespace Brick\Math\Exception;
  4. /**
  5. * Exception thrown when attempting to create a number from a string with an invalid format.
  6. */
  7. class NumberFormatException extends MathException
  8. {
  9. /**
  10. * @param string $char The failing character.
  11. *
  12. * @return NumberFormatException
  13. *
  14. * @psalm-pure
  15. */
  16. public static function charNotInAlphabet(string $char) : self
  17. {
  18. $ord = \ord($char);
  19. if ($ord < 32 || $ord > 126) {
  20. $char = \strtoupper(\dechex($ord));
  21. if ($ord < 10) {
  22. $char = '0' . $char;
  23. }
  24. } else {
  25. $char = '"' . $char . '"';
  26. }
  27. return new self(sprintf('Char %s is not a valid character in the given alphabet.', $char));
  28. }
  29. }