1
- <?php declare ( strict_types = 1 );
2
-
1
+ <?php
3
2
/**
4
3
* Abilities API
5
4
*
10
9
* @since 0.1.0
11
10
*/
12
11
12
+ declare ( strict_types = 1 );
13
+
13
14
/**
14
15
* Encapsulates the properties and methods related to a specific ability in the registry.
15
16
*
@@ -49,15 +50,15 @@ class WP_Ability {
49
50
* The optional ability input schema.
50
51
*
51
52
* @since 0.1.0
52
- * @var array
53
+ * @var array<string,mixed>
53
54
*/
54
55
protected $ input_schema = array ();
55
56
56
57
/**
57
58
* The optional ability output schema.
58
59
*
59
60
* @since 0.1.0
60
- * @var array
61
+ * @var array<string,mixed>
61
62
*/
62
63
protected $ output_schema = array ();
63
64
@@ -81,7 +82,7 @@ class WP_Ability {
81
82
* The optional ability metadata.
82
83
*
83
84
* @since 0.1.0
84
- * @var array
85
+ * @var array<string,mixed>
85
86
*/
86
87
protected $ meta = array ();
87
88
@@ -94,10 +95,10 @@ class WP_Ability {
94
95
*
95
96
* @since 0.1.0
96
97
*
97
- * @param string $name The name of the ability, with its namespace.
98
- * @param array $properties An associative array of properties for the ability. This should
99
- * include `label`, `description`, `input_schema`, `output_schema`,
100
- * `execute_callback`, `permission_callback`, and `meta`.
98
+ * @param string $name The name of the ability, with its namespace.
99
+ * @param array<string,mixed> $properties An associative array of properties for the ability. This should
100
+ * include `label`, `description`, `input_schema`, `output_schema`,
101
+ * `execute_callback`, `permission_callback`, and `meta`.
101
102
*/
102
103
public function __construct ( string $ name , array $ properties ) {
103
104
$ this ->name = $ name ;
@@ -145,7 +146,7 @@ public function get_description(): string {
145
146
*
146
147
* @since 0.1.0
147
148
*
148
- * @return array The input schema for the ability.
149
+ * @return array<string,mixed> The input schema for the ability.
149
150
*/
150
151
public function get_input_schema (): array {
151
152
return $ this ->input_schema ;
@@ -156,7 +157,7 @@ public function get_input_schema(): array {
156
157
*
157
158
* @since 0.1.0
158
159
*
159
- * @return array The output schema for the ability.
160
+ * @return array<string,mixed> The output schema for the ability.
160
161
*/
161
162
public function get_output_schema (): array {
162
163
return $ this ->output_schema ;
@@ -167,7 +168,7 @@ public function get_output_schema(): array {
167
168
*
168
169
* @since 0.1.0
169
170
*
170
- * @return array The metadata for the ability.
171
+ * @return array<string,mixed> The metadata for the ability.
171
172
*/
172
173
public function get_meta (): array {
173
174
return $ this ->meta ;
@@ -178,7 +179,7 @@ public function get_meta(): array {
178
179
*
179
180
* @since 0.1.0
180
181
*
181
- * @param array $input Optional. The input data to validate.
182
+ * @param array<string,mixed> $input Optional. The input data to validate.
182
183
* @return bool Returns true if valid, false if validation fails.
183
184
*/
184
185
protected function validate_input ( array $ input = array () ): bool {
@@ -214,7 +215,7 @@ protected function validate_input( array $input = array() ): bool {
214
215
*
215
216
* @since 0.1.0
216
217
*
217
- * @param array $input Optional. The input data for permission checking.
218
+ * @param array<string,mixed> $input Optional. The input data for permission checking.
218
219
* @return bool Whether the ability has the necessary permission.
219
220
*/
220
221
public function has_permission ( array $ input = array () ): bool {
@@ -234,8 +235,8 @@ public function has_permission( array $input = array() ): bool {
234
235
*
235
236
* @since 0.1.0
236
237
*
237
- * @param array $input The input data for the ability.
238
- * @return mixed|WP_Error The result of the ability execution, or WP_Error on failure.
238
+ * @param array<string,mixed> $input The input data for the ability.
239
+ * @return mixed|\ WP_Error The result of the ability execution, or WP_Error on failure.
239
240
*/
240
241
protected function do_execute ( array $ input ) {
241
242
if ( ! is_callable ( $ this ->execute_callback ) ) {
@@ -292,8 +293,8 @@ protected function validate_output( $output ): bool {
292
293
*
293
294
* @since 0.1.0
294
295
*
295
- * @param array $input Optional. The input data for the ability.
296
- * @return mixed|WP_Error The result of the ability execution, or WP_Error on failure.
296
+ * @param array<string,mixed> $input Optional. The input data for the ability.
297
+ * @return mixed|\ WP_Error The result of the ability execution, or WP_Error on failure.
297
298
*/
298
299
public function execute ( array $ input = array () ) {
299
300
if ( ! $ this ->has_permission ( $ input ) ) {
@@ -326,6 +327,6 @@ public function execute( array $input = array() ) {
326
327
* @since 0.1.0
327
328
*/
328
329
public function __wakeup (): void {
329
- throw new \LogicException ( __CLASS__ . ' should never be unserialized. ' );
330
+ throw new \LogicException ( self ::class . ' should never be unserialized. ' );
330
331
}
331
332
}
0 commit comments