-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclass-wp-codebox-status-taxonomy.php
More file actions
117 lines (106 loc) · 3.72 KB
/
Copy pathclass-wp-codebox-status-taxonomy.php
File metadata and controls
117 lines (106 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Status vocabulary bridges for host-side response contracts.
*
* @package WPCodebox
*/
defined( 'ABSPATH' ) || exit;
final class WP_Codebox_Status_Taxonomy {
/**
* @param array<string,mixed> $input Status conversion input.
*/
public static function command_envelope_status( array $input ): string {
$status = self::status_string( $input['status'] ?? '' );
if ( in_array( $status, array( 'completed', 'failed', 'timed_out', 'cancelled', 'running', 'queued' ), true ) ) {
return $status;
}
if ( in_array( $status, array( 'succeeded', 'no_op', 'passed' ), true ) ) {
return 'completed';
}
if ( 'timeout' === $status ) {
return 'timed_out';
}
if ( in_array( $status, array( 'provider_error', 'unable_to_remediate', 'blocked' ), true ) ) {
return 'failed';
}
if ( '' !== $status ) {
return $status;
}
return true === ( $input['success'] ?? false ) && 0 === (int) ( $input['exit_status'] ?? 0 ) ? 'completed' : 'failed';
}
/**
* @param array<string,mixed> $input Status conversion input.
*/
public static function phase_recipe_status( array $input ): string {
$status = self::status_string( $input['status'] ?? '' );
if ( in_array( $status, array( 'succeeded', 'failed', 'partial', 'blocked', 'skipped', 'running' ), true ) ) {
return $status;
}
if ( in_array( $status, array( 'completed', 'passed', 'no_op' ), true ) ) {
return 'succeeded';
}
if ( in_array( $status, array( 'timeout', 'provider_error', 'unable_to_remediate', 'timed_out' ), true ) ) {
return 'failed';
}
if ( '' !== $status ) {
return $status;
}
return true === ( $input['success'] ?? false ) && 0 === (int) ( $input['exit_status'] ?? 0 ) ? 'succeeded' : 'failed';
}
/**
* @param array<string,mixed> $input Status conversion input.
*/
public static function agent_task_status( array $input ): string {
$status = self::status_string( $input['status'] ?? '' );
if ( in_array( $status, array( 'succeeded', 'failed', 'no_op', 'timeout', 'provider_error', 'unable_to_remediate' ), true ) ) {
return $status;
}
if ( in_array( $status, array( 'completed', 'passed' ), true ) ) {
return false === ( $input['success'] ?? true ) || 0 !== (int) ( $input['exit_status'] ?? 0 ) ? 'failed' : 'succeeded';
}
if ( 'timed_out' === $status ) {
return 'timeout';
}
if ( 'blocked' === $status ) {
return 'unable_to_remediate';
}
if ( true === ( $input['no_op'] ?? false ) ) {
return 'no_op';
}
if ( true === ( $input['unable_to_remediate'] ?? false ) ) {
return 'unable_to_remediate';
}
if ( true === ( $input['timeout'] ?? false ) ) {
return 'timeout';
}
if ( ! empty( $input['provider_error'] ) ) {
return 'provider_error';
}
return true === ( $input['success'] ?? false ) && 0 === (int) ( $input['exit_status'] ?? 0 ) ? 'succeeded' : 'failed';
}
/**
* @param array<string,mixed> $input Status conversion input.
*/
public static function check_status( array $input ): string {
$status = self::status_string( $input['status'] ?? '' );
if ( in_array( $status, array( 'passed', 'failed', 'warning', 'skipped', 'unknown' ), true ) ) {
return $status;
}
if ( in_array( $status, array( 'succeeded', 'completed', 'no_op' ), true ) ) {
return 'passed';
}
if ( in_array( $status, array( 'partial', 'blocked' ), true ) ) {
return 'warning';
}
if ( in_array( $status, array( 'timeout', 'provider_error', 'unable_to_remediate', 'timed_out' ), true ) ) {
return 'failed';
}
if ( '' !== $status ) {
return $status;
}
return true === ( $input['success'] ?? false ) && 0 === (int) ( $input['exit_status'] ?? 0 ) ? 'passed' : 'failed';
}
private static function status_string( mixed $status ): string {
return is_string( $status ) ? trim( $status ) : '';
}
}