Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ListParam
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 getListType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 dump
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Wikimedia\Message;
4
5/**
6 * Value object representing a message parameter that consists of a list of values.
7 *
8 * Message parameter classes are pure value objects and are safely newable.
9 *
10 * @newable
11 */
12class ListParam extends MessageParam {
13    private $listType;
14
15    /**
16     * @stable to call.
17     *
18     * @param string $listType One of the ListType constants.
19     * @param (MessageParam|MessageValue|string|int|float)[] $elements Values in the list.
20     *  Values that are not instances of MessageParam are wrapped using ParamType::TEXT.
21     */
22    public function __construct( $listType, array $elements ) {
23        $this->type = ParamType::LIST;
24        $this->listType = $listType;
25        $this->value = [];
26        foreach ( $elements as $element ) {
27            if ( $element instanceof MessageParam ) {
28                $this->value[] = $element;
29            } else {
30                $this->value[] = new ScalarParam( ParamType::TEXT, $element );
31            }
32        }
33    }
34
35    /**
36     * Get the type of the list
37     *
38     * @return string One of the ListType constants
39     */
40    public function getListType() {
41        return $this->listType;
42    }
43
44    public function dump() {
45        $contents = '';
46        foreach ( $this->value as $element ) {
47            $contents .= $element->dump();
48        }
49        return "<{$this->type} listType=\"{$this->listType}\">$contents</{$this->type}>";
50    }
51}