Debian Codegraph @

lib/3rdParty/composer/brick/math/src/Exception/NumberFormatException.php

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