Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 13 |
CRAP | |
0.00% |
0 / 1 |
CustomIndexField | |
0.00% |
0 / 47 |
|
0.00% |
0 / 13 |
1406 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getStringValue | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
getType | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
20 | |||
getData | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
20 | |||
getLabel | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
getSize | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
getPossibleValues | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
getHelp | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
isHidden | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
isHeader | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
isAllowedInJs | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
isPagelist | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace ProofreadPage\Index; |
4 | |
5 | /** |
6 | * @license GPL-2.0-or-later |
7 | * |
8 | * An index entry. |
9 | */ |
10 | class CustomIndexField { |
11 | |
12 | /** |
13 | * The key of the entry |
14 | * @var string |
15 | */ |
16 | protected $key; |
17 | |
18 | /** |
19 | * The value of the entry |
20 | * @var string |
21 | */ |
22 | protected $value; |
23 | |
24 | /** |
25 | * The config of the entry |
26 | * @var array |
27 | */ |
28 | protected $config; |
29 | |
30 | /** |
31 | * @param string $key |
32 | * @param string $value |
33 | * @param array $config |
34 | */ |
35 | public function __construct( $key, $value, array $config ) { |
36 | $this->key = $key; |
37 | $this->value = trim( $value ); |
38 | $this->config = $config; |
39 | } |
40 | |
41 | /** |
42 | * Return the key of the entry |
43 | * @return string |
44 | */ |
45 | public function getKey() { |
46 | return $this->key; |
47 | } |
48 | |
49 | /** |
50 | * Return the value of the entry as string |
51 | * @return string |
52 | */ |
53 | public function getStringValue() { |
54 | if ( $this->value === '' ) { |
55 | if ( isset( $this->config['default'] ) ) { |
56 | return (string)$this->config['default']; |
57 | } else { |
58 | return ''; |
59 | } |
60 | } else { |
61 | return $this->value; |
62 | } |
63 | } |
64 | |
65 | /** |
66 | * Return the type of the entry |
67 | * @return string |
68 | */ |
69 | public function getType(): string { |
70 | if ( isset( $this->config['type'] ) && $this->config['type'] !== null && $this->config['type'] !== '' ) { |
71 | return strtolower( $this->config['type'] ); |
72 | } else { |
73 | return 'string'; |
74 | } |
75 | } |
76 | |
77 | /** |
78 | * Return the field's data name. |
79 | * This is a lowercase string that defines what sort of information is stored in this field. |
80 | * |
81 | * @return ?string |
82 | */ |
83 | public function getData(): ?string { |
84 | if ( isset( $this->config['data'] ) && $this->config['data'] !== null && $this->config['data'] !== '' ) { |
85 | return strtolower( $this->config['data'] ); |
86 | } else { |
87 | return null; |
88 | } |
89 | } |
90 | |
91 | /** |
92 | * Return the label of the entry |
93 | * @return string |
94 | */ |
95 | public function getLabel() { |
96 | if ( isset( $this->config['label'] ) && $this->config['label'] != '' ) { |
97 | return $this->config['label']; |
98 | } else { |
99 | return $this->key; |
100 | } |
101 | } |
102 | |
103 | /** |
104 | * Return size of the edition field |
105 | * @return int |
106 | */ |
107 | public function getSize() { |
108 | if ( |
109 | isset( $this->config['size'] ) && |
110 | is_numeric( $this->config['size'] ) && |
111 | $this->config['size'] >= 1 |
112 | ) { |
113 | return (int)$this->config['size']; |
114 | } else { |
115 | return 1; |
116 | } |
117 | } |
118 | |
119 | /** |
120 | * Return the possible values of the entry as an array value => label of null |
121 | * @return string[]|null |
122 | */ |
123 | public function getPossibleValues() { |
124 | if ( isset( $this->config['values'] ) && is_array( $this->config['values'] ) ) { |
125 | return $this->config['values']; |
126 | } else { |
127 | return null; |
128 | } |
129 | } |
130 | |
131 | /** |
132 | * Return the help text or an empty string |
133 | * @return string |
134 | */ |
135 | public function getHelp() { |
136 | if ( isset( $this->config['help'] ) && $this->config['help'] ) { |
137 | return $this->config['help']; |
138 | } else { |
139 | return ''; |
140 | } |
141 | } |
142 | |
143 | /** |
144 | * Say if the entry is "hidden" |
145 | * @return bool |
146 | */ |
147 | public function isHidden() { |
148 | if ( isset( $this->config['hidden'] ) ) { |
149 | if ( is_bool( $this->config['hidden'] ) ) { |
150 | return $this->config['hidden']; |
151 | } else { |
152 | return filter_var( $this->config['hidden'], FILTER_VALIDATE_BOOLEAN ); |
153 | } |
154 | } else { |
155 | return false; |
156 | } |
157 | } |
158 | |
159 | /** |
160 | * Say if the entry have to be given to "header template" |
161 | * @return bool |
162 | */ |
163 | public function isHeader() { |
164 | if ( in_array( strtolower( $this->key ), [ 'header', 'footer', 'css', 'width' ], true ) ) { |
165 | return true; |
166 | } else { |
167 | if ( isset( $this->config['header'] ) ) { |
168 | if ( is_bool( $this->config['header'] ) ) { |
169 | return $this->config['header']; |
170 | } else { |
171 | return filter_var( $this->config['header'], FILTER_VALIDATE_BOOLEAN ); |
172 | } |
173 | } else { |
174 | return false; |
175 | } |
176 | } |
177 | } |
178 | |
179 | /** |
180 | * Say if entry should be exposed via mw.config |
181 | * @return bool |
182 | */ |
183 | public function isAllowedInJs() { |
184 | if ( isset( $this->config['js'] ) ) { |
185 | if ( is_bool( $this->config['js'] ) ) { |
186 | return $this->config['js']; |
187 | } else { |
188 | return filter_var( $this->config['js'], FILTER_VALIDATE_BOOLEAN ); |
189 | } |
190 | } else { |
191 | return false; |
192 | } |
193 | } |
194 | |
195 | /** |
196 | * Say if entry expects a pagelist |
197 | * @return bool |
198 | */ |
199 | public function isPagelist() { |
200 | return $this->getData() === 'pagelist'; |
201 | } |
202 | } |