Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
76.47% covered (warning)
76.47%
13 / 17
42.86% covered (danger)
42.86%
3 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
TaskSetFilters
76.47% covered (warning)
76.47%
13 / 17
42.86% covered (danger)
42.86%
3 / 7
7.64
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getTopicFiltersMode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setTaskTypeFilters
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTaskTypeFilters
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTopicFilters
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toJsonArray
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 newFromJsonArray
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace GrowthExperiments\NewcomerTasks\Task;
4
5use GrowthExperiments\NewcomerTasks\TaskSuggester\SearchStrategy\SearchStrategy;
6use MediaWiki\Json\JsonUnserializable;
7use MediaWiki\Json\JsonUnserializableTrait;
8use MediaWiki\Json\JsonUnserializer;
9
10/**
11 * Class which contains the set of filters (task, topics) used to generate a TaskSet.
12 *
13 * JsonSerializable is implemented to provide the ability to compare TaskSetFilters across
14 * TaskSets by JSON encoding the objects.
15 */
16class TaskSetFilters implements JsonUnserializable {
17
18    use JsonUnserializableTrait;
19
20    /**
21     * @var string[] List of task type IDs to limit the suggestions to.
22     *   An empty array means no filtering.
23     */
24    private $taskTypeFilters;
25    /**
26     * @var string[] List of topic IDs to limit the suggestions to.
27     *   An empty array means no filtering.
28     */
29    private $topicFilters;
30    /**
31     * @var string|null Matching mode for topics. One of: 'AND', 'OR'.
32     * @See SearchStrategy::TOPIC_MATCH_MODES
33     */
34    private $topicFiltersMode;
35
36    /**
37     * @param string[] $taskTypeFilters
38     * @param string[] $topicFilters
39     * @param string|null $topicFiltersMode
40     */
41    public function __construct(
42        array $taskTypeFilters = [],
43        array $topicFilters = [],
44        ?string $topicFiltersMode = null
45    ) {
46        $this->taskTypeFilters = $taskTypeFilters;
47        $this->topicFilters = $topicFilters;
48        $this->topicFiltersMode = $topicFiltersMode ?? SearchStrategy::TOPIC_MATCH_MODE_OR;
49    }
50
51    /**
52     * @return string
53     */
54    public function getTopicFiltersMode(): string {
55        return $this->topicFiltersMode;
56    }
57
58    /**
59     * @param string[] $taskTypeFilters
60     */
61    public function setTaskTypeFilters( array $taskTypeFilters ): void {
62        $this->taskTypeFilters = $taskTypeFilters;
63    }
64
65    /**
66     * @return string[]
67     */
68    public function getTaskTypeFilters(): array {
69        return $this->taskTypeFilters;
70    }
71
72    /**
73     * @return string[]
74     */
75    public function getTopicFilters(): array {
76        return $this->topicFilters;
77    }
78
79    /** @inheritDoc */
80    protected function toJsonArray(): array {
81        return [
82            'task' => $this->taskTypeFilters,
83            'topic' => $this->topicFilters,
84            'topicMode' => $this->topicFiltersMode
85        ];
86    }
87
88    /** @inheritDoc */
89    public static function newFromJsonArray( JsonUnserializer $unserializer, array $json ) {
90        return new self(
91            $json['task'],
92            $json['topic'],
93            $json['topicMode'] ?? SearchStrategy::TOPIC_MATCH_MODE_OR
94        );
95    }
96
97}