Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
30 / 30 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
RemoteSearchTaskSuggesterFactory | |
100.00% |
30 / 30 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
create | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\TaskSuggester; |
4 | |
5 | use GrowthExperiments\NewcomerTasks\ConfigurationLoader\ConfigurationLoader; |
6 | use GrowthExperiments\NewcomerTasks\NewcomerTasksUserOptionsLookup; |
7 | use GrowthExperiments\NewcomerTasks\TaskSuggester\SearchStrategy\SearchStrategy; |
8 | use GrowthExperiments\NewcomerTasks\TaskType\TaskTypeHandlerRegistry; |
9 | use MediaWiki\Cache\LinkBatchFactory; |
10 | use MediaWiki\Http\HttpRequestFactory; |
11 | use MediaWiki\Title\TitleFactory; |
12 | use StatusValue; |
13 | |
14 | /** |
15 | * Factory for RemoteSearchTaskSuggester. |
16 | */ |
17 | class RemoteSearchTaskSuggesterFactory extends SearchTaskSuggesterFactory { |
18 | |
19 | /** @var HttpRequestFactory */ |
20 | private $requestFactory; |
21 | |
22 | /** @var TitleFactory */ |
23 | private $titleFactory; |
24 | |
25 | /** @var string */ |
26 | private $apiUrl; |
27 | |
28 | /** |
29 | * @param TaskTypeHandlerRegistry $taskTypeHandlerRegistry |
30 | * @param ConfigurationLoader $configurationLoader |
31 | * @param SearchStrategy $searchStrategy |
32 | * @param NewcomerTasksUserOptionsLookup $newcomerTasksUserOptionsLookup |
33 | * @param HttpRequestFactory $requestFactory |
34 | * @param TitleFactory $titleFactory |
35 | * @param LinkBatchFactory $linkBatchFactory |
36 | * @param string $apiUrl Base URL of the remote API (ending with 'api.php'). |
37 | */ |
38 | public function __construct( |
39 | TaskTypeHandlerRegistry $taskTypeHandlerRegistry, |
40 | ConfigurationLoader $configurationLoader, |
41 | SearchStrategy $searchStrategy, |
42 | NewcomerTasksUserOptionsLookup $newcomerTasksUserOptionsLookup, |
43 | HttpRequestFactory $requestFactory, |
44 | TitleFactory $titleFactory, |
45 | LinkBatchFactory $linkBatchFactory, |
46 | string $apiUrl |
47 | ) { |
48 | parent::__construct( |
49 | $taskTypeHandlerRegistry, |
50 | $configurationLoader, |
51 | $searchStrategy, |
52 | $newcomerTasksUserOptionsLookup, |
53 | $linkBatchFactory |
54 | ); |
55 | $this->requestFactory = $requestFactory; |
56 | $this->titleFactory = $titleFactory; |
57 | $this->apiUrl = $apiUrl; |
58 | } |
59 | |
60 | /** |
61 | * @param ConfigurationLoader|null $customConfigurationLoader |
62 | * @return RemoteSearchTaskSuggester|ErrorForwardingTaskSuggester |
63 | */ |
64 | public function create( ?ConfigurationLoader $customConfigurationLoader = null ) { |
65 | $configurationLoader = $customConfigurationLoader ?? $this->configurationLoader; |
66 | $taskTypes = $configurationLoader->loadTaskTypes(); |
67 | if ( $taskTypes instanceof StatusValue ) { |
68 | return $this->createError( $taskTypes ); |
69 | } |
70 | $topics = $configurationLoader->loadTopics(); |
71 | if ( $topics instanceof StatusValue ) { |
72 | return $this->createError( $topics ); |
73 | } |
74 | $suggester = new RemoteSearchTaskSuggester( |
75 | $this->taskTypeHandlerRegistry, |
76 | $this->searchStrategy, |
77 | $this->newcomerTasksUserOptionsLookup, |
78 | $this->linkBatchFactory, |
79 | $this->requestFactory, |
80 | $this->titleFactory, |
81 | $this->apiUrl, |
82 | $taskTypes, |
83 | $topics |
84 | ); |
85 | $suggester->setLogger( $this->logger ); |
86 | return $suggester; |
87 | } |
88 | |
89 | } |