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