Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
Option | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getValue | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isSelected | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Option.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 `Option` 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 | /** |
20 | * Option |
21 | * |
22 | * This class is part of the Codex PHP library and is responsible for |
23 | * representing an immutable object. It is primarily intended for use |
24 | * with a builder class to construct its instances. |
25 | * |
26 | * @category Component |
27 | * @package Codex\Component |
28 | * @since 0.1.0 |
29 | * @author Doğu Abaris <abaris@null.net> |
30 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
31 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
32 | */ |
33 | class Option { |
34 | |
35 | /** |
36 | * The value of the option, used for form submission and programmatic selection. |
37 | */ |
38 | protected string $value; |
39 | |
40 | /** |
41 | * The display text for the option, shown in the select dropdown. |
42 | */ |
43 | protected string $text; |
44 | |
45 | /** |
46 | * Indicates whether the option is selected by default. |
47 | */ |
48 | protected bool $selected; |
49 | |
50 | /** |
51 | * Constructor for the Option component. |
52 | * |
53 | * Initializes an Option instance with the specified properties. |
54 | * |
55 | * @param string $value The value of the option. |
56 | * @param string $text The display text of the option. |
57 | * @param bool $selected Whether the option is selected by default. |
58 | */ |
59 | public function __construct( |
60 | string $value, |
61 | string $text, |
62 | bool $selected |
63 | ) { |
64 | $this->value = $value; |
65 | $this->text = $text; |
66 | $this->selected = $selected; |
67 | } |
68 | |
69 | /** |
70 | * Get the option's value. |
71 | * |
72 | * @since 0.1.0 |
73 | * @return string The value of the option. |
74 | */ |
75 | public function getValue(): string { |
76 | return $this->value; |
77 | } |
78 | |
79 | /** |
80 | * Get the option's display text. |
81 | * |
82 | * @since 0.1.0 |
83 | * @return string The display text of the option. |
84 | */ |
85 | public function getText(): string { |
86 | return $this->text; |
87 | } |
88 | |
89 | /** |
90 | * Get the option's selected state. |
91 | * |
92 | * @since 0.1.0 |
93 | * @return bool Whether the option is selected. |
94 | */ |
95 | public function isSelected(): bool { |
96 | return $this->selected; |
97 | } |
98 | } |