Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ZKeyReference
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDefinition
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 isValid
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getZValue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * WikiLambda ZKeyReference
4 *
5 * @file
6 * @ingroup Extensions
7 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
8 * @license MIT
9 */
10
11namespace MediaWiki\Extension\WikiLambda\ZObjects;
12
13use MediaWiki\Extension\WikiLambda\Registry\ZTypeRegistry;
14use MediaWiki\Extension\WikiLambda\ZObjectUtils;
15
16class ZKeyReference extends ZObject {
17
18    /**
19     * Construct a ZKeyReference instance, bypassing the internal ZString formally contained.
20     *
21     * @param string $value
22     */
23    public function __construct( $value ) {
24        $this->data[ ZTypeRegistry::Z_KEYREFERENCE_VALUE ] = $value;
25    }
26
27    /**
28     * @inheritDoc
29     */
30    public static function getDefinition(): array {
31        return [
32            'type' => [
33                'type' => ZTypeRegistry::Z_REFERENCE,
34                'value' => ZTypeRegistry::Z_KEYREFERENCE,
35            ],
36            'keys' => [
37                ZTypeRegistry::Z_KEYREFERENCE_VALUE => [
38                    'type' => ZTypeRegistry::BUILTIN_STRING,
39                    'default' => ''
40                ],
41            ],
42        ];
43    }
44
45    /**
46     * @inheritDoc
47     */
48    public function isValid(): bool {
49        if ( !is_string( $this->data[ ZTypeRegistry::Z_KEYREFERENCE_VALUE ] ) ) {
50            return false;
51        }
52        return ZObjectUtils::isValidZObjectKey( $this->data[ ZTypeRegistry::Z_KEYREFERENCE_VALUE ] );
53    }
54
55    /**
56     * Get string value of the ZKeyReference object
57     *
58     * @return string The identifier of the ZKey referred by this ZObject
59     */
60    public function getZValue() {
61        return $this->data[ ZTypeRegistry::Z_KEYREFERENCE_VALUE ];
62    }
63}