Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
MentorProvider | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSignupTitle | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
newMentorFromUserIdentity | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
isMentor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
getMentors | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getMentorsSafe | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
getAutoAssignedMentors | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getWeightedAutoAssignedMentors | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getManuallyAssignedMentors | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Mentorship\Provider; |
4 | |
5 | use GrowthExperiments\Mentorship\Mentor; |
6 | use GrowthExperiments\WikiConfigException; |
7 | use MediaWiki\Title\Title; |
8 | use MediaWiki\User\UserIdentity; |
9 | use Psr\Log\LoggerAwareTrait; |
10 | use Psr\Log\NullLogger; |
11 | |
12 | abstract class MentorProvider { |
13 | use LoggerAwareTrait; |
14 | |
15 | public function __construct() { |
16 | $this->setLogger( new NullLogger() ); |
17 | } |
18 | |
19 | /** @var int Maximum mentor intro length. */ |
20 | public const INTRO_TEXT_LENGTH = 240; |
21 | |
22 | /** |
23 | * Returns a Title to the signup page, if it exists |
24 | * |
25 | * @return Title|null |
26 | */ |
27 | abstract public function getSignupTitle(): ?Title; |
28 | |
29 | /** |
30 | * Construct a Mentor object for given UserIdentity |
31 | * |
32 | * This is useful for when you know the mentor's username, and need MentorManager to provide |
33 | * specific details about them. |
34 | * |
35 | * The caller needs to ensure $mentorUser is a mentor (otherwise, implementation may |
36 | * throw). You can use MentorProvider::isMentor() for that purpose. |
37 | * |
38 | * @param UserIdentity $mentorUser Caller needs to ensure $mentorUser is a mentor |
39 | * @param UserIdentity|null $menteeUser If passed, may be used to customize message using |
40 | * mentee's username. |
41 | * @return Mentor |
42 | */ |
43 | abstract public function newMentorFromUserIdentity( |
44 | UserIdentity $mentorUser, |
45 | ?UserIdentity $menteeUser = null |
46 | ): Mentor; |
47 | |
48 | /** |
49 | * Checks if an user is a mentor (regardless of their auto-assignment status) |
50 | * @param UserIdentity $user |
51 | * @return bool |
52 | */ |
53 | public function isMentor( UserIdentity $user ): bool { |
54 | return $user->isRegistered() && in_array( $user->getName(), $this->getMentorsSafe() ); |
55 | } |
56 | |
57 | /** |
58 | * Get all mentors, regardless on their auto-assignment status |
59 | * @throws WikiConfigException If the mentor page cannot be fetched due to misconfiguration. |
60 | * @return string[] List of mentors usernames. |
61 | */ |
62 | public function getMentors(): array { |
63 | return array_unique( |
64 | array_merge( |
65 | $this->getAutoAssignedMentors(), |
66 | $this->getManuallyAssignedMentors() |
67 | ) |
68 | ); |
69 | } |
70 | |
71 | /** |
72 | * Get all mentors, regardless of their auto-assignment status |
73 | * |
74 | * This does the same thing as getMentors(), but it suppresses any instance |
75 | * of WikiConfigException (and returns an empty array instead). |
76 | * |
77 | * @return string[] |
78 | */ |
79 | public function getMentorsSafe(): array { |
80 | $mentors = []; |
81 | try { |
82 | $mentors = array_merge( $mentors, $this->getAutoAssignedMentors() ); |
83 | } catch ( WikiConfigException $e ) { |
84 | } |
85 | try { |
86 | $mentors = array_merge( $mentors, $this->getManuallyAssignedMentors() ); |
87 | } catch ( WikiConfigException $e ) { |
88 | } |
89 | return array_unique( $mentors ); |
90 | } |
91 | |
92 | /** |
93 | * Get all the mentors who are automatically assigned to mentees. |
94 | * @throws WikiConfigException If the mentor page cannot be fetched due to misconfiguration. |
95 | * @return string[] List of mentor usernames. |
96 | */ |
97 | abstract public function getAutoAssignedMentors(): array; |
98 | |
99 | /** |
100 | * Get weighted list of automatically assigned mentors |
101 | * |
102 | * If a mentor is configured to receive more mentees than others, the returned array will |
103 | * have their name multiple times. |
104 | * |
105 | * @return string[] Array of usernames |
106 | */ |
107 | abstract public function getWeightedAutoAssignedMentors(): array; |
108 | |
109 | /** |
110 | * Get a list of mentors who are not automatically assigned to mentees. |
111 | * @throws WikiConfigException If the mentor page cannot be fetched due to misconfiguration. |
112 | * @return string[] List of mentors usernames. |
113 | */ |
114 | abstract public function getManuallyAssignedMentors(): array; |
115 | } |