Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MediaWikiConfigReaderWrapper | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
get | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
has | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Config; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | use MediaWiki\Extension\CommunityConfiguration\Access\MediaWikiConfigReader; |
7 | |
8 | /** |
9 | * Wrapper around MediaWikiConfigReader from CommunityConfiguration, in order |
10 | * to modify configuration before passing it to GrowthExperiments if needed. |
11 | * |
12 | * @see MediaWikiConfigReader |
13 | */ |
14 | class MediaWikiConfigReaderWrapper implements Config { |
15 | public const MAP_POST_ON_TOP_VALUES = [ |
16 | 'top' => true, |
17 | 'bottom' => false, |
18 | ]; |
19 | |
20 | public const MAP_ASK_MENTOR_VALUES = [ |
21 | 'mentor-talk-page' => true, |
22 | 'help-desk-page' => false, |
23 | ]; |
24 | |
25 | private Config $mediawikiConfigReader; |
26 | |
27 | private Config $mainConfig; |
28 | |
29 | /** |
30 | * @param Config $mediawikiConfigReader |
31 | * @param Config $mainConfig |
32 | */ |
33 | public function __construct( |
34 | Config $mediawikiConfigReader, |
35 | Config $mainConfig |
36 | ) { |
37 | $this->mediawikiConfigReader = $mediawikiConfigReader; |
38 | $this->mainConfig = $mainConfig; |
39 | } |
40 | |
41 | /** |
42 | * @param string $name |
43 | * @return mixed |
44 | */ |
45 | public function get( $name ) { |
46 | $value = $this->mediawikiConfigReader->get( $name ); |
47 | if ( $name === 'GEHelpPanelHelpDeskPostOnTop' ) { |
48 | $value = self::MAP_POST_ON_TOP_VALUES[$value]; |
49 | } |
50 | if ( $name === 'GEHelpPanelAskMentor' ) { |
51 | $value = self::MAP_ASK_MENTOR_VALUES[$value]; |
52 | } |
53 | if ( $name === 'GELevelingUpKeepGoingNotificationThresholds' ) { |
54 | $thresholds = $this->mainConfig->get( 'GELevelingUpKeepGoingNotificationThresholds' ); |
55 | $value = [ $thresholds[ 0 ], $value ]; |
56 | } |
57 | return $value; |
58 | } |
59 | |
60 | /** |
61 | * @param string $name |
62 | * @return bool |
63 | */ |
64 | public function has( $name ): bool { |
65 | return $this->mediawikiConfigReader->has( $name ); |
66 | } |
67 | } |