Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
96.88% |
31 / 32 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
ManageMentorsRemoveMentor | |
96.88% |
31 / 32 |
|
75.00% |
3 / 4 |
5 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
getFormFields | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
onSubmit | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
2.01 | |||
onSuccess | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Specials\Forms; |
4 | |
5 | use GrowthExperiments\Mentorship\MentorRemover; |
6 | use MediaWiki\Context\IContextSource; |
7 | use MediaWiki\Status\Status; |
8 | use MediaWiki\User\UserIdentity; |
9 | |
10 | class ManageMentorsRemoveMentor extends ManageMentorsAbstractForm { |
11 | |
12 | private UserIdentity $mentorUser; |
13 | private MentorRemover $mentorRemover; |
14 | |
15 | /** |
16 | * @param MentorRemover $mentorRemover |
17 | * @param UserIdentity $mentorUser |
18 | * @param IContextSource $context |
19 | */ |
20 | public function __construct( |
21 | MentorRemover $mentorRemover, |
22 | UserIdentity $mentorUser, |
23 | IContextSource $context |
24 | ) { |
25 | $this->mentorUser = $mentorUser; |
26 | parent::__construct( |
27 | $context, |
28 | 'growthexperiments-manage-mentors-' |
29 | ); |
30 | |
31 | $this->mentorRemover = $mentorRemover; |
32 | |
33 | $this->setPreHtml( $this->msg( |
34 | 'growthexperiments-manage-mentors-remove-mentor-pretext', |
35 | $mentorUser->getName() |
36 | )->parse() ); |
37 | } |
38 | |
39 | /** |
40 | * @inheritDoc |
41 | */ |
42 | protected function getFormFields(): array { |
43 | return [ |
44 | 'reason' => [ |
45 | 'type' => 'text', |
46 | 'label-message' => 'growthexperiments-manage-mentors-remove-mentor-reason', |
47 | ] |
48 | ]; |
49 | } |
50 | |
51 | /** |
52 | * @inheritDoc |
53 | */ |
54 | public function onSubmit( array $data ) { |
55 | if ( !self::canManageMentors( $this->getAuthority() ) ) { |
56 | return false; |
57 | } |
58 | |
59 | return Status::wrap( $this->mentorRemover->removeMentor( |
60 | $this->getUser(), |
61 | $this->mentorUser, |
62 | $data['reason'], |
63 | $this->getContext() |
64 | ) ); |
65 | } |
66 | |
67 | /** |
68 | * @inheritDoc |
69 | */ |
70 | protected function onSuccess(): void { |
71 | $out = $this->getOutput(); |
72 | $out->addWikiMsg( |
73 | 'growthexperiments-manage-mentors-remove-mentor-success', |
74 | $this->mentorUser->getName() |
75 | ); |
76 | $out->addWikiMsg( |
77 | 'growthexperiments-manage-mentors-return-back' |
78 | ); |
79 | } |
80 | } |