Route_Exception   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 53
rs 10
c 3
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A invalid_http_method() 0 7 1
A callback_not_defined() 0 14 2
A namespace_not_defined() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Route Exceptions
7
 *
8
 * @package PinkCrab\Route\Route
9
 * @author Glynn Quelch [email protected]
10
 * @since 0.0.1
11
 */
12
13
namespace PinkCrab\Route;
14
15
use Exception;
16
use PinkCrab\Route\Route\Route;
17
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 {
65
		return new self(
66
			sprintf(
67
				'%s is a none supported HTTP Mehtod.',
68
				strtoupper( $route->get_method() )
69
			),
70
			103
71
		);
72
	}
73
}
74