Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
2 / 3 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ErrorForwardingTaskSuggester | |
66.67% |
2 / 3 |
|
66.67% |
2 / 3 |
4.59 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
suggest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
filter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\TaskSuggester; |
4 | |
5 | use GrowthExperiments\NewcomerTasks\Task\TaskSet; |
6 | use GrowthExperiments\NewcomerTasks\Task\TaskSetFilters; |
7 | use MediaWiki\User\UserIdentity; |
8 | use StatusValue; |
9 | |
10 | /** |
11 | * An TaskSuggester which returns a pre-configured error. |
12 | * |
13 | * Used for the delayed reporting of errors that happen early on in the lifecycle where we |
14 | * probably don't have a straightforward way to notify the user. This is not uncommon since |
15 | * some of the configuration might be managed on-wiki; and we don't want to use internal |
16 | * reporting or exceptions for user errors. |
17 | */ |
18 | class ErrorForwardingTaskSuggester implements TaskSuggester { |
19 | |
20 | /** @var StatusValue */ |
21 | private $status; |
22 | |
23 | /** @var StatusValue */ |
24 | private $filterStatus; |
25 | |
26 | /** |
27 | * @param StatusValue $status The error to return for suggest(). |
28 | * @param StatusValue|null $filterStatus The error to return for filter() (null means the |
29 | * method is a no-op). |
30 | */ |
31 | public function __construct( StatusValue $status, StatusValue $filterStatus = null ) { |
32 | $this->status = $status; |
33 | } |
34 | |
35 | /** @inheritDoc */ |
36 | public function suggest( |
37 | UserIdentity $user, |
38 | TaskSetFilters $taskSetFilters, |
39 | ?int $limit = null, |
40 | ?int $offset = null, |
41 | array $options = [] |
42 | ) { |
43 | return $this->status; |
44 | } |
45 | |
46 | /** @inheritDoc */ |
47 | public function filter( UserIdentity $user, TaskSet $taskSet ) { |
48 | return $this->filterStatus ?: $taskSet; |
49 | } |
50 | |
51 | } |