Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
19 / 19 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
ZReference | |
100.00% |
19 / 19 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDefinition | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
isValid | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getSerialized | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getZValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * WikiLambda ZReference |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
8 | * @license MIT |
9 | */ |
10 | |
11 | namespace MediaWiki\Extension\WikiLambda\ZObjects; |
12 | |
13 | use MediaWiki\Extension\WikiLambda\Registry\ZTypeRegistry; |
14 | use MediaWiki\Extension\WikiLambda\ZObjectUtils; |
15 | |
16 | class ZReference extends ZObject { |
17 | |
18 | /** |
19 | * Construct a ZReference instance given the string value of the Zid which it references to |
20 | * |
21 | * @param string $value |
22 | */ |
23 | public function __construct( $value ) { |
24 | $this->data[ ZTypeRegistry::Z_REFERENCE_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_REFERENCE, |
35 | ], |
36 | 'keys' => [ |
37 | ZTypeRegistry::Z_REFERENCE_VALUE => [ |
38 | 'type' => ZTypeRegistry::BUILTIN_REFERENCE |
39 | ], |
40 | ], |
41 | ]; |
42 | } |
43 | |
44 | /** |
45 | * @inheritDoc |
46 | */ |
47 | public function isValid(): bool { |
48 | if ( !is_string( $this->data[ ZTypeRegistry::Z_REFERENCE_VALUE ] ) ) { |
49 | return false; |
50 | } |
51 | return ZObjectUtils::isValidZObjectReference( $this->data[ ZTypeRegistry::Z_REFERENCE_VALUE ] ); |
52 | } |
53 | |
54 | /** |
55 | * @inheritDoc |
56 | */ |
57 | public function getSerialized( $form = self::FORM_CANONICAL ) { |
58 | if ( $form === self::FORM_CANONICAL ) { |
59 | return $this->getZValue(); |
60 | } else { |
61 | return parent::getSerialized(); |
62 | } |
63 | } |
64 | |
65 | /** |
66 | * Get the value of this ZReference |
67 | * |
68 | * @return string |
69 | */ |
70 | public function getZValue() { |
71 | return $this->data[ ZTypeRegistry::Z_REFERENCE_VALUE ]; |
72 | } |
73 | } |