Completed
Push — master ( 7464ba...bae15a )
by
unknown
02:18
created

ContextCursorSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 20 4
1
<?php
2
3
namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Context;
4
5
/**
6
 * A serializer for {@link ContextCursor}s.
7
 *
8
 * @license GNU GPL v2+
9
 */
10
class ContextCursorSerializer {
11
12
	/**
13
	 * @param ContextCursor $cursor
14
	 * @return array
15
	 */
16
	public function serialize( ContextCursor $cursor ) {
17
		$type = $cursor->getType();
18
		$serialization = [
19
			't' => $type,
20
			'i' => $cursor->getEntityId(),
21
			'p' => $cursor->getStatementPropertyId(),
22
			'g' => $cursor->getStatementGuid(),
23
			'h' => $cursor->getSnakHash(),
24
		];
25
26
		if ( $type === Context::TYPE_QUALIFIER || $type === Context::TYPE_REFERENCE ) {
27
			$serialization['P'] = $cursor->getSnakPropertyId();
28
			if ( $type === Context::TYPE_REFERENCE ) {
29
				/** @var ReferenceContextCursor $cursor */
30
				$serialization['r'] = $cursor->getReferenceHash();
31
			}
32
		}
33
34
		return $serialization;
35
	}
36
37
}
38