Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UnsupportedContentTypeBodyValidator
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validateBody
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Rest\Validator;
4
5use MediaWiki\Rest\LocalizedHttpException;
6use MediaWiki\Rest\RequestInterface;
7use Wikimedia\Message\MessageValue;
8
9/**
10 * Validator that always fails. Meant as a convenience for Handler::getBodyValidator():
11 *
12 *     public function getBodyValidator( $contentType ) {
13 *         if ( $contentType === 'supported/content-type' ) {
14 *             return new MyValidator();
15 *         }
16 *         return new UnsupportedContentTypeBodyValidator( $contentType );
17 *     }
18 *
19 * @since 1.40
20 */
21class UnsupportedContentTypeBodyValidator implements BodyValidator {
22
23    /** @var string */
24    private string $contentType;
25
26    /**
27     * @param string $contentType
28     */
29    public function __construct( string $contentType ) {
30        $this->contentType = $contentType;
31    }
32
33    /**
34     * @inheritDoc
35     * @return never
36     */
37    public function validateBody( RequestInterface $request ) {
38        throw new LocalizedHttpException(
39            new MessageValue( 'rest-unsupported-content-type', [ $this->contentType ] ),
40            415
41        );
42    }
43
44}