Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
ProgressBar | |
0.00% |
0 / 12 |
|
0.00% |
0 / 7 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isInline | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isDisabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAttributes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * ProgressBar.php |
4 | * |
5 | * This file is part of the Codex design system, the official design system for Wikimedia projects. |
6 | * It contains the definition and implementation of the `ProgressBar` class, responsible for managing |
7 | * the behavior and properties of the corresponding component. |
8 | * |
9 | * @category Component |
10 | * @package Codex\Component |
11 | * @since 0.1.0 |
12 | * @author Doğu Abaris <abaris@null.net> |
13 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
14 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
15 | */ |
16 | |
17 | namespace Wikimedia\Codex\Component; |
18 | |
19 | use Wikimedia\Codex\Renderer\ProgressBarRenderer; |
20 | |
21 | /** |
22 | * ProgressBar |
23 | * |
24 | * This class is part of the Codex PHP library and is responsible for |
25 | * representing an immutable object. It is primarily intended for use |
26 | * with a builder class to construct its instances. |
27 | * |
28 | * @category Component |
29 | * @package Codex\Component |
30 | * @since 0.1.0 |
31 | * @author Doğu Abaris <abaris@null.net> |
32 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
33 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
34 | */ |
35 | class ProgressBar { |
36 | |
37 | /** |
38 | * The ID for the progress bar. |
39 | */ |
40 | private string $id; |
41 | |
42 | /** |
43 | * The ARIA label for the progress bar, important for accessibility. |
44 | */ |
45 | private string $label; |
46 | |
47 | /** |
48 | * Whether the progress bar is a smaller, inline variant. |
49 | */ |
50 | private bool $inline; |
51 | |
52 | /** |
53 | * Whether the progress bar is disabled. |
54 | */ |
55 | private bool $disabled; |
56 | |
57 | /** |
58 | * Additional HTML attributes for the outer `<div>` element of the progress bar. |
59 | */ |
60 | private array $attributes; |
61 | |
62 | /** |
63 | * The renderer instance used to render the progress bar. |
64 | */ |
65 | private ProgressBarRenderer $renderer; |
66 | |
67 | /** |
68 | * Constructor for the ProgressBar component. |
69 | * |
70 | * Initializes a ProgressBar instance with the specified properties. |
71 | * |
72 | * @param string $id The ID for the progress bar. |
73 | * @param string $label The ARIA label for the progress bar. |
74 | * @param bool $inline Whether the progress bar is inline. |
75 | * @param bool $disabled Whether the progress bar is disabled. |
76 | * @param array $attributes Additional HTML attributes for the progress bar. |
77 | * @param ProgressBarRenderer $renderer The renderer to use for rendering the progress bar. |
78 | */ |
79 | public function __construct( |
80 | string $id, |
81 | string $label, |
82 | bool $inline, |
83 | bool $disabled, |
84 | array $attributes, |
85 | ProgressBarRenderer $renderer |
86 | ) { |
87 | $this->id = $id; |
88 | $this->label = $label; |
89 | $this->inline = $inline; |
90 | $this->disabled = $disabled; |
91 | $this->attributes = $attributes; |
92 | $this->renderer = $renderer; |
93 | } |
94 | |
95 | /** |
96 | * Get the ProgressBar's HTML ID attribute. |
97 | * |
98 | * This method returns the ID assigned to the progress bar element, which is used |
99 | * for identifying the progress bar in the HTML document. |
100 | * |
101 | * @since 0.1.0 |
102 | * @return string The ID of the ProgressBar. |
103 | */ |
104 | public function getId(): string { |
105 | return $this->id; |
106 | } |
107 | |
108 | /** |
109 | * Get the ARIA label for the progress bar. |
110 | * |
111 | * This method returns the ARIA label that is used for the progress bar, which is important for accessibility. |
112 | * The label provides a descriptive name for the progress bar, helping users with assistive technologies |
113 | * to understand its purpose. |
114 | * |
115 | * @since 0.1.0 |
116 | * @return string The ARIA label for the progress bar. |
117 | */ |
118 | public function getLabel(): string { |
119 | return $this->label; |
120 | } |
121 | |
122 | /** |
123 | * Get whether the progress bar is inline. |
124 | * |
125 | * This method returns a boolean value indicating whether the progress bar is the smaller, inline variant. |
126 | * |
127 | * @since 0.1.0 |
128 | * @return bool True if the progress bar is inline, false otherwise. |
129 | */ |
130 | public function isInline(): bool { |
131 | return $this->inline; |
132 | } |
133 | |
134 | /** |
135 | * Get whether the progress bar is disabled. |
136 | * |
137 | * This method returns a boolean value indicating whether the progress bar is disabled. |
138 | * |
139 | * @since 0.1.0 |
140 | * @return bool True if the progress bar is disabled, false otherwise. |
141 | */ |
142 | public function isDisabled(): bool { |
143 | return $this->disabled; |
144 | } |
145 | |
146 | /** |
147 | * Get the additional HTML attributes for the outer `<div>` element. |
148 | * |
149 | * This method returns an associative array of HTML attributes that are applied to the outer `<div>` element of the |
150 | * progress bar. These attributes can include `id`, `data-*`, `aria-*`, or any other valid HTML attributes. |
151 | * |
152 | * @since 0.1.0 |
153 | * @return array The additional attributes as an array. |
154 | */ |
155 | public function getAttributes(): array { |
156 | return $this->attributes; |
157 | } |
158 | |
159 | /** |
160 | * Get the component's HTML representation. |
161 | * |
162 | * This method generates the HTML markup for the component, incorporating relevant properties |
163 | * and any additional attributes. The component is structured using appropriate HTML elements |
164 | * as defined by the implementation. |
165 | * |
166 | * @since 0.1.0 |
167 | * @return string The generated HTML string for the component. |
168 | */ |
169 | public function getHtml(): string { |
170 | return $this->renderer->render( $this ); |
171 | } |
172 | } |