Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
CommunityGetMentorDataTrait | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
getMentorData | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Mentorship\Provider; |
4 | |
5 | use MediaWiki\Extension\CommunityConfiguration\Provider\IConfigurationProvider; |
6 | use MediaWiki\Status\StatusFormatter; |
7 | use Psr\Log\LoggerAwareTrait; |
8 | use RuntimeException; |
9 | |
10 | trait CommunityGetMentorDataTrait { |
11 | use LoggerAwareTrait; |
12 | |
13 | private IConfigurationProvider $provider; |
14 | private StatusFormatter $statusFormatter; |
15 | |
16 | protected function getMentorData(): array { |
17 | $result = $this->provider->loadValidConfiguration(); |
18 | if ( !$result->isOK() ) { |
19 | // Loading the mentor list failed. Log an error and return an empty array. |
20 | $this->logger->error( ...$this->statusFormatter->getPsr3MessageAndContext( $result, [ |
21 | 'impact' => 'No data about mentors can be found; wiki behaves as if it had no mentors at all', |
22 | ] ) ); |
23 | return []; |
24 | } |
25 | |
26 | // needed to receive an associative array |
27 | // REVIEW: Do we want to keep this? See T369608. |
28 | $data = json_decode( |
29 | json_encode( $result->getValue() ), |
30 | true |
31 | ); |
32 | if ( !is_array( $data ) ) { |
33 | $this->logger->error( |
34 | __METHOD__ . ' failed to convert mentor list to an associative array', |
35 | [ |
36 | 'impact' => 'No data about mentors can be found; wiki behaves as if it had no mentors at all', |
37 | 'exception' => new RuntimeException, |
38 | ] |
39 | ); |
40 | return []; |
41 | } |
42 | if ( !array_key_exists( AbstractStructuredMentorWriter::CONFIG_KEY, $data ) ) { |
43 | // TODO: Remove this when the mentor list gets a JSON schema (CONFIG_KEY will be then |
44 | // populated via the defaults system). |
45 | return []; |
46 | } |
47 | return $data[AbstractStructuredMentorWriter::CONFIG_KEY]; |
48 | } |
49 | } |