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