Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Outreach | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
isCampaignActive | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
isUserEligible | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | namespace MobileFrontend\Amc; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | use MediaWiki\Config\ConfigException; |
7 | use MediaWiki\User\User; |
8 | |
9 | final class Outreach { |
10 | /** |
11 | * Config name used to enable/disable the AMC Outreach feature |
12 | */ |
13 | private const CONFIG_NAME = 'MFAmcOutreach'; |
14 | |
15 | /** |
16 | * Config name used to set the minimum number of edits a user must make before |
17 | * they will be eligible for AMC Outreach |
18 | */ |
19 | private const MIN_EDIT_COUNT_CONFIG_NAME = 'MFAmcOutreachMinEditCount'; |
20 | |
21 | /** |
22 | * @var UserMode |
23 | */ |
24 | private $userMode; |
25 | /** |
26 | * @var User |
27 | */ |
28 | private $user; |
29 | /** |
30 | * @var Manager |
31 | */ |
32 | private $amc; |
33 | |
34 | /** |
35 | * System config |
36 | * @var Config |
37 | */ |
38 | private $config; |
39 | |
40 | /** |
41 | * @param UserMode $userMode |
42 | * @param Manager $amcManager |
43 | * @param User $user |
44 | * @param Config $config |
45 | */ |
46 | public function __construct( |
47 | UserMode $userMode, Manager $amcManager, User $user, Config $config |
48 | ) { |
49 | $this->userMode = $userMode; |
50 | $this->amc = $amcManager; |
51 | $this->user = $user; |
52 | $this->config = $config; |
53 | } |
54 | |
55 | /** |
56 | * Whether or not the outreach campaign is turned on and amc is available |
57 | * |
58 | * @return bool |
59 | */ |
60 | public function isCampaignActive() { |
61 | return $this->config->get( self::CONFIG_NAME ) && |
62 | $this->amc->isAvailable(); |
63 | } |
64 | |
65 | /** |
66 | * Whether or not the current user is eligible to see the outreach campaign |
67 | * |
68 | * @return bool |
69 | * @throws ConfigException |
70 | */ |
71 | public function isUserEligible() { |
72 | return $this->isCampaignActive() && |
73 | !$this->userMode->isEnabled() && |
74 | $this->user->getEditCount() >= $this->config->get( self::MIN_EDIT_COUNT_CONFIG_NAME ) && |
75 | // T231057: Don't show drawer during browser tests |
76 | !$this->user->isBot(); |
77 | } |
78 | } |