Passed
Push — master ( 448c6e...d87c6c )
by Glynn
09:54 queued 08:08
created
src/Module/Route_Middleware.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 	protected Route_Manager $route_manager;
27 27
 
28
-	public function __construct( Route_Manager $route_manager ) {
28
+	public function __construct(Route_Manager $route_manager) {
29 29
 		$this->route_manager = $route_manager;
30 30
 	}
31 31
 
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
 	 * @param object $class
36 36
 	 * @return object
37 37
 	 */
38
-	public function process( object $class ): object {
38
+	public function process(object $class): object {
39 39
 
40
-		if ( is_a( $class, Route_Controller::class ) ) {
41
-			$routes = $class->get_routes( new Route_Collection() );
40
+		if (is_a($class, Route_Controller::class)) {
41
+			$routes = $class->get_routes(new Route_Collection());
42 42
 			$routes->each(
43
-				function( Abstract_Route $route ) {
44
-					if ( is_a( $route, Route::class ) ) {
45
-						$this->route_manager->from_route( $route );
43
+				function(Abstract_Route $route) {
44
+					if (is_a($route, Route::class)) {
45
+						$this->route_manager->from_route($route);
46 46
 						return;
47 47
 					}
48 48
 
49
-					if ( is_a( $route, Route_Group::class ) ) {
50
-						$this->route_manager->from_group( $route );
49
+					if (is_a($route, Route_Group::class)) {
50
+						$this->route_manager->from_group($route);
51 51
 						return;
52 52
 					}
53 53
 				}
Please login to merge, or discard this patch.
src/Module/Route.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@
 block discarded – undo
32 32
 	## Unused methods
33 33
 
34 34
 	/** @inheritDoc */
35
-	public function pre_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
35
+	public function pre_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
36 36
 
37 37
 	/** @inheritDoc */
38
-	public function post_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
38
+	public function post_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
39 39
 
40 40
 	/** @inheritDoc */
41
-	public function pre_boot( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
41
+	public function pre_boot(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
42 42
 }
Please login to merge, or discard this patch.
src/Route/Route_Group.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
 	protected Route_Factory $route_factory;
31 31
 	protected string $route;
32 32
 
33
-	public function __construct( string $namespace, string $route ) {
33
+	public function __construct(string $namespace, string $route) {
34 34
 		$this->route         = $route;
35 35
 		$this->namespace     = $namespace;
36
-		$this->route_factory = new Route_Factory( $namespace );
36
+		$this->route_factory = new Route_Factory($namespace);
37 37
 	}
38 38
 
39 39
 	/**
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callable
52 52
 	 * @return Route
53 53
 	 */
54
-	public function get( callable $callable ): Route {
55
-		$route = $this->route_factory->get( $this->route, $callable );
56
-		$route->namespace( $this->namespace );
57
-		$this->routes[ Route::GET ] = $route;
54
+	public function get(callable $callable): Route {
55
+		$route = $this->route_factory->get($this->route, $callable);
56
+		$route->namespace($this->namespace);
57
+		$this->routes[Route::GET] = $route;
58 58
 		return $route;
59 59
 	}
60 60
 
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callable
65 65
 	 * @return Route
66 66
 	 */
67
-	public function post( callable $callable ): Route {
68
-		$route = $this->route_factory->post( $this->route, $callable );
69
-		$route->namespace( $this->namespace );
70
-		$this->routes[ Route::POST ] = $route;
67
+	public function post(callable $callable): Route {
68
+		$route = $this->route_factory->post($this->route, $callable);
69
+		$route->namespace($this->namespace);
70
+		$this->routes[Route::POST] = $route;
71 71
 		return $route;
72 72
 	}
73 73
 
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callable
78 78
 	 * @return Route
79 79
 	 */
80
-	public function put( callable $callable ): Route {
81
-		$route = $this->route_factory->put( $this->route, $callable );
82
-		$route->namespace( $this->namespace );
83
-		$this->routes[ Route::PUT ] = $route;
80
+	public function put(callable $callable): Route {
81
+		$route = $this->route_factory->put($this->route, $callable);
82
+		$route->namespace($this->namespace);
83
+		$this->routes[Route::PUT] = $route;
84 84
 		return $route;
85 85
 	}
86 86
 
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callable
91 91
 	 * @return Route
92 92
 	 */
93
-	public function patch( callable $callable ): Route {
94
-		$route = $this->route_factory->patch( $this->route, $callable );
95
-		$route->namespace( $this->namespace );
96
-		$this->routes[ Route::PATCH ] = $route;
93
+	public function patch(callable $callable): Route {
94
+		$route = $this->route_factory->patch($this->route, $callable);
95
+		$route->namespace($this->namespace);
96
+		$this->routes[Route::PATCH] = $route;
97 97
 		return $route;
98 98
 	}
99 99
 
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callable
104 104
 	 * @return Route
105 105
 	 */
106
-	public function delete( callable $callable ): Route {
107
-		$route = $this->route_factory->delete( $this->route, $callable );
108
-		$route->namespace( $this->namespace );
109
-		$this->routes[ Route::DELETE ] = $route;
106
+	public function delete(callable $callable): Route {
107
+		$route = $this->route_factory->delete($this->route, $callable);
108
+		$route->namespace($this->namespace);
109
+		$this->routes[Route::DELETE] = $route;
110 110
 		return $route;
111 111
 	}
112 112
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 * @deprecated 0.0.2 This is not really used and should be removed in a future version.
118 118
 	 * @return self
119 119
 	 */
120
-	public function add_rest_route( Route $route ): self {
121
-		$this->routes[ $route->get_method() ] = $route;
120
+	public function add_rest_route(Route $route): self {
121
+		$this->routes[$route->get_method()] = $route;
122 122
 		return $this;
123 123
 	}
124 124
 
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @param string $method
138 138
 	 * @return bool
139 139
 	 */
140
-	public function method_exists( string $method ): bool {
141
-		return array_key_exists( \strtoupper( $method ), $this->routes );
140
+	public function method_exists(string $method): bool {
141
+		return array_key_exists(\strtoupper($method), $this->routes);
142 142
 	}
143 143
 
144 144
 	/**
@@ -147,6 +147,6 @@  discard block
 block discarded – undo
147 147
 	 * @return bool
148 148
 	 */
149 149
 	public function has_routes(): bool {
150
-		return ! empty( $this->routes );
150
+		return ! empty($this->routes);
151 151
 	}
152 152
 }
Please login to merge, or discard this patch.
src/Route/Abstract_Route.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param Argument $argument
57 57
 	 * @return static
58 58
 	 */
59
-	public function argument( Argument $argument ) {
60
-		$this->arguments[ $argument->get_key() ] = $argument;
59
+	public function argument(Argument $argument) {
60
+		$this->arguments[$argument->get_key()] = $argument;
61 61
 		return $this;
62 62
 	}
63 63
 
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 	 * @param string $key
68 68
 	 * @return bool
69 69
 	 */
70
-	public function has_argument( string $key ): bool {
71
-		return \array_key_exists( $key, $this->arguments );
70
+	public function has_argument(string $key): bool {
71
+		return \array_key_exists($key, $this->arguments);
72 72
 	}
73 73
 
74 74
 	/**
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * @param callable(WP_REST_Request $request):bool $auth_callback
78 78
 	 * @return static
79 79
 	 */
80
-	public function authentication( callable $auth_callback ) {
80
+	public function authentication(callable $auth_callback) {
81 81
 		$this->authentication[] = $auth_callback;
82 82
 		return $this;
83 83
 	}
Please login to merge, or discard this patch.
src/Route_Factory.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 	protected string $namespace;
22 22
 
23
-	public function __construct( string $namespace ) {
23
+	public function __construct(string $namespace) {
24 24
 		$this->namespace = $namespace;
25 25
 	}
26 26
 
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	 * @param string $namespace
31 31
 	 * @return Route_Factory
32 32
 	 */
33
-	public static function for( string $namespace ): Route_Factory {
34
-		return new self( $namespace );
33
+	public static function for (string $namespace): Route_Factory {
34
+		return new self($namespace);
35 35
 	}
36 36
 
37 37
 	/**
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callback
43 43
 	 * @return Route
44 44
 	 */
45
-	protected function request( string $method, string $route, callable $callback ): Route {
46
-		$route = new Route( $method, $route );
45
+	protected function request(string $method, string $route, callable $callback): Route {
46
+		$route = new Route($method, $route);
47 47
 		return $route
48
-			->callback( $callback )
49
-			->namespace( $this->namespace );
48
+			->callback($callback)
49
+			->namespace($this->namespace);
50 50
 	}
51 51
 
52 52
 	/**
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callback
57 57
 	 * @return Route
58 58
 	 */
59
-	public function get( string $route, callable $callback ): Route {
60
-		return $this->request( Route::GET, $route, $callback );
59
+	public function get(string $route, callable $callback): Route {
60
+		return $this->request(Route::GET, $route, $callback);
61 61
 	}
62 62
 
63 63
 	/**
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callback
68 68
 	 * @return Route
69 69
 	 */
70
-	public function post( string $route, callable $callback ): Route {
71
-		return $this->request( Route::POST, $route, $callback );
70
+	public function post(string $route, callable $callback): Route {
71
+		return $this->request(Route::POST, $route, $callback);
72 72
 	}
73 73
 
74 74
 	/**
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callback
79 79
 	 * @return Route
80 80
 	 */
81
-	public function put( string $route, callable $callback ): Route {
82
-		return $this->request( Route::PUT, $route, $callback );
81
+	public function put(string $route, callable $callback): Route {
82
+		return $this->request(Route::PUT, $route, $callback);
83 83
 	}
84 84
 
85 85
 	/**
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callback
90 90
 	 * @return Route
91 91
 	 */
92
-	public function patch( string $route, callable $callback ): Route {
93
-		return $this->request( Route::PATCH, $route, $callback );
92
+	public function patch(string $route, callable $callback): Route {
93
+		return $this->request(Route::PATCH, $route, $callback);
94 94
 	}
95 95
 
96 96
 	/**
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 	 * @param callable(\WP_REST_Request): (\WP_HTTP_Response|\WP_Error) $callback
101 101
 	 * @return Route
102 102
 	 */
103
-	public function delete( string $route, callable $callback ): Route {
104
-		return $this->request( Route::DELETE, $route, $callback );
103
+	public function delete(string $route, callable $callback): Route {
104
+		return $this->request(Route::DELETE, $route, $callback);
105 105
 	}
106 106
 
107 107
 	/**
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 	 * @param ?callable(Route_Group): void $config
112 112
 	 * @return Route_Group
113 113
 	 */
114
-	public function group_builder( string $route, ?callable $config ): Route_Group {
115
-		$group = new Route_Group( $this->namespace, $route );
114
+	public function group_builder(string $route, ?callable $config): Route_Group {
115
+		$group = new Route_Group($this->namespace, $route);
116 116
 
117 117
 		// Apply the callback.
118
-		if ( ! is_null( $config ) ) {
119
-			$config( $group );
118
+		if ( ! is_null($config)) {
119
+			$config($group);
120 120
 		}
121 121
 
122 122
 		return $group;
Please login to merge, or discard this patch.
src/Registration/Route_Manager.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	protected Hook_Loader $loader;
24 24
 	protected WP_Rest_Registrar $registrar;
25 25
 
26
-	public function __construct( WP_Rest_Registrar $registrar, Hook_Loader $hook_loader ) {
26
+	public function __construct(WP_Rest_Registrar $registrar, Hook_Loader $hook_loader) {
27 27
 		$this->loader    = $hook_loader;
28 28
 		$this->registrar = $registrar;
29 29
 	}
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
 	 * @param Route $route
35 35
 	 * @return self
36 36
 	 */
37
-	public function from_route( Route $route ): self {
37
+	public function from_route(Route $route): self {
38 38
 		$this->loader->action(
39 39
 			'rest_api_init',
40
-			$this->registrar->create_callback( $route )
40
+			$this->registrar->create_callback($route)
41 41
 		);
42 42
 
43 43
 		return $this;
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	 * @param \PinkCrab\Route\Route\Route_Group $group
50 50
 	 * @return self
51 51
 	 */
52
-	public function from_group( Route_Group $group ): self {
53
-		foreach ( $this->unpack_group( $group ) as $route ) {
54
-			$this->from_route( $route );
52
+	public function from_group(Route_Group $group): self {
53
+		foreach ($this->unpack_group($group) as $route) {
54
+			$this->from_route($route);
55 55
 		}
56 56
 
57 57
 		return $this;
@@ -64,31 +64,31 @@  discard block
 block discarded – undo
64 64
 	 * @return Route[]
65 65
 	 * @throws Route_Exception code 102
66 66
 	 */
67
-	protected function unpack_group( Route_Group $group ): array {
67
+	protected function unpack_group(Route_Group $group): array {
68 68
 
69 69
 		$routes = array();
70 70
 		// Loop through each group
71
-		foreach ( $group->get_rest_routes() as $method => $route ) {
72
-			$populated_route = $this->create_base_route_from_group( $method, $group );
71
+		foreach ($group->get_rest_routes() as $method => $route) {
72
+			$populated_route = $this->create_base_route_from_group($method, $group);
73 73
 
74 74
 			// Replace args if set.
75
-			foreach ( $route->get_arguments() as $key => $argument ) {
76
-				$populated_route->argument( $argument );
75
+			foreach ($route->get_arguments() as $key => $argument) {
76
+				$populated_route->argument($argument);
77 77
 			}
78 78
 
79 79
 			// Extends any group based authentication with a route based.
80
-			foreach ( $route->get_authentication() as $key => $auth_callback ) {
81
-				$populated_route->authentication( $auth_callback );
80
+			foreach ($route->get_authentication() as $key => $auth_callback) {
81
+				$populated_route->authentication($auth_callback);
82 82
 			}
83 83
 
84 84
 			// If we have no callback defined for route, throw.
85
-			if ( is_null( $route->get_callback() ) ) {
86
-				throw Route_Exception::callback_not_defined( $route );
85
+			if (is_null($route->get_callback())) {
86
+				throw Route_Exception::callback_not_defined($route);
87 87
 			}
88 88
 
89
-			$populated_route->callback( $route->get_callback() );
89
+			$populated_route->callback($route->get_callback());
90 90
 
91
-			$routes[ $method ] = $populated_route;
91
+			$routes[$method] = $populated_route;
92 92
 		}
93 93
 		return $routes;
94 94
 	}
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
 	 * @param Route_Group $group
103 103
 	 * @return Route
104 104
 	 */
105
-	protected function create_base_route_from_group( string $method, Route_Group $group ): Route {
106
-		$route = new Route( \strtoupper( $method ), $group->get_route() );
107
-		$route->namespace( $group->get_namespace() );
105
+	protected function create_base_route_from_group(string $method, Route_Group $group): Route {
106
+		$route = new Route(\strtoupper($method), $group->get_route());
107
+		$route->namespace($group->get_namespace());
108 108
 
109
-		foreach ( $group->get_authentication() as $auth_callback ) {
110
-			$route->authentication( $auth_callback );
109
+		foreach ($group->get_authentication() as $auth_callback) {
110
+			$route->authentication($auth_callback);
111 111
 		}
112 112
 
113
-		foreach ( $group->get_arguments() as $argument ) {
114
-			$route->argument( $argument );
113
+		foreach ($group->get_arguments() as $argument) {
114
+			$route->argument($argument);
115 115
 		}
116 116
 
117 117
 		return $route;
Please login to merge, or discard this patch.
src/Route_Controller.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 	 * @throws Route_Exception (code 101)
36 36
 	 */
37 37
 	private function get_namespace(): string {
38
-		if ( ! is_string( $this->namespace ) || mb_strlen( $this->namespace ) === 0 ) {
39
-			throw Route_Exception::namespace_not_defined( get_class( $this ) );
38
+		if ( ! is_string($this->namespace) || mb_strlen($this->namespace) === 0) {
39
+			throw Route_Exception::namespace_not_defined(get_class($this));
40 40
 		}
41 41
 
42 42
 		return $this->namespace;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 * @throws Route_Exception (code 101)
50 50
 	 */
51 51
 	private function get_factory(): Route_Factory {
52
-		return Route_Factory::for( $this->get_namespace() );
52
+		return Route_Factory::for ($this->get_namespace());
53 53
 	}
54 54
 
55 55
 	/**
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
 	 * @param Route_Collection $collection
59 59
 	 * @return Route_Collection
60 60
 	 */
61
-	final public function get_routes( Route_Collection $collection ): Route_Collection {
62
-		$routes = $this->define_routes( $this->get_factory() );
63
-		foreach ( $routes as $route ) {
64
-			$collection->add_route( $route );
61
+	final public function get_routes(Route_Collection $collection): Route_Collection {
62
+		$routes = $this->define_routes($this->get_factory());
63
+		foreach ($routes as $route) {
64
+			$collection->add_route($route);
65 65
 		}
66 66
 
67 67
 		return $collection;
@@ -73,6 +73,6 @@  discard block
 block discarded – undo
73 73
 	 * @param Route_Factory $factory
74 74
 	 * @return array<Route|Route_Group>
75 75
 	 */
76
-	abstract protected function define_routes( Route_Factory $factory): array;
76
+	abstract protected function define_routes(Route_Factory $factory): array;
77 77
 
78 78
 }
Please login to merge, or discard this patch.