Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
LegacyGetMentorDataTrait | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
getMentorData | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Mentorship\Provider; |
4 | |
5 | use GrowthExperiments\Config\WikiPageConfigLoader; |
6 | use MediaWiki\Status\Status; |
7 | use MediaWiki\Title\Title; |
8 | use Psr\Log\LoggerAwareTrait; |
9 | use StatusValue; |
10 | |
11 | /** |
12 | * Helper to share code between StructuredMentorWriter and StructuredMentorProvider |
13 | * |
14 | * This declares WikiPageConfigLoader $configLoader and LinkTarget $mentorList as private |
15 | * variables, which need to be set by the constructor. |
16 | */ |
17 | trait LegacyGetMentorDataTrait { |
18 | use LoggerAwareTrait; |
19 | |
20 | private WikiPageConfigLoader $configLoader; |
21 | private Title $mentorList; |
22 | |
23 | /** |
24 | * Wrapper around WikiPageConfigLoader |
25 | * |
26 | * Guaranteed to return a valid mentor list. If a valid mentor list cannot be constructed |
27 | * using the wiki page, it constructs an empty mentor list instead and logs an error. |
28 | * |
29 | * This is cached within WikiPageConfigLoader. |
30 | * |
31 | * @return array |
32 | */ |
33 | protected function getMentorData(): array { |
34 | $res = $this->configLoader->load( $this->mentorList ); |
35 | if ( $res instanceof StatusValue ) { |
36 | // Loading the mentor list failed. Log an error and return an empty array. |
37 | $this->logger->error( |
38 | __METHOD__ . ' failed to load mentor list: {error}', |
39 | [ |
40 | 'error' => Status::wrap( $res )->getWikiText( false, false, 'en' ), |
41 | 'impact' => 'No data about mentors can be found; wiki behaves as if it had no mentors at all' |
42 | ] |
43 | ); |
44 | return []; |
45 | } |
46 | return $res['Mentors']; |
47 | } |
48 | |
49 | } |