Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
81.25% |
13 / 16 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
TopicDecorator | |
81.25% |
13 / 16 |
|
40.00% |
2 / 5 |
8.42 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
loadTaskTypes | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
loadTopics | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
getDisabledTaskTypes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadInfoboxTemplates | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\ConfigurationLoader; |
4 | |
5 | use CirrusSearch\Query\ArticleTopicFeature; |
6 | use GrowthExperiments\NewcomerTasks\TaskType\TaskType; |
7 | use GrowthExperiments\NewcomerTasks\Topic\RawOresTopic; |
8 | use StatusValue; |
9 | |
10 | /** |
11 | * Configuration loader for customizing topic types (ores or growth) and task types; |
12 | * used in listTaskCounts maintenance script |
13 | */ |
14 | class TopicDecorator implements ConfigurationLoader { |
15 | |
16 | use ConfigurationLoaderTrait; |
17 | |
18 | /** @var ConfigurationLoader */ |
19 | private $configurationLoader; |
20 | |
21 | /** @var bool */ |
22 | private $useOresTopics; |
23 | |
24 | /** |
25 | * @var TaskType[] |
26 | */ |
27 | private $extraTaskTypes; |
28 | |
29 | /** |
30 | * @param ConfigurationLoader $configurationLoader |
31 | * @param bool $useOresTopics Whether raw ORES topic should be used |
32 | * @param TaskType[] $extraTaskTypes Extra task types to extend the task configuration with. |
33 | */ |
34 | public function __construct( |
35 | ConfigurationLoader $configurationLoader, |
36 | bool $useOresTopics, |
37 | array $extraTaskTypes = [] |
38 | ) { |
39 | $this->configurationLoader = $configurationLoader; |
40 | $this->useOresTopics = $useOresTopics; |
41 | $this->extraTaskTypes = $extraTaskTypes; |
42 | } |
43 | |
44 | /** @inheritDoc */ |
45 | public function loadTaskTypes() { |
46 | $taskTypes = $this->configurationLoader->loadTaskTypes(); |
47 | if ( $taskTypes instanceof StatusValue ) { |
48 | return $taskTypes; |
49 | } |
50 | return array_merge( $taskTypes, $this->extraTaskTypes ); |
51 | } |
52 | |
53 | /** @inheritDoc */ |
54 | public function loadTopics() { |
55 | if ( $this->useOresTopics ) { |
56 | $topics = array_map( static function ( string $oresId ) { |
57 | return new RawOresTopic( $oresId, $oresId ); |
58 | }, array_keys( ArticleTopicFeature::TERMS_TO_LABELS ) ); |
59 | if ( $topics ) { |
60 | return $topics; |
61 | } |
62 | } |
63 | return $this->configurationLoader->loadTopics(); |
64 | } |
65 | |
66 | /** @inheritDoc */ |
67 | public function getDisabledTaskTypes(): array { |
68 | // Extra task types are never disabled. |
69 | return $this->configurationLoader->getDisabledTaskTypes(); |
70 | } |
71 | |
72 | /** @inheritDoc */ |
73 | public function loadInfoboxTemplates(): array { |
74 | return $this->configurationLoader->loadInfoboxTemplates(); |
75 | } |
76 | } |