Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
3.33% covered (danger)
3.33%
1 / 30
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TransformWikitextToLintHandler
3.33% covered (danger)
3.33%
1 / 30
33.33% covered (danger)
33.33%
1 / 3
11.13
0.00% covered (danger)
0.00%
0 / 1
 getParamSettings
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRequestBodySchema
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
2
 getResponseBodySchemaFileName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Rest\Handler;
4
5/**
6 * Handler for transforming content given in the request.
7 *
8 * This class primarily deals with parameter validation and OpenAPI spec generation.
9 * Everything else is handled by the base class.
10 *
11 * TODO: reconsider the ParsoidHandler => TransformHandler hierarchy. Consider consolidating
12 *     classes and moving more validation into functions like getParamSettings(),
13 *     getBodyParamSettings(), etc.
14 *
15 * @unstable Pending consolidation of the Parsoid extension with core code.
16 */
17class TransformWikitextToLintHandler extends TransformHandler {
18
19    /** @inheritDoc */
20    public function getParamSettings() {
21        return [];
22    }
23
24    /**
25     * The parent TransformHandler class accepts a variety of body parameters in different
26     * situations, some of which can accept values in multiple types and therefore cannot
27     * be described in getBodyParamSettings(). See TransformHandler::execute(), and notice
28     * that both "wikitext" and "html" can be either a string or an object.
29     *
30     * We therefore define a request body schema directly rather than the more common approach of
31     * generating it from definitions in getBodyParamSettings().
32     */
33    protected function getRequestBodySchema( string $mediaType ): array {
34        return [
35            'oneOf' => [
36                [
37                    'type' => 'object',
38                    'properties' => [
39                        'wikitext' => [
40                            'type' => 'string',
41                        ]
42                    ]
43                ],
44                [
45                    'type' => 'object',
46                    'properties' => [
47                        'wikitext' => [
48                            'type' => 'object',
49                            'properties' => [
50                                'headers' => [
51                                    'type' => 'object',
52                                ],
53                                'body' => [
54                                    'type' => 'string',
55                                ]
56                            ]
57                        ]
58                    ]
59                ]
60            ],
61        ];
62    }
63
64    public function getResponseBodySchemaFileName( string $method ): ?string {
65        return __DIR__ . '/Schema/ContentLintErrors.json';
66    }
67}