@@ -45,11 +45,10 @@ class WP_REST_Abilities_Run_Controller extends WP_REST_Controller {
4545 * Registers the routes for ability execution.
4646 *
4747 * @since 0.1.0
48- * @return void
4948 *
5049 * @see register_rest_route()
5150 */
52- public function register_routes () {
51+ public function register_routes (): void {
5352 register_rest_route (
5453 $ this ->namespace ,
5554 '/ ' . $ this ->rest_base . '/(?P<id>[a-zA-Z0-9\-\/]+?)/run ' ,
@@ -87,11 +86,11 @@ public function register_routes() {
8786 * @param \WP_REST_Request $request Full details about the request.
8887 * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
8988 */
90- public function run_ability_with_method_check ( $ request ) {
89+ public function run_ability_with_method_check ( \ WP_REST_Request $ request ) {
9190 $ ability = wp_get_ability ( $ request ['id ' ] );
9291
9392 if ( ! $ ability ) {
94- return new WP_Error (
93+ return new \ WP_Error (
9594 'rest_ability_not_found ' ,
9695 __ ( 'Ability not found. ' , 'abilities-api ' ),
9796 array ( 'status ' => 404 )
@@ -104,13 +103,15 @@ public function run_ability_with_method_check( $request ) {
104103 $ method = $ request ->get_method ();
105104
106105 if ( 'resource ' === $ type && 'GET ' !== $ method ) {
107- return new WP_Error (
106+ return new \ WP_Error (
108107 'rest_invalid_method ' ,
109108 __ ( 'Resource abilities require GET method. ' , 'abilities-api ' ),
110109 array ( 'status ' => 405 )
111110 );
112- } elseif ( 'POST ' !== $ method ) {
113- return new WP_Error (
111+ }
112+
113+ if ( 'POST ' !== $ method ) {
114+ return new \WP_Error (
114115 'rest_invalid_method ' ,
115116 __ ( 'Tool abilities require POST method. ' , 'abilities-api ' ),
116117 array ( 'status ' => 405 )
@@ -128,11 +129,11 @@ public function run_ability_with_method_check( $request ) {
128129 * @param \WP_REST_Request $request Full details about the request.
129130 * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
130131 */
131- public function run_ability ( $ request ) {
132+ public function run_ability ( \ WP_REST_Request $ request ) {
132133 $ ability = wp_get_ability ( $ request ['id ' ] );
133134
134135 if ( ! $ ability ) {
135- return new WP_Error (
136+ return new \ WP_Error (
136137 'rest_ability_not_found ' ,
137138 __ ( 'Ability not found. ' , 'abilities-api ' ),
138139 array ( 'status ' => 404 )
@@ -154,15 +155,15 @@ public function run_ability( $request ) {
154155 $ result = $ ability ->execute ( $ input );
155156
156157 if ( is_wp_error ( $ result ) ) {
157- return new WP_Error (
158+ return new \ WP_Error (
158159 'rest_ability_execution_failed ' ,
159160 $ result ->get_error_message (),
160161 array ( 'status ' => 500 )
161162 );
162163 }
163164
164165 if ( is_null ( $ result ) ) {
165- return new WP_Error (
166+ return new \ WP_Error (
166167 'rest_ability_execution_failed ' ,
167168 __ ( 'Ability execution failed. Please check permissions and input parameters. ' , 'abilities-api ' ),
168169 array ( 'status ' => 500 )
@@ -185,11 +186,11 @@ public function run_ability( $request ) {
185186 * @param \WP_REST_Request $request Full details about the request.
186187 * @return true|\WP_Error True if the request has execution permission, WP_Error object otherwise.
187188 */
188- public function run_ability_permissions_check ( $ request ) {
189+ public function run_ability_permissions_check ( \ WP_REST_Request $ request ) {
189190 $ ability = wp_get_ability ( $ request ['id ' ] );
190191
191192 if ( ! $ ability ) {
192- return new WP_Error (
193+ return new \ WP_Error (
193194 'rest_ability_not_found ' ,
194195 __ ( 'Ability not found. ' , 'abilities-api ' ),
195196 array ( 'status ' => 404 )
@@ -204,7 +205,7 @@ public function run_ability_permissions_check( $request ) {
204205 }
205206
206207 if ( ! $ ability ->has_permission ( $ input ) ) {
207- return new WP_Error (
208+ return new \ WP_Error (
208209 'rest_cannot_execute ' ,
209210 __ ( 'Sorry, you are not allowed to execute this ability. ' , 'abilities-api ' ),
210211 array ( 'status ' => rest_authorization_required_code () )
@@ -223,7 +224,7 @@ public function run_ability_permissions_check( $request ) {
223224 * @param array<string, mixed> $input The input data to validate.
224225 * @return true|\WP_Error True if validation passes, WP_Error object on failure.
225226 */
226- private function validate_input ( $ ability , $ input ) {
227+ private function validate_input ( \ WP_Ability $ ability , array $ input ) {
227228 $ input_schema = $ ability ->get_input_schema ();
228229
229230 if ( empty ( $ input_schema ) ) {
@@ -232,7 +233,7 @@ private function validate_input( $ability, $input ) {
232233
233234 $ validation_result = rest_validate_value_from_schema ( $ input , $ input_schema );
234235 if ( is_wp_error ( $ validation_result ) ) {
235- return new WP_Error (
236+ return new \ WP_Error (
236237 'rest_invalid_param ' ,
237238 sprintf (
238239 /* translators: %s: error message */
@@ -255,7 +256,7 @@ private function validate_input( $ability, $input ) {
255256 * @param mixed $output The output data to validate.
256257 * @return true|\WP_Error True if validation passes, WP_Error object on failure.
257258 */
258- private function validate_output ( $ ability , $ output ) {
259+ private function validate_output ( \ WP_Ability $ ability , $ output ) {
259260 $ output_schema = $ ability ->get_output_schema ();
260261
261262 if ( empty ( $ output_schema ) ) {
@@ -264,7 +265,7 @@ private function validate_output( $ability, $output ) {
264265
265266 $ validation_result = rest_validate_value_from_schema ( $ output , $ output_schema );
266267 if ( is_wp_error ( $ validation_result ) ) {
267- return new WP_Error (
268+ return new \ WP_Error (
268269 'rest_invalid_response ' ,
269270 sprintf (
270271 /* translators: %s: error message */
@@ -285,7 +286,7 @@ private function validate_output( $ability, $output ) {
285286 *
286287 * @return array<string, mixed> Arguments for the run endpoint.
287288 */
288- public function get_run_args () {
289+ public function get_run_args (): array {
289290 return array (
290291 'input ' => array (
291292 'description ' => __ ( 'Input parameters for the ability execution. ' , 'abilities-api ' ),
@@ -302,7 +303,7 @@ public function get_run_args() {
302303 *
303304 * @return array<string, mixed> Schema for the run endpoint.
304305 */
305- public function get_run_schema () {
306+ public function get_run_schema (): array {
306307 return array (
307308 '$schema ' => 'http://json-schema.org/draft-04/schema# ' ,
308309 'title ' => 'ability-execution ' ,
0 commit comments