Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
MenteesPrefixSearchHandler
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
6
 getParamSettings
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\Rest\Handler;
4
5use GrowthExperiments\MentorDashboard\MenteeOverview\MenteeOverviewDataProvider;
6use GrowthExperiments\MentorDashboard\MenteeOverview\MenteeOverviewPrefixSearchDataFilter;
7use MediaWiki\Rest\HttpException;
8use MediaWiki\Rest\SimpleHandler;
9use Wikimedia\ParamValidator\ParamValidator;
10
11class MenteesPrefixSearchHandler extends SimpleHandler {
12    /** @var MenteeOverviewDataProvider */
13    private $dataProvider;
14
15    /**
16     * @param MenteeOverviewDataProvider $dataProvider
17     */
18    public function __construct(
19        MenteeOverviewDataProvider $dataProvider
20    ) {
21        $this->dataProvider = $dataProvider;
22    }
23
24    /**
25     * @param string $prefix
26     * @return array
27     * @throws HttpException
28     */
29    public function run( string $prefix ) {
30        $authority = $this->getAuthority();
31        if ( !$authority->isNamed() ) {
32            throw new HttpException( 'You must be logged in', 403 );
33        }
34        $user = $authority->getUser();
35
36        $params = $this->getValidatedParams();
37        $limit = $params['limit'] ?? 10;
38
39        $dataFilter = new MenteeOverviewPrefixSearchDataFilter(
40            $this->dataProvider->getFormattedDataForMentor( $user )
41        );
42
43        return [
44            'prefix' => $prefix,
45            'limit' => $limit,
46            'usernames' => $dataFilter
47                ->prefix( $prefix )
48                ->limit( $limit )
49                ->getUsernames()
50        ];
51    }
52
53    /** @inheritDoc */
54    public function getParamSettings() {
55        return [
56            'prefix' => [
57                self::PARAM_SOURCE => 'path',
58                ParamValidator::PARAM_REQUIRED => true,
59                ParamValidator::PARAM_TYPE => 'string',
60            ],
61            'limit' => [
62                self::PARAM_SOURCE => 'query',
63                ParamValidator::PARAM_TYPE => 'integer',
64                ParamValidator::PARAM_REQUIRED => false,
65            ],
66        ];
67    }
68}