Completed
Push — master ( 5a9251...e48e23 )
by
unknown
03:04
created

ReferenceContextCursor::getMainArray()   D

Complexity

Conditions 9
Paths 144

Size

Total Lines 44
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 4.6666
c 0
b 0
f 0
cc 9
eloc 28
nc 144
nop 1
1
<?php
2
3
namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Context;
4
5
/**
6
 * @license GNU GPL v2+
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
	protected function &getMainArray( array &$container ) {
65
		$statementArray = &$this->getStatementArray(
66
			$container,
67
			$this->entityId,
68
			$this->statementPropertyId,
69
			$this->statementGuid
70
		);
71
72
		if ( !array_key_exists( 'references', $statementArray ) ) {
73
			$statementArray['references'] = [];
74
		}
75
		$referencesArray = &$statementArray['references'];
76
77
		foreach ( $referencesArray as &$potentialReferenceArray ) {
78
			if ( $potentialReferenceArray['hash'] === $this->referenceHash ) {
79
				$referenceArray = &$potentialReferenceArray;
80
				break;
81
			}
82
		}
83
		if ( !isset( $referenceArray ) ) {
84
			$referenceArray = [ 'hash' => $this->referenceHash, 'snaks' => [] ];
85
			$referencesArray[] = &$referenceArray;
86
		}
87
88
		$snaksArray = &$referenceArray['snaks'];
89
90
		if ( !array_key_exists( $this->snakPropertyId, $snaksArray ) ) {
91
			$snaksArray[$this->snakPropertyId] = [];
92
		}
93
		$propertyArray = &$snaksArray[$this->snakPropertyId];
94
95
		foreach ( $propertyArray as &$potentialSnakArray ) {
96
			if ( $potentialSnakArray['hash'] === $this->snakHash ) {
97
				$snakArray = &$potentialSnakArray;
98
				break;
99
			}
100
		}
101
		if ( !isset( $snakArray ) ) {
102
			$snakArray = [ 'hash' => $this->snakHash ];
103
			$propertyArray[] = &$snakArray;
104
		}
105
106
		return $snakArray;
107
	}
108
109
}
110