Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ChartArgumentsParser | |
0.00% |
0 / 36 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
parseArguments | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
90 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Chart; |
4 | |
5 | use MediaWiki\Parser\Parser; |
6 | |
7 | class ChartArgumentsParser { |
8 | private DataPageResolver $dataPageResolver; |
9 | |
10 | public function __construct( DataPageResolver $dataPageResolver ) { |
11 | $this->dataPageResolver = $dataPageResolver; |
12 | } |
13 | |
14 | public function parseArguments( Parser $parser, array $args ): ParsedArguments { |
15 | $magicWords = $parser->getMagicWordFactory()->newArray( [ |
16 | 'chart_data' |
17 | ] ); |
18 | |
19 | $definition = array_shift( $args ); |
20 | $dataSource = null; |
21 | $options = []; |
22 | |
23 | $errors = []; |
24 | foreach ( $args as $arg ) { |
25 | if ( str_contains( $arg, '=' ) ) { |
26 | [ $key, $value ] = array_map( 'trim', explode( '=', $arg, 2 ) ); |
27 | switch ( $magicWords->matchStartToEnd( $key ) ) { |
28 | case 'chart_data': |
29 | $dataSource = $value; |
30 | break; |
31 | default: |
32 | // no-op |
33 | } |
34 | } |
35 | } |
36 | |
37 | $definitionTitle = null; |
38 | if ( $definition === null ) { |
39 | $errors[] = [ |
40 | 'key' => 'chart-error-chart-definition-not-found', |
41 | 'params' => [] |
42 | ]; |
43 | } else { |
44 | $definitionTitle = $this->dataPageResolver->resolvePageInDataNamespace( $definition ); |
45 | |
46 | if ( !$definitionTitle ) { |
47 | $errors[] = [ |
48 | 'key' => 'chart-error-chart-definition-not-found', |
49 | 'params' => [] |
50 | ]; |
51 | } |
52 | } |
53 | |
54 | $dataTitle = null; |
55 | if ( $dataSource !== null ) { |
56 | $dataTitle = $this->dataPageResolver->resolvePageInDataNamespace( $dataSource ); |
57 | if ( !$dataTitle ) { |
58 | $errors[] = [ |
59 | 'key' => 'chart-error-data-source-page-not-found', |
60 | 'params' => [] |
61 | ]; |
62 | } |
63 | } |
64 | |
65 | return new ParsedArguments( $definitionTitle, $dataTitle, $options, $errors ); |
66 | } |
67 | |
68 | } |