Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ContextCursorSerializer
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 serialize
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Context;
4
5/**
6 * A serializer for {@link ContextCursor}s.
7 *
8 * @license GPL-2.0-or-later
9 */
10class ContextCursorSerializer {
11
12    /**
13     * @param ContextCursor $cursor
14     * @return array
15     */
16    public function serialize( ContextCursor $cursor ) {
17        if ( $cursor instanceof EntityContextCursor ) {
18            return [
19                't' => '\entity',
20                'i' => $cursor->getEntityId(),
21            ];
22        }
23
24        $type = $cursor->getType();
25        $serialization = [
26            't' => $type,
27            'i' => $cursor->getEntityId(),
28            'p' => $cursor->getStatementPropertyId(),
29            'g' => $cursor->getStatementGuid(),
30            'h' => $cursor->getSnakHash(),
31        ];
32
33        if ( $type === Context::TYPE_QUALIFIER || $type === Context::TYPE_REFERENCE ) {
34            $serialization['P'] = $cursor->getSnakPropertyId();
35            if ( $type === Context::TYPE_REFERENCE ) {
36                /** @var ReferenceContextCursor $cursor */
37                '@phan-var ReferenceContextCursor $cursor';
38                $serialization['r'] = $cursor->getReferenceHash();
39            }
40        }
41
42        return $serialization;
43    }
44
45}