Completed
Push — master ( f2f357...ccb861 )
by
unknown
02:21
created

ReferenceContextCursor::getReferenceHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Context;
4
5
/**
6
 * @license GPL-2.0-or-later
7
 */
8
class 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 View Code Duplication
	public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
}
139