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