Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| 1 | <?php |
| 2 | /** |
| 3 | * The interface each type of proposed change implements. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Jetpack_Mu_Wpcom\Proposals; |
| 9 | |
| 10 | use WP_Error; |
| 11 | |
| 12 | /** |
| 13 | * One handler per type of data. The engine stores and locks items; handlers own their data. |
| 14 | * |
| 15 | * A stored item is { id, type, target, base, change }. Handlers fill target, base and change. |
| 16 | */ |
| 17 | interface Proposal_Handler { |
| 18 | |
| 19 | /** |
| 20 | * Validate and sanitize a requested change as the proposing user, with no side effects. |
| 21 | * |
| 22 | * @param array $request The agent's request for this item. |
| 23 | * @return array|WP_Error { target, base, change, warning? } |
| 24 | */ |
| 25 | public function build( array $request ); |
| 26 | |
| 27 | /** |
| 28 | * Whether a stored item has a shape build() could have produced. |
| 29 | * |
| 30 | * @param array $item Stored item. |
| 31 | */ |
| 32 | public function is_valid( array $item ): bool; |
| 33 | |
| 34 | /** |
| 35 | * What the item changes, such as 'post:12'. No two items in a proposal may share one. |
| 36 | * |
| 37 | * @param array $item Stored item. |
| 38 | * @return string[] |
| 39 | */ |
| 40 | public function targets( array $item ): array; |
| 41 | |
| 42 | /** |
| 43 | * Whether the current user may preview, apply or reject the item. |
| 44 | * |
| 45 | * @param array $item Stored item. |
| 46 | */ |
| 47 | public function can_review( array $item ): bool; |
| 48 | |
| 49 | /** |
| 50 | * Live values that changed since the item was built. |
| 51 | * |
| 52 | * @param array $item Stored item. |
| 53 | * @return array<int, array{reason: string}> |
| 54 | */ |
| 55 | public function conflicts( array $item ): array; |
| 56 | |
| 57 | /** |
| 58 | * Add the overlay and write guard for these items. Called once per preview request. |
| 59 | * |
| 60 | * @param array $items Stored items of this type. |
| 61 | */ |
| 62 | public function start_preview( array $items ): void; |
| 63 | |
| 64 | /** |
| 65 | * The live URL that best shows the item. |
| 66 | * |
| 67 | * @param array $item Stored item. |
| 68 | */ |
| 69 | public function preview_target( array $item ): ?string; |
| 70 | |
| 71 | /** |
| 72 | * Write the change as the current user. Reports failure in the result rather than returning an error. |
| 73 | * |
| 74 | * @param array $item Stored item. |
| 75 | * @return array{changed: string[], error?: string} |
| 76 | */ |
| 77 | public function apply( array $item ): array; |
| 78 | |
| 79 | /** |
| 80 | * The change, for an agent to show the person in chat. |
| 81 | * |
| 82 | * @param array $item Stored item. |
| 83 | * @param string $status Proposal status. Live values are only a baseline while it is pending. |
| 84 | * @return array<int, array{label: string, kind: string}> |
| 85 | */ |
| 86 | public function describe( array $item, string $status ): array; |
| 87 | } |