@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * @param Argument $argument |
| 56 | 56 | * @return static |
| 57 | 57 | */ |
| 58 | - public function argument( Argument $argument ) { |
|
| 59 | - $this->arguments[ $argument->get_key() ] = $argument; |
|
| 58 | + public function argument(Argument $argument) { |
|
| 59 | + $this->arguments[$argument->get_key()] = $argument; |
|
| 60 | 60 | return $this; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | * @param string $key |
| 67 | 67 | * @return bool |
| 68 | 68 | */ |
| 69 | - public function has_argument( string $key ): bool { |
|
| 70 | - return \array_key_exists( $key, $this->arguments ); |
|
| 69 | + public function has_argument(string $key): bool { |
|
| 70 | + return \array_key_exists($key, $this->arguments); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param callable(\WP_REST_Request): bool $auth_callback |
| 77 | 77 | * @return static |
| 78 | 78 | */ |
| 79 | - public function authentication( callable $auth_callback ) { |
|
| 79 | + public function authentication(callable $auth_callback) { |
|
| 80 | 80 | $this->authentication[] = $auth_callback; |
| 81 | 81 | return $this; |
| 82 | 82 | } |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | * @return self |
| 25 | 25 | * @code 101 |
| 26 | 26 | */ |
| 27 | - public static function namespace_not_defined( string $route ): self { |
|
| 27 | + public static function namespace_not_defined(string $route): self { |
|
| 28 | 28 | return new self( |
| 29 | - sprintf( 'Namespace not defined in %s', $route ), |
|
| 29 | + sprintf('Namespace not defined in %s', $route), |
|
| 30 | 30 | 101 |
| 31 | 31 | ); |
| 32 | 32 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return self |
| 39 | 39 | * @code 102 |
| 40 | 40 | */ |
| 41 | - public static function callback_not_defined( Route $route ): self { |
|
| 41 | + public static function callback_not_defined(Route $route): self { |
|
| 42 | 42 | // Set the namespace if exists. |
| 43 | 43 | $namespace = '' !== $route->get_namespace() |
| 44 | 44 | ? $route->get_namespace() |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | return new self( |
| 48 | 48 | sprintf( |
| 49 | 49 | 'Callback not defined for [%s] %s%s', |
| 50 | - strtoupper( $route->get_method() ), |
|
| 51 | - strtoupper( $namespace ), |
|
| 52 | - strtoupper( $route->get_route() ) |
|
| 50 | + strtoupper($route->get_method()), |
|
| 51 | + strtoupper($namespace), |
|
| 52 | + strtoupper($route->get_route()) |
|
| 53 | 53 | ), |
| 54 | 54 | 102 |
| 55 | 55 | ); |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | * @param Route $route |
| 62 | 62 | * @return self |
| 63 | 63 | */ |
| 64 | - public static function invalid_http_method( Route $route ): self { |
|
| 64 | + public static function invalid_http_method(Route $route): self { |
|
| 65 | 65 | return new self( |
| 66 | 66 | sprintf( |
| 67 | 67 | '%s is a none supported HTTP Mehtod.', |
| 68 | - strtoupper( $route->get_method() ) |
|
| 68 | + strtoupper($route->get_method()) |
|
| 69 | 69 | ), |
| 70 | 70 | 103 |
| 71 | 71 | ); |
@@ -32,11 +32,11 @@ |
||
| 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 | } |
@@ -26,10 +26,10 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -20,7 +20,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -25,7 +25,7 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -35,8 +35,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |