Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
83.33% |
5 / 6 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
ParserFunctionTracker | |
83.33% |
5 / 6 |
|
50.00% |
1 / 2 |
5.12 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
addTrackingCategories | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
4.13 |
1 | <?php |
2 | |
3 | namespace Kartographer; |
4 | |
5 | use InvalidArgumentException; |
6 | use MediaWiki\Parser\Parser; |
7 | |
8 | /** |
9 | * @license MIT |
10 | */ |
11 | class ParserFunctionTracker { |
12 | |
13 | private Parser $parser; |
14 | |
15 | public function __construct( Parser $parser ) { |
16 | $this->parser = $parser; |
17 | } |
18 | |
19 | /** |
20 | * @param array<string,bool> $messages |
21 | */ |
22 | public function addTrackingCategories( array $messages ): void { |
23 | foreach ( $messages as $msg => $enabled ) { |
24 | if ( !is_bool( $enabled ) ) { |
25 | throw new InvalidArgumentException( '$messages must be an array mapping message keys to booleans' ); |
26 | } |
27 | |
28 | // Messages used here: |
29 | // * kartographer-broken-category |
30 | // * kartographer-tracking-category |
31 | if ( $enabled ) { |
32 | $this->parser->addTrackingCategory( $msg ); |
33 | } |
34 | } |
35 | } |
36 | |
37 | } |