Passed
Pull Request — master (#45)
by Glynn
08:31
created
src/Registration/WP_Rest_Registrar.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -26,10 +26,10 @@  discard block
 block discarded – undo
26 26
 	 * @param \PinkCrab\Route\Route\Route $route
27 27
 	 * @return callable
28 28
 	 */
29
-	public function create_callback( Route $route ): callable { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
30
-		return function () use ( $route ): void {
31
-			$model = $this->map_to_wp_rest( $route );
32
-			register_rest_route( $model->namespace, $model->route, $model->args );
29
+	public function create_callback(Route $route): callable { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
30
+		return function() use ($route): void {
31
+			$model = $this->map_to_wp_rest($route);
32
+			register_rest_route($model->namespace, $model->route, $model->args);
33 33
 		};
34 34
 	}
35 35
 
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	 * @param \PinkCrab\Route\Route\Route $route
40 40
 	 * @return WP_Rest_Route
41 41
 	 */
42
-	public function map_to_wp_rest( Route $route ): WP_Rest_Route { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
42
+	public function map_to_wp_rest(Route $route): WP_Rest_Route { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
43 43
 		$wp_rest            = new WP_Rest_Route();
44 44
 		$wp_rest->namespace = $route->get_namespace();
45 45
 		$wp_rest->route     = $route->get_route();
46
-		$wp_rest->args      = $this->parse_options( $route );
46
+		$wp_rest->args      = $this->parse_options($route);
47 47
 		return $wp_rest;
48 48
 	}
49 49
 
@@ -54,23 +54,23 @@  discard block
 block discarded – undo
54 54
 	 * @return array<mixed>
55 55
 	 * @throws Route_Exception
56 56
 	 */
57
-	protected function parse_options( Route $route ): array {
57
+	protected function parse_options(Route $route): array {
58 58
 
59 59
 		// If we have no callback defined for route, throw.
60
-		if ( is_null( $route->get_callback() ) ) {
61
-			throw Route_Exception::callback_not_defined( $route ); // phpcs:ignore 
60
+		if (is_null($route->get_callback())) {
61
+			throw Route_Exception::callback_not_defined($route); // phpcs:ignore 
62 62
 		}
63 63
 
64 64
 		// If we have an invlaid method, throw
65
-		if ( ! $this->is_valid_method( $route->get_method() ) ) {
66
-			throw Route_Exception::invalid_http_method( $route ); // phpcs:ignore 
65
+		if ( ! $this->is_valid_method($route->get_method())) {
66
+			throw Route_Exception::invalid_http_method($route); // phpcs:ignore 
67 67
 		}
68 68
 
69 69
 		$options                        = array();
70 70
 		$options['methods']             = $route->get_method();
71 71
 		$options['callback']            = $route->get_callback();
72
-		$options['permission_callback'] = $this->compose_permission_callback( $route );
73
-		$options['args']                = $this->parse_args( $route );
72
+		$options['permission_callback'] = $this->compose_permission_callback($route);
73
+		$options['args']                = $this->parse_args($route);
74 74
 
75 75
 		return $options;
76 76
 	}
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
 	 * @param Route $route
82 82
 	 * @return array<mixed>
83 83
 	 */
84
-	protected function parse_args( Route $route ): array { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
84
+	protected function parse_args(Route $route): array { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
85 85
 		return array_reduce(
86 86
 			$route->get_arguments(),
87
-			function ( array $args, Argument $argument ) {
88
-				$args[ $argument->get_key() ] = Argument_Parser::as_single( $argument );
87
+			function(array $args, Argument $argument) {
88
+				$args[$argument->get_key()] = Argument_Parser::as_single($argument);
89 89
 				return $args;
90 90
 			},
91 91
 			array()
@@ -98,12 +98,12 @@  discard block
 block discarded – undo
98 98
 	 * @param string $method
99 99
 	 * @return boolean
100 100
 	 */
101
-	protected function is_valid_method( string $method ): bool {
101
+	protected function is_valid_method(string $method): bool {
102 102
 		return in_array(
103 103
 			$method,
104 104
 			apply_filters(
105 105
 				'pinkcrab/route/accepted_http_methods', // phpcs:ignore WordPress.NamingConventions.ValidHookName
106
-				array( Route::DELETE, Route::POST, Route::PUT, Route::PATCH, Route::GET )
106
+				array(Route::DELETE, Route::POST, Route::PUT, Route::PATCH, Route::GET)
107 107
 			),
108 108
 			true
109 109
 		);
@@ -115,19 +115,19 @@  discard block
 block discarded – undo
115 115
 	 * @param Route $route
116 116
 	 * @return callable
117 117
 	 */
118
-	protected function compose_permission_callback( Route $route ): callable {
118
+	protected function compose_permission_callback(Route $route): callable {
119 119
 		$callbacks = $route->get_authentication();
120 120
 
121 121
 		// If we have no callback defined, use return true.
122
-		if ( count( $callbacks ) === 0 ) {
122
+		if (count($callbacks) === 0) {
123 123
 			return '__return_true';
124 124
 		}
125 125
 
126 126
 		// If we only have 1, return as is.
127
-		if ( count( $callbacks ) === 1 ) {
128
-			return reset( $callbacks );
127
+		if (count($callbacks) === 1) {
128
+			return reset($callbacks);
129 129
 		}
130 130
 
131
-		return all( ...$callbacks );
131
+		return all(...$callbacks);
132 132
 	}
133 133
 }
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 ); // phpcs:ignore
85
+			if (is_null($route->get_callback())) {
86
+				throw Route_Exception::callback_not_defined($route); // phpcs:ignore
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_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 ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
23
+	public function __construct(string $namespace) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
34
-		return new self( $namespace );
33
+	public static function for (string $namespace): Route_Factory { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
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/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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound
38
+	public function process(object $class): object { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound
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/Route_Collection.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 
19 19
 class Route_Collection extends Collection {
20 20
 
21
-	protected const ALLOWED_ROUTE_TYPES = array( Route::class, Route_Group::class );
21
+	protected const ALLOWED_ROUTE_TYPES = array(Route::class, Route_Group::class);
22 22
 
23 23
 	/**
24 24
 	 * Overwrite this method in any extended classes, to modify the inital data.
@@ -26,12 +26,12 @@  discard block
 block discarded – undo
26 26
 	 * @param array<int|string, mixed> $data
27 27
 	 * @return array<int|string, mixed>
28 28
 	 */
29
-	protected function map_construct( array $data ): array {
29
+	protected function map_construct(array $data): array {
30 30
 		return array_filter(
31 31
 			$data,
32
-			function ( $datum ): bool {
32
+			function($datum): bool {
33 33
 				return in_array(
34
-					esc_attr( get_class( $datum ) ?: '' ), // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
34
+					esc_attr(get_class($datum) ?: ''), // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
35 35
 					self::ALLOWED_ROUTE_TYPES,
36 36
 					true
37 37
 				);
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
 	 * @param Route|Route_Group $route
46 46
 	 * @return static
47 47
 	 */
48
-	public function add_route( $route ) {
49
-		$this->push( $route );
48
+	public function add_route($route) {
49
+		$this->push($route);
50 50
 		return $this;
51 51
 	}
52 52
 }
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( \esc_html( get_class( $this ) ) );
38
+		if ( ! is_string($this->namespace) || mb_strlen($this->namespace) === 0) {
39
+			throw Route_Exception::namespace_not_defined(\esc_html(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,5 +73,5 @@  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
 }
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 ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
33
+	public function __construct(string $namespace, string $route) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.callableFound
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 boolean
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 boolean
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/Route.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 	protected $callback = null;
37 37
 
38 38
 
39
-	public function __construct( string $method, string $route ) {
39
+	public function __construct(string $method, string $route) {
40 40
 		$this->method = $method;
41
-		$this->route  = $this->format_route( $route );
41
+		$this->route  = $this->format_route($route);
42 42
 	}
43 43
 
44 44
 	/**
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 	 * @param string $route
48 48
 	 * @return string
49 49
 	 */
50
-	protected function format_route( string $route ): string {
51
-		$route = $this->translate_arguments( $route );
52
-		return '/' . ltrim( $route, '/\\' );
50
+	protected function format_route(string $route): string {
51
+		$route = $this->translate_arguments($route);
52
+		return '/'.ltrim($route, '/\\');
53 53
 	}
54 54
 
55 55
 	/**
@@ -59,27 +59,27 @@  discard block
 block discarded – undo
59 59
 	 * @param string $route
60 60
 	 * @return string
61 61
 	 */
62
-	protected function translate_arguments( string $route ): string {
63
-		if ( preg_match( '/[^-:\/_{}()a-zA-Z\d]/', $route ) ) {
62
+	protected function translate_arguments(string $route): string {
63
+		if (preg_match('/[^-:\/_{}()a-zA-Z\d]/', $route)) {
64 64
 			return $route;
65 65
 		}
66 66
 
67 67
 		// Create capture group for ":parameter"
68 68
 		$allowed_chars = '[\@a-zA-Z0-9&.?:-_=#]*';
69 69
 		$route         = preg_replace(
70
-			'/:(' . $allowed_chars . ')/',
71
-			'(?<$1>' . $allowed_chars . ')',
70
+			'/:('.$allowed_chars.')/',
71
+			'(?<$1>'.$allowed_chars.')',
72 72
 			$route
73 73
 		);
74 74
 
75 75
 		// Create capture group for '{parameter}'
76 76
 		$route = preg_replace(
77
-			'/{(' . $allowed_chars . ')}/',
78
-			'(?<$1>' . $allowed_chars . ')',
79
-			is_string( $route ) ? $route : ''
77
+			'/{('.$allowed_chars.')}/',
78
+			'(?<$1>'.$allowed_chars.')',
79
+			is_string($route) ? $route : ''
80 80
 		);
81 81
 
82
-		return is_string( $route ) ? $route : '';
82
+		return is_string($route) ? $route : '';
83 83
 	}
84 84
 
85 85
 	/**
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @return self
100 100
 	 */
101
-	public function callback( callable $callback ): self {
101
+	public function callback(callable $callback): self {
102 102
 		$this->callback = $callback;
103 103
 		return $this;
104 104
 	}
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	 * @param string $namespace
128 128
 	 * @return static
129 129
 	 */
130
-	public function namespace( string $namespace ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
130
+	public function namespace(string $namespace) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
131 131
 		$this->namespace = $namespace;
132 132
 		return $this;
133 133
 	}
@@ -138,27 +138,27 @@  discard block
 block discarded – undo
138 138
 	 * @param string $method
139 139
 	 * @return self
140 140
 	 */
141
-	public function with_method( string $method ): self {
142
-		$clone = new self( $method, $this->get_route() );
141
+	public function with_method(string $method): self {
142
+		$clone = new self($method, $this->get_route());
143 143
 		// Arguments
144
-		if ( ! empty( $this->arguments ) ) {
145
-			foreach ( $this->arguments as $argument ) {
146
-				$clone->argument( $argument );
144
+		if ( ! empty($this->arguments)) {
145
+			foreach ($this->arguments as $argument) {
146
+				$clone->argument($argument);
147 147
 			}
148 148
 		}
149 149
 		// Authentication
150
-		if ( ! empty( $this->authentication ) ) {
151
-			foreach ( $this->authentication as $authentication ) {
152
-				$clone->authentication( $authentication );
150
+		if ( ! empty($this->authentication)) {
151
+			foreach ($this->authentication as $authentication) {
152
+				$clone->authentication($authentication);
153 153
 			}
154 154
 		}
155 155
 		// Callback
156
-		if ( ! empty( $this->callback ) ) {
157
-			$clone->callback( $this->callback );
156
+		if ( ! empty($this->callback)) {
157
+			$clone->callback($this->callback);
158 158
 		}
159 159
 		// Namespace
160
-		if ( ! empty( $this->namespace ) ) {
161
-			$clone->namespace( $this->namespace );
160
+		if ( ! empty($this->namespace)) {
161
+			$clone->namespace($this->namespace);
162 162
 		}
163 163
 
164 164
 		return $clone;
Please login to merge, or discard this patch.