| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace Dudlewebs\WPMCS\GCP\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 |
public static function invalidFormat(string $value) : self |
| 12 |
{ |
| 13 |
return new self(\sprintf('The given value "%s" does not represent a valid number.', $value)); |
| 14 |
} |
| 15 |
/** |
| 16 |
* @param string $char The failing character. |
| 17 |
* |
| 18 |
* @psalm-pure |
| 19 |
*/ |
| 20 |
public static function charNotInAlphabet(string $char) : self |
| 21 |
{ |
| 22 |
$ord = \ord($char); |
| 23 |
if ($ord < 32 || $ord > 126) { |
| 24 |
$char = \strtoupper(\dechex($ord)); |
| 25 |
if ($ord < 10) { |
| 26 |
$char = '0' . $char; |
| 27 |
} |
| 28 |
} else { |
| 29 |
$char = '"' . $char . '"'; |
| 30 |
} |
| 31 |
return new self(\sprintf('Char %s is not a valid character in the given alphabet.', $char)); |
| 32 |
} |
| 33 |
} |
| 34 |
|