PluginProbe
Plugin Check (PCP) / trunk
Plugin Check (PCP) vtrunk
2.1.0 trunk 0.1 0.2.0 0.2.1 0.2.2 0.2.3 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 ci-artifacts
plugin-check / includes / SVN / Section.php

Section.php in Plugin Check (PCP) trunk, at includes/SVN/Section.php

104 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Section class.
4 *
5 * @package Plugin_Check
6 */
7
8 namespace WordPress\Plugin_Check\SVN;
9
10 use JsonSerializable;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Class Section.
18 *
19 * A named group of checks within a report.
20 *
21 * @since 2.1.0
22 */
23 class Section implements JsonSerializable {
24
25 /**
26 * Machine-readable section ID.
27 *
28 * @var string
29 */
30 public string $id;
31
32 /**
33 * Human-readable section label.
34 *
35 * @var string
36 */
37 public string $label;
38
39 /**
40 * Checks in this section.
41 *
42 * @var array<int, array{key: string, label: string, status: string, detail: string}>
43 */
44 private array $checks = array();
45
46 /**
47 * Constructor.
48 *
49 * @since 2.1.0
50 *
51 * @param string $id Section ID.
52 * @param string $label Section label.
53 */
54 public function __construct( string $id, string $label ) {
55 $this->id = $id;
56 $this->label = $label;
57 }
58
59 /**
60 * Add a check.
61 *
62 * @since 2.1.0
63 *
64 * @param string $key Machine-readable, untranslated check identifier.
65 * @param string $label Translated check label.
66 * @param string $status pass|warn|fail|info.
67 * @param string $detail Translated detail text.
68 */
69 public function add_check( string $key, string $label, string $status, string $detail = '' ): void {
70 $this->checks[] = array(
71 'key' => $key,
72 'label' => $label,
73 'status' => $status,
74 'detail' => $detail,
75 );
76 }
77
78 /**
79 * Return checks in this section.
80 *
81 * @since 2.1.0
82 *
83 * @return array<int, array{key: string, label: string, status: string, detail: string}>
84 */
85 public function get_checks(): array {
86 return $this->checks;
87 }
88
89 /**
90 * Serialize to JSON.
91 *
92 * @since 2.1.0
93 *
94 * @return array<string, mixed>
95 */
96 public function jsonSerialize(): array {
97 return array(
98 'id' => $this->id,
99 'label' => $this->label,
100 'checks' => $this->checks,
101 );
102 }
103 }
104