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