| Total Complexity | 4 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class Route_Exception extends Exception { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Returns Route_Exception for namespace not defined. |
||
| 22 | * |
||
| 23 | * @param string $route |
||
| 24 | * @return self |
||
| 25 | * @code 101 |
||
| 26 | */ |
||
| 27 | public static function namespace_not_defined( string $route ): self { |
||
| 28 | return new self( |
||
| 29 | sprintf( 'Namespace not defined in %s', $route ), |
||
| 30 | 101 |
||
| 31 | ); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Returns an exception for a route with no callback defined. |
||
| 36 | * |
||
| 37 | * @param Route $route |
||
| 38 | * @return self |
||
| 39 | * @code 102 |
||
| 40 | */ |
||
| 41 | public static function callback_not_defined( Route $route ): self { |
||
| 42 | // Set the namespace if exists. |
||
| 43 | $namespace = '' !== $route->get_namespace() |
||
| 44 | ? $route->get_namespace() |
||
| 45 | : '_MISSING_NAMESPACE_'; |
||
| 46 | |||
| 47 | return new self( |
||
| 48 | sprintf( |
||
| 49 | 'Callback not defined for [%s] %s%s', |
||
| 50 | strtoupper( $route->get_method() ), |
||
| 51 | strtoupper( $namespace ), |
||
| 52 | strtoupper( $route->get_route() ) |
||
| 53 | ), |
||
| 54 | 102 |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns an exception for a route with an invlaid/unsupported HTTP method. |
||
| 60 | * |
||
| 61 | * @param Route $route |
||
| 62 | * @return self |
||
| 63 | */ |
||
| 64 | public static function invalid_http_method( Route $route ): self { |
||
| 71 | ); |
||
| 72 | } |
||
| 73 | } |
||
| 74 |