Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryMentorList
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace GrowthExperiments\Api;
4
5use GrowthExperiments\Mentorship\Provider\AbstractStructuredMentorWriter;
6use GrowthExperiments\Mentorship\Provider\MentorProvider;
7use MediaWiki\Api\ApiQuery;
8use MediaWiki\Api\ApiQueryBase;
9use MediaWiki\User\UserIdentityLookup;
10
11class ApiQueryMentorList extends ApiQueryBase {
12
13    private UserIdentityLookup $userIdentityLookup;
14    private MentorProvider $mentorProvider;
15
16    public function __construct(
17        ApiQuery $queryModule,
18        string $moduleName,
19        UserIdentityLookup $userIdentityLookup,
20        MentorProvider $mentorProvider
21    ) {
22        parent::__construct( $queryModule, $moduleName );
23        $this->userIdentityLookup = $userIdentityLookup;
24        $this->mentorProvider = $mentorProvider;
25    }
26
27    /**
28     * @inheritDoc
29     */
30    public function execute() {
31        $result = [];
32        $mentorNames = $this->mentorProvider->getMentorsSafe();
33        foreach ( $mentorNames as $mentorName ) {
34            $mentorUser = $this->userIdentityLookup->getUserIdentityByName( $mentorName );
35            if ( !$mentorUser ) {
36                continue;
37            }
38            $mentor = $this->mentorProvider->newMentorFromUserIdentity( $mentorUser );
39            $result[$mentorUser->getId()] = AbstractStructuredMentorWriter::serializeMentor( $mentor );
40
41            // for convenience of the consumers
42            $result[$mentorUser->getId()]['username'] = $mentorUser->getName();
43        }
44
45        // NOTE: Continuation support is not implemented, because all mentors are always
46        // stored in MediaWiki:GrowthMentors.json, which (being a regular wiki page) has no
47        // continuation support either.
48        $this->getResult()->addValue( null, $this->getModuleName(), $result );
49    }
50}