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