Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
ReferenceContextCursor
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
8 / 8
17
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getType
n/a
0 / 0
n/a
0 / 0
1
 getEntityId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStatementPropertyId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStatementGuid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSnakPropertyId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSnakHash
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getReferenceHash
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMainArray
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
1 / 1
9
1<?php
2
3namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Context;
4
5/**
6 * @license GPL-2.0-or-later
7 */
8class ReferenceContextCursor extends ApiV2ContextCursor {
9
10    /**
11     * @var string
12     */
13    private $entityId;
14
15    /**
16     * @var string
17     */
18    private $statementPropertyId;
19
20    /**
21     * @var string
22     */
23    private $statementGuid;
24
25    /**
26     * @var string
27     */
28    private $snakHash;
29
30    /**
31     * @var string
32     */
33    private $snakPropertyId;
34
35    /**
36     * @var string
37     */
38    private $referenceHash;
39
40    /**
41     * @param string $entityId
42     * @param string $statementPropertyId
43     * @param string $statementGuid
44     * @param string $snakHash
45     * @param string $snakPropertyId
46     * @param string $referenceHash
47     */
48    public function __construct(
49        $entityId,
50        $statementPropertyId,
51        $statementGuid,
52        $snakHash,
53        $snakPropertyId,
54        $referenceHash
55    ) {
56        $this->entityId = $entityId;
57        $this->statementPropertyId = $statementPropertyId;
58        $this->statementGuid = $statementGuid;
59        $this->snakHash = $snakHash;
60        $this->snakPropertyId = $snakPropertyId;
61        $this->referenceHash = $referenceHash;
62    }
63
64    /**
65     * @codeCoverageIgnore This method is purely declarative.
66     */
67    public function getType() {
68        return Context::TYPE_REFERENCE;
69    }
70
71    public function getEntityId() {
72        return $this->entityId;
73    }
74
75    public function getStatementPropertyId() {
76        return $this->statementPropertyId;
77    }
78
79    public function getStatementGuid() {
80        return $this->statementGuid;
81    }
82
83    public function getSnakPropertyId() {
84        return $this->snakPropertyId;
85    }
86
87    public function getSnakHash() {
88        return $this->snakHash;
89    }
90
91    public function getReferenceHash() {
92        return $this->referenceHash;
93    }
94
95    protected function &getMainArray( array &$container ) {
96        $statementArray = &$this->getStatementArray( $container );
97
98        if ( !array_key_exists( 'references', $statementArray ) ) {
99            $statementArray['references'] = [];
100        }
101        $referencesArray = &$statementArray['references'];
102
103        $referenceHash = $this->getReferenceHash();
104        foreach ( $referencesArray as &$potentialReferenceArray ) {
105            if ( $potentialReferenceArray['hash'] === $referenceHash ) {
106                $referenceArray = &$potentialReferenceArray;
107                break;
108            }
109        }
110        if ( !isset( $referenceArray ) ) {
111            $referenceArray = [ 'hash' => $referenceHash, 'snaks' => [] ];
112            $referencesArray[] = &$referenceArray;
113        }
114
115        $snaksArray = &$referenceArray['snaks'];
116
117        $snakPropertyId = $this->getSnakPropertyId();
118        if ( !array_key_exists( $snakPropertyId, $snaksArray ) ) {
119            $snaksArray[$snakPropertyId] = [];
120        }
121        $propertyArray = &$snaksArray[$snakPropertyId];
122
123        $snakHash = $this->getSnakHash();
124        foreach ( $propertyArray as &$potentialSnakArray ) {
125            if ( $potentialSnakArray['hash'] === $snakHash ) {
126                $snakArray = &$potentialSnakArray;
127                break;
128            }
129        }
130        if ( !isset( $snakArray ) ) {
131            $snakArray = [ 'hash' => $snakHash ];
132            $propertyArray[] = &$snakArray;
133        }
134
135        return $snakArray;
136    }
137
138}