Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
SurveyAudience | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace QuickSurveys; |
4 | |
5 | use Wikimedia\Assert\ParameterTypeException; |
6 | |
7 | class SurveyAudience extends Schema { |
8 | |
9 | /** |
10 | * A list of keys that need to be defined in a date range. |
11 | */ |
12 | private const VALID_DATE_RANGE_KEYS = [ |
13 | 'from' => 'string', |
14 | 'to' => 'string', |
15 | ]; |
16 | |
17 | /** |
18 | * A list of accepted audience keys and their required types. |
19 | */ |
20 | private const VALID_AUDIENCE_KEYS = [ |
21 | 'minEdits' => 'integer', |
22 | 'maxEdits' => 'integer', |
23 | 'countries' => 'array', |
24 | 'anons' => 'boolean', |
25 | 'registrationStart' => 'string', |
26 | 'registrationEnd' => 'string', |
27 | 'pageIds' => 'array', |
28 | 'userAgent' => 'array', |
29 | 'firstEdit' => [ self::ARRAY, self::VALID_DATE_RANGE_KEYS ], |
30 | 'lastEdit' => [ self::ARRAY, self::VALID_DATE_RANGE_KEYS ], |
31 | ]; |
32 | |
33 | /** |
34 | * Validate a survey audience definition. |
35 | * |
36 | * @param array $audienceDefinition defining the audience with keys |
37 | * that match the available keys defined in VALID_KEYS |
38 | * @throws ParameterTypeException when a key has the wrong type |
39 | */ |
40 | public function __construct( array $audienceDefinition ) { |
41 | parent::__construct( $audienceDefinition, self::VALID_AUDIENCE_KEYS ); |
42 | } |
43 | } |