Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ExperimentManagerFactory | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
newInstance | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\MetricsPlatform; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | |
7 | /** |
8 | * Provides a stable API to construct an instance of {@link ExperimentManager}. |
9 | */ |
10 | class ExperimentManagerFactory { |
11 | |
12 | public const CONSTRUCTOR_OPTIONS = [ |
13 | 'MetricsPlatformEnableExperimentOverrides' |
14 | ]; |
15 | |
16 | private InstrumentConfigsFetcher $configsFetcher; |
17 | private Config $config; |
18 | |
19 | public function __construct( InstrumentConfigsFetcher $configsFetcher, Config $config ) { |
20 | $this->configsFetcher = $configsFetcher; |
21 | $this->config = $config; |
22 | } |
23 | |
24 | /** |
25 | * Creates a new instance of {@link ExperimentManager} using configs fetched from either local config (highest |
26 | * priority) or from MPIC (lowest priority). |
27 | * |
28 | * @return ExperimentManager |
29 | */ |
30 | public function newInstance(): ExperimentManager { |
31 | $experimentConfigs = $this->config->has( 'MetricsPlatformExperiments' ) ? |
32 | $this->config->get( 'MetricsPlatformExperiments' ) : |
33 | $this->configsFetcher->getExperimentConfigs(); |
34 | |
35 | return new ExperimentManager( |
36 | $experimentConfigs, |
37 | $this->config->get( 'MetricsPlatformEnableExperimentOverrides' ) |
38 | ); |
39 | } |
40 | } |