Completed
Push — master ( 1b65e5...7464ba )
by
unknown
02:16
created

QualifierContextCursor::getEntityId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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 QualifierContextCursor 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
	 * @param string $entityId
37
	 * @param string $statementPropertyId
38
	 * @param string $statementGuid
39
	 * @param string $snakHash
40
	 * @param string $snakPropertyId
41
	 */
42 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...
43
		$entityId,
44
		$statementPropertyId,
45
		$statementGuid,
46
		$snakHash,
47
		$snakPropertyId
48
	) {
49
		$this->entityId = $entityId;
50
		$this->statementPropertyId = $statementPropertyId;
51
		$this->statementGuid = $statementGuid;
52
		$this->snakHash = $snakHash;
53
		$this->snakPropertyId = $snakPropertyId;
54
	}
55
56
	/**
57
	 * @codeCoverageIgnore This method is purely declarative.
58
	 */
59
	public function getType() {
60
		return Context::TYPE_QUALIFIER;
61
	}
62
63
	public function getEntityId() {
64
		return $this->entityId;
65
	}
66
67
	public function getStatementPropertyId() {
68
		return $this->statementPropertyId;
69
	}
70
71
	public function getStatementGuid() {
72
		return $this->statementGuid;
73
	}
74
75
	public function getSnakPropertyId() {
76
		return $this->snakPropertyId;
77
	}
78
79
	public function getSnakHash() {
80
		return $this->snakHash;
81
	}
82
83
	protected function &getMainArray( array &$container ) {
84
		$statementArray = &$this->getStatementArray( $container );
85
86
		if ( !array_key_exists( 'qualifiers', $statementArray ) ) {
87
			$statementArray['qualifiers'] = [];
88
		}
89
		$qualifiersArray = &$statementArray['qualifiers'];
90
91
		$snakPropertyId = $this->getSnakPropertyId();
92
		if ( !array_key_exists( $snakPropertyId, $qualifiersArray ) ) {
93
			$qualifiersArray[$snakPropertyId] = [];
94
		}
95
		$propertyArray = &$qualifiersArray[$snakPropertyId];
96
97
		$snakHash = $this->getSnakHash();
98
		foreach ( $propertyArray as &$potentialQualifierArray ) {
99
			if ( $potentialQualifierArray['hash'] === $snakHash ) {
100
				$qualifierArray = &$potentialQualifierArray;
101
				break;
102
			}
103
		}
104
		if ( !isset( $qualifierArray ) ) {
105
			$qualifierArray = [ 'hash' => $snakHash ];
106
			$propertyArray[] = &$qualifierArray;
107
		}
108
109
		return $qualifierArray;
110
	}
111
112
}
113