1+ <?php
2+
3+ namespace Nejcc \PhpDatatypes \Exceptions ;
4+
5+ use InvalidArgumentException as BaseInvalidArgumentException ;
6+
7+ class InvalidArgumentException extends BaseInvalidArgumentException
8+ {
9+ /**
10+ * Create a new invalid argument exception
11+ *
12+ * @param string $message The exception message
13+ * @param int $code The exception code
14+ * @param \Throwable|null $previous The previous exception
15+ */
16+ public function __construct (string $ message = "" , int $ code = 0 , ?\Throwable $ previous = null )
17+ {
18+ parent ::__construct ($ message , $ code , $ previous );
19+ }
20+
21+ /**
22+ * Create an exception for invalid component count
23+ *
24+ * @param int $expected Expected number of components
25+ * @param int $actual Actual number of components
26+ * @return self
27+ */
28+ public static function invalidComponentCount (int $ expected , int $ actual ): self
29+ {
30+ return new self (sprintf (
31+ 'Invalid number of components. Expected %d, got %d ' ,
32+ $ expected ,
33+ $ actual
34+ ));
35+ }
36+
37+ /**
38+ * Create an exception for non-numeric components
39+ *
40+ * @param array $components The invalid components
41+ * @return self
42+ */
43+ public static function nonNumericComponents (array $ components ): self
44+ {
45+ return new self (sprintf (
46+ 'All components must be numeric. Got: %s ' ,
47+ implode (', ' , array_map ('gettype ' , $ components ))
48+ ));
49+ }
50+
51+ /**
52+ * Create an exception for different dimensions
53+ *
54+ * @param int $expected Expected dimension
55+ * @param int $actual Actual dimension
56+ * @return self
57+ */
58+ public static function differentDimensions (int $ expected , int $ actual ): self
59+ {
60+ return new self (sprintf (
61+ 'Vectors must have the same dimension. Expected %d, got %d ' ,
62+ $ expected ,
63+ $ actual
64+ ));
65+ }
66+ }
0 commit comments