Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
HealthCheck | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
test | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
register_health_check | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace NewfoldLabs\WP\Module\Performance\HealthChecks; |
4 | |
5 | /** |
6 | * Abstract class for a health check. |
7 | */ |
8 | abstract class HealthCheck { |
9 | /** |
10 | * Health check ID. |
11 | * |
12 | * @var string |
13 | */ |
14 | public $id; |
15 | |
16 | /** |
17 | * Health check title. |
18 | * |
19 | * @var string |
20 | */ |
21 | public $title; |
22 | |
23 | /** |
24 | * Health check passing text. |
25 | * |
26 | * @var string |
27 | */ |
28 | public $passing_text; |
29 | |
30 | /** |
31 | * Health check failing text. |
32 | * |
33 | * @var string |
34 | */ |
35 | public $failing_text; |
36 | |
37 | /** |
38 | * Health check description. |
39 | * |
40 | * @var string |
41 | */ |
42 | public $description; |
43 | |
44 | /** |
45 | * Health check description actions. |
46 | * |
47 | * @var string |
48 | */ |
49 | public $actions; |
50 | |
51 | /** |
52 | * Health check badge color. |
53 | * |
54 | * @var string |
55 | */ |
56 | public $badge_color = 'blue'; |
57 | |
58 | /** |
59 | * Health check test. |
60 | * |
61 | * @var bool Test result. |
62 | */ |
63 | public function test() { |
64 | return true; |
65 | } |
66 | |
67 | /** |
68 | * Register the health check with the manager. |
69 | * |
70 | * @param array $tests Site Health tests. |
71 | * |
72 | * @return array Site Health tests. |
73 | */ |
74 | public function register_health_check( $tests ) { |
75 | /** |
76 | * Filter to easily enable/disable the health check. |
77 | * |
78 | * @param bool $do_check Whether to run the health check. |
79 | */ |
80 | $do_check = apply_filters( 'newfold/features/filter/isEnabled:healthChecks:' . $this->id, true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
81 | if ( ! $do_check ) { |
82 | return $tests; |
83 | } |
84 | |
85 | // Right now, we're only supporting direct health checks. |
86 | $tests['direct'][ $this->id ] = array( |
87 | 'label' => $this->title, |
88 | 'test' => function () { |
89 | $passed = $this->test(); |
90 | |
91 | return array( |
92 | 'label' => $passed ? $this->passing_text : $this->failing_text, |
93 | 'status' => $passed ? 'good' : 'recommended', |
94 | 'description' => sprintf( '<p>%s</p>', $this->description ), |
95 | 'actions' => $this->actions, |
96 | 'test' => $this->id, |
97 | 'badge' => array( |
98 | // No text domain, as we want to match the WP core badge text. |
99 | 'label' => __( 'Performance' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain |
100 | 'color' => $this->badge_color, |
101 | ), |
102 | ); |
103 | }, |
104 | ); |
105 | |
106 | return $tests; |
107 | } |
108 | } |