Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ArrayDef
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
3.14
0.00% covered (danger)
0.00%
0 / 1
 supportsArrays
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validate
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace MediaWiki\ParamValidator\TypeDef;
4
5use Wikimedia\ParamValidator\TypeDef;
6
7/**
8 * Type definition for array structures, typically
9 * used for validating JSON request bodies.
10 *
11 * Failure codes:
12 *  - 'notarray': The value is not an array.
13 *
14 * @todo implement validation based on a JSON schema
15 *
16 * @since 1.42
17 */
18class ArrayDef extends TypeDef {
19
20    public function supportsArrays() {
21        return true;
22    }
23
24    public function validate( $name, $value, array $settings, array $options ) {
25        if ( !is_array( $value ) ) {
26            // Message used: paramvalidator-notarray
27            $this->failure( 'notarray', $name, $value, $settings, $options );
28        }
29
30        return $value;
31    }
32
33}