Completed
Push — master ( 9ffa4a...fe64de )
by
unknown
05:54
created
src/ConstraintCheck/Helper/LoggingHelper.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 		$this->dataFactory = $dataFactory;
49 49
 		$this->logger = $logger;
50 50
 		$this->constraintCheckDurationLimits = [
51
-			'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ),
52
-			'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ),
51
+			'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'),
52
+			'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'),
53 53
 		];
54 54
 	}
55 55
 
@@ -75,41 +75,41 @@  discard block
 block discarded – undo
75 75
 		$durationSeconds,
76 76
 		$method
77 77
 	) {
78
-		$constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 );
78
+		$constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1);
79 79
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
80 80
 
81 81
 		$this->dataFactory->timing(
82
-			'wikibase.quality.constraints.check.timing.' .
83
-				$constraintTypeItemId . '-' .
82
+			'wikibase.quality.constraints.check.timing.'.
83
+				$constraintTypeItemId.'-'.
84 84
 				$constraintCheckerClassShortName,
85 85
 			$durationSeconds * 1000
86 86
 		);
87 87
 
88 88
 		// find the longest limit (and associated log level) that the duration exceeds
89
-		foreach ( $this->constraintCheckDurationLimits as $level => $limit ) {
89
+		foreach ($this->constraintCheckDurationLimits as $level => $limit) {
90 90
 			if (
91 91
 				// duration exceeds this limit
92
-				isset( $limit ) && $durationSeconds > $limit &&
92
+				isset($limit) && $durationSeconds > $limit &&
93 93
 				// this limit is longer than previous longest limit
94
-				( !isset( $limitSeconds ) || $limit > $limitSeconds )
94
+				(!isset($limitSeconds) || $limit > $limitSeconds)
95 95
 			) {
96 96
 				$limitSeconds = $limit;
97 97
 				$logLevel = $level;
98 98
 			}
99 99
 		}
100 100
 
101
-		if ( !isset( $limitSeconds ) ) {
101
+		if (!isset($limitSeconds)) {
102 102
 			return;
103 103
 		}
104
-		if ( $context->getType() !== Context::TYPE_STATEMENT ) {
104
+		if ($context->getType() !== Context::TYPE_STATEMENT) {
105 105
 			// TODO log less details but still log something
106 106
 			return;
107 107
 		}
108 108
 
109 109
 		$this->logger->log(
110 110
 			$logLevel,
111
-			'Constraint check with {constraintCheckerClassShortName} ' .
112
-			'took longer than {limitSeconds} second(s) ' .
111
+			'Constraint check with {constraintCheckerClassShortName} '.
112
+			'took longer than {limitSeconds} second(s) '.
113 113
 			'(duration: {durationSeconds} seconds).',
114 114
 			[
115 115
 				'method' => $method,
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/RangeCheckerHelper.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		UnitConverter $unitConverter = null
48 48
 	) {
49 49
 		$this->config = $config;
50
-		$this->timeParser = ( new TimeParserFactory() )->getTimeParser();
50
+		$this->timeParser = (new TimeParserFactory())->getTimeParser();
51 51
 		$this->timeCalculator = new TimeValueCalculator();
52 52
 		$this->unitConverter = $unitConverter;
53 53
 	}
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 	 * @param UnboundedQuantityValue $value
57 57
 	 * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value.
58 58
 	 */
59
-	private function standardize( UnboundedQuantityValue $value ) {
60
-		if ( $this->unitConverter !== null ) {
61
-			$standard = $this->unitConverter->toStandardUnits( $value );
62
-			if ( $standard !== null ) {
59
+	private function standardize(UnboundedQuantityValue $value) {
60
+		if ($this->unitConverter !== null) {
61
+			$standard = $this->unitConverter->toStandardUnits($value);
62
+			if ($standard !== null) {
63 63
 				return $standard;
64 64
 			} else {
65 65
 				return $value;
@@ -81,23 +81,23 @@  discard block
 block discarded – undo
81 81
 	 *                 when $lhs is respectively less than, equal to, or greater than $rhs.
82 82
 	 *                 (In other words, just like the “spaceship” operator <=>.)
83 83
 	 */
84
-	public function getComparison( DataValue $lhs = null, DataValue $rhs = null ) {
85
-		if ( $lhs === null || $rhs === null ) {
84
+	public function getComparison(DataValue $lhs = null, DataValue $rhs = null) {
85
+		if ($lhs === null || $rhs === null) {
86 86
 			return 0;
87 87
 		}
88 88
 
89
-		if ( $lhs->getType() !== $rhs->getType() ) {
90
-			throw new InvalidArgumentException( 'Different data value types' );
89
+		if ($lhs->getType() !== $rhs->getType()) {
90
+			throw new InvalidArgumentException('Different data value types');
91 91
 		}
92 92
 
93
-		switch ( $lhs->getType() ) {
93
+		switch ($lhs->getType()) {
94 94
 			case 'time':
95 95
 				/** @var TimeValue $lhs */
96 96
 				/** @var TimeValue $rhs */
97
-				$lhsTimestamp = $this->timeCalculator->getTimestamp( $lhs );
98
-				$rhsTimestamp = $this->timeCalculator->getTimestamp( $rhs );
97
+				$lhsTimestamp = $this->timeCalculator->getTimestamp($lhs);
98
+				$rhsTimestamp = $this->timeCalculator->getTimestamp($rhs);
99 99
 
100
-				if ( $lhsTimestamp === $rhsTimestamp ) {
100
+				if ($lhsTimestamp === $rhsTimestamp) {
101 101
 					return 0;
102 102
 				}
103 103
 
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 			case 'quantity':
106 106
 				/** @var QuantityValue|UnboundedQuantityValue $lhs */
107 107
 				/** @var QuantityValue|UnboundedQuantityValue $rhs */
108
-				$lhsStandard = $this->standardize( $lhs );
109
-				$rhsStandard = $this->standardize( $rhs );
110
-				return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() );
108
+				$lhsStandard = $this->standardize($lhs);
109
+				$rhsStandard = $this->standardize($rhs);
110
+				return $lhsStandard->getAmount()->compare($rhsStandard->getAmount());
111 111
 		}
112 112
 
113
-		throw new InvalidArgumentException( 'Unsupported data value type' );
113
+		throw new InvalidArgumentException('Unsupported data value type');
114 114
 	}
115 115
 
116 116
 	/**
@@ -125,83 +125,83 @@  discard block
 block discarded – undo
125 125
 	 * @throws InvalidArgumentException if the values do not both have the same, supported data value type
126 126
 	 * @return UnboundedQuantityValue
127 127
 	 */
128
-	public function getDifference( DataValue $minuend, DataValue $subtrahend ) {
129
-		if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) {
130
-			$minuendSeconds = $this->timeCalculator->getTimestamp( $minuend );
131
-			$subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend );
128
+	public function getDifference(DataValue $minuend, DataValue $subtrahend) {
129
+		if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') {
130
+			$minuendSeconds = $this->timeCalculator->getTimestamp($minuend);
131
+			$subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend);
132 132
 			return UnboundedQuantityValue::newFromNumber(
133 133
 				$minuendSeconds - $subtrahendSeconds,
134
-				$this->config->get( 'WBQualityConstraintsSecondUnit' )
134
+				$this->config->get('WBQualityConstraintsSecondUnit')
135 135
 			);
136 136
 		}
137
-		if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) {
138
-			$minuendStandard = $this->standardize( $minuend );
139
-			$subtrahendStandard = $this->standardize( $subtrahend );
137
+		if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') {
138
+			$minuendStandard = $this->standardize($minuend);
139
+			$subtrahendStandard = $this->standardize($subtrahend);
140 140
 			$minuendValue = $minuendStandard->getAmount()->getValueFloat();
141 141
 			$subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat();
142 142
 			$diff = $minuendValue - $subtrahendValue;
143 143
 			// we don’t check whether both quantities have the same standard unit –
144 144
 			// that’s the job of a different constraint type, Units (T164372)
145
-			return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() );
145
+			return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit());
146 146
 		}
147 147
 
148
-		throw new InvalidArgumentException( 'Unsupported or different data value types' );
148
+		throw new InvalidArgumentException('Unsupported or different data value types');
149 149
 	}
150 150
 
151
-	public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ) {
152
-		if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) ||
153
-			!preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches )
151
+	public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend) {
152
+		if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) ||
153
+			!preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches)
154 154
 		) {
155
-			throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' );
155
+			throw new InvalidArgumentException('TimeValue::getTime() did not match expected format');
156 156
 		}
157
-		$minuendYear = (float)$minuendMatches[1];
158
-		$subtrahendYear = (float)$subtrahendMatches[1];
157
+		$minuendYear = (float) $minuendMatches[1];
158
+		$subtrahendYear = (float) $subtrahendMatches[1];
159 159
 		$minuendRest = $minuendMatches[2];
160 160
 		$subtrahendRest = $subtrahendMatches[2];
161 161
 
162 162
 		// calculate difference of years
163 163
 		$diff = $minuendYear - $subtrahendYear;
164
-		if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) {
164
+		if ($minuendYear > 0.0 && $subtrahendYear < 0.0) {
165 165
 			$diff -= 1.0; // there is no year 0, remove it from difference
166
-		} elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) {
166
+		} elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) {
167 167
 			$diff -= -1.0; // there is no year 0, remove it from negative difference
168 168
 		}
169 169
 
170 170
 		// adjust for date within year by parsing the month-day part within the same year
171
-		$minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest );
172
-		$subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest );
173
-		$minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue );
174
-		$subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue );
175
-		if ( $minuendDateSeconds < $subtrahendDateSeconds ) {
171
+		$minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest);
172
+		$subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest);
173
+		$minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue);
174
+		$subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue);
175
+		if ($minuendDateSeconds < $subtrahendDateSeconds) {
176 176
 			// difference in the last year is actually less than one full year
177 177
 			// e. g. 1975-03-01 - 1974-09-01 is just six months
178 178
 			// (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough)
179 179
 			$diff -= 0.5;
180
-		} elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) {
180
+		} elseif ($minuendDateSeconds > $subtrahendDateSeconds) {
181 181
 			// difference in the last year is actually more than one full year
182 182
 			// e. g. 1975-09-01 - 1974-03-01 is 18 months
183 183
 			// (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough)
184 184
 			$diff += 0.5;
185 185
 		}
186 186
 
187
-		$unit = $this->config->get( 'WBQualityConstraintsYearUnit' );
188
-		return UnboundedQuantityValue::newFromNumber( $diff, $unit );
187
+		$unit = $this->config->get('WBQualityConstraintsYearUnit');
188
+		return UnboundedQuantityValue::newFromNumber($diff, $unit);
189 189
 	}
190 190
 
191 191
 	/**
192 192
 	 * @param string $timeString
193 193
 	 * @return TimeValue
194 194
 	 */
195
-	public function parseTime( $timeString ) {
196
-		return $this->timeParser->parse( $timeString );
195
+	public function parseTime($timeString) {
196
+		return $this->timeParser->parse($timeString);
197 197
 	}
198 198
 
199 199
 	/**
200 200
 	 * @param string $quantityString
201 201
 	 * @return QuantityValue|UnboundedQuantityValue
202 202
 	 */
203
-	public function parseQuantity( $quantityString ) {
204
-		return UnboundedQuantityValue::newFromNumber( $quantityString );
203
+	public function parseQuantity($quantityString) {
204
+		return UnboundedQuantityValue::newFromNumber($quantityString);
205 205
 	}
206 206
 
207 207
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Result/CheckResult.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 	public function getDataValue() {
147 147
 		$mainSnak = $this->context->getSnak();
148 148
 
149
-		if ( $mainSnak instanceof PropertyValueSnak ) {
149
+		if ($mainSnak instanceof PropertyValueSnak) {
150 150
 			return $mainSnak->getDataValue();
151 151
 		}
152 152
 
153
-		throw new LogicException( 'Cannot get DataValue, Snak is of type ' . $this->getSnakType() . '.' );
153
+		throw new LogicException('Cannot get DataValue, Snak is of type '.$this->getSnakType().'.');
154 154
 	}
155 155
 
156 156
 	/**
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @param string $key
179 179
 	 * @param string $value
180 180
 	 */
181
-	public function addParameter( $key, $value ) {
181
+	public function addParameter($key, $value) {
182 182
 		$this->parameters[$key][] = $value;
183 183
 	}
184 184
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	/**
193 193
 	 * @param string $status
194 194
 	 */
195
-	public function setStatus( $status ) {
195
+	public function setStatus($status) {
196 196
 		$this->status = $status;
197 197
 	}
198 198
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 * @param Metadata $cm
208 208
 	 * @return self
209 209
 	 */
210
-	public function withMetadata( Metadata $cm ) {
210
+	public function withMetadata(Metadata $cm) {
211 211
 		$this->metadata = $cm;
212 212
 		return $this;
213 213
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Cache/CachedArray.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 	 */
21 21
 	private $metadata;
22 22
 
23
-	public function __construct( array $array, Metadata $metadata ) {
23
+	public function __construct(array $array, Metadata $metadata) {
24 24
 		$this->array = $array;
25 25
 		$this->metadata = $metadata;
26 26
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Cache/DependencyMetadata.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @param EntityId $entityId An entity ID from which the value was derived.
30 30
 	 * @return self Indication that a value is was derived from the entity with the given ID.
31 31
 	 */
32
-	public static function ofEntityId( EntityId $entityId ) {
32
+	public static function ofEntityId(EntityId $entityId) {
33 33
 		$ret = new self;
34 34
 		$ret->entityIds[] = $entityId;
35 35
 		return $ret;
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	 * @param self[] $metadatas
40 40
 	 * @return self
41 41
 	 */
42
-	public static function merge( array $metadatas ) {
43
-		Assert::parameterElementType( self::class, $metadatas, '$metadatas' );
42
+	public static function merge(array $metadatas) {
43
+		Assert::parameterElementType(self::class, $metadatas, '$metadatas');
44 44
 		$ret = new self;
45
-		foreach ( $metadatas as $metadata ) {
46
-			$ret->entityIds = array_merge( $ret->entityIds, $metadata->entityIds );
45
+		foreach ($metadatas as $metadata) {
46
+			$ret->entityIds = array_merge($ret->entityIds, $metadata->entityIds);
47 47
 		}
48 48
 		return $ret;
49 49
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Cache/CachedBool.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 	 * @param bool $bool
25 25
 	 * @param Metadata $metadata
26 26
 	 */
27
-	public function __construct( $bool, Metadata $metadata ) {
27
+	public function __construct($bool, Metadata $metadata) {
28 28
 		$this->bool = $bool;
29 29
 		$this->metadata = $metadata;
30 30
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Cache/Metadata.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
 		return $ret;
33 33
 	}
34 34
 
35
-	public static function ofCachingMetadata( CachingMetadata $cachingMetadata ) {
35
+	public static function ofCachingMetadata(CachingMetadata $cachingMetadata) {
36 36
 		$ret = new self;
37 37
 		$ret->cachingMetadata = $cachingMetadata;
38 38
 		$ret->dependencyMetadata = DependencyMetadata::blank();
39 39
 		return $ret;
40 40
 	}
41 41
 
42
-	public static function ofDependencyMetadata( DependencyMetadata $dependencyMetadata ) {
42
+	public static function ofDependencyMetadata(DependencyMetadata $dependencyMetadata) {
43 43
 		$ret = new self;
44 44
 		$ret->cachingMetadata = CachingMetadata::fresh();
45 45
 		$ret->dependencyMetadata = $dependencyMetadata;
@@ -50,17 +50,17 @@  discard block
 block discarded – undo
50 50
 	 * @param self[] $metadatas
51 51
 	 * @return self
52 52
 	 */
53
-	public static function merge( array $metadatas ) {
54
-		Assert::parameterElementType( self::class, $metadatas, '$metadatas' );
53
+	public static function merge(array $metadatas) {
54
+		Assert::parameterElementType(self::class, $metadatas, '$metadatas');
55 55
 		$cachingMetadatas = [];
56 56
 		$dependencyMetadatas = [];
57
-		foreach ( $metadatas as $metadata ) {
57
+		foreach ($metadatas as $metadata) {
58 58
 			$cachingMetadatas[] = $metadata->cachingMetadata;
59 59
 			$dependencyMetadatas[] = $metadata->dependencyMetadata;
60 60
 		}
61 61
 		$ret = new self;
62
-		$ret->cachingMetadata = CachingMetadata::merge( $cachingMetadatas );
63
-		$ret->dependencyMetadata = DependencyMetadata::merge( $dependencyMetadatas );
62
+		$ret->cachingMetadata = CachingMetadata::merge($cachingMetadatas);
63
+		$ret->dependencyMetadata = DependencyMetadata::merge($dependencyMetadatas);
64 64
 		return $ret;
65 65
 	}
66 66
 
Please login to merge, or discard this patch.
src/ConstraintReportFactory.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	public static function getDefaultInstance() {
138 138
 		static $instance = null;
139 139
 
140
-		if ( $instance === null ) {
140
+		if ($instance === null) {
141 141
 			$wikibaseRepo = WikibaseRepo::getDefaultInstance();
142 142
 			$entityIdFormatter = $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory()->getEntityIdFormatter(
143 143
 				$wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory()->newLabelDescriptionLookup(
@@ -205,21 +205,21 @@  discard block
 block discarded – undo
205 205
 	 * @return DelegatingConstraintChecker
206 206
 	 */
207 207
 	public function getConstraintChecker() {
208
-		if ( $this->delegatingConstraintChecker === null ) {
208
+		if ($this->delegatingConstraintChecker === null) {
209 209
 			$this->delegatingConstraintChecker = new DelegatingConstraintChecker(
210 210
 				$this->lookup,
211 211
 				$this->getConstraintCheckerMap(),
212
-				new CachingConstraintLookup( $this->getConstraintRepository() ),
212
+				new CachingConstraintLookup($this->getConstraintRepository()),
213 213
 				$this->constraintParameterParser,
214 214
 				$this->statementGuidParser,
215 215
 				new LoggingHelper(
216 216
 					$this->dataFactory,
217
-					LoggerFactory::getInstance( 'WikibaseQualityConstraints' ),
217
+					LoggerFactory::getInstance('WikibaseQualityConstraints'),
218 218
 					$this->config
219 219
 				),
220
-				$this->config->get( 'WBQualityConstraintsCheckQualifiers' ),
221
-				$this->config->get( 'WBQualityConstraintsCheckReferences' ),
222
-				$this->config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' )
220
+				$this->config->get('WBQualityConstraintsCheckQualifiers'),
221
+				$this->config->get('WBQualityConstraintsCheckReferences'),
222
+				$this->config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers')
223 223
 			);
224 224
 		}
225 225
 
@@ -230,10 +230,10 @@  discard block
 block discarded – undo
230 230
 	 * @return ConstraintChecker[]
231 231
 	 */
232 232
 	private function getConstraintCheckerMap() {
233
-		if ( $this->constraintCheckerMap === null ) {
233
+		if ($this->constraintCheckerMap === null) {
234 234
 			$connectionCheckerHelper = new ConnectionCheckerHelper();
235
-			$rangeCheckerHelper = new RangeCheckerHelper( $this->config, $this->unitConverter );
236
-			if ( $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ) !== '' ) {
235
+			$rangeCheckerHelper = new RangeCheckerHelper($this->config, $this->unitConverter);
236
+			if ($this->config->get('WBQualityConstraintsSparqlEndpoint') !== '') {
237 237
 				$sparqlHelper = new SparqlHelper(
238 238
 					$this->config,
239 239
 					$this->rdfVocabulary,
@@ -254,74 +254,74 @@  discard block
 block discarded – undo
254 254
 			);
255 255
 
256 256
 			$this->constraintCheckerMap = [
257
-				$this->config->get( 'WBQualityConstraintsConflictsWithConstraintId' )
257
+				$this->config->get('WBQualityConstraintsConflictsWithConstraintId')
258 258
 					=> new ConflictsWithChecker(
259 259
 						$this->lookup,
260 260
 						$this->constraintParameterParser,
261 261
 						$connectionCheckerHelper,
262 262
 						$this->constraintParameterRenderer
263 263
 					),
264
-				$this->config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' )
264
+				$this->config->get('WBQualityConstraintsItemRequiresClaimConstraintId')
265 265
 					=> new ItemChecker(
266 266
 						$this->lookup,
267 267
 						$this->constraintParameterParser,
268 268
 						$connectionCheckerHelper,
269 269
 						$this->constraintParameterRenderer
270 270
 					),
271
-				$this->config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' )
271
+				$this->config->get('WBQualityConstraintsValueRequiresClaimConstraintId')
272 272
 					=> new TargetRequiredClaimChecker(
273 273
 						$this->lookup,
274 274
 						$this->constraintParameterParser,
275 275
 						$connectionCheckerHelper,
276 276
 						$this->constraintParameterRenderer
277 277
 					),
278
-				$this->config->get( 'WBQualityConstraintsSymmetricConstraintId' )
278
+				$this->config->get('WBQualityConstraintsSymmetricConstraintId')
279 279
 					=> new SymmetricChecker(
280 280
 						$this->lookup,
281 281
 						$connectionCheckerHelper,
282 282
 						$this->constraintParameterRenderer
283 283
 					),
284
-				$this->config->get( 'WBQualityConstraintsInverseConstraintId' )
284
+				$this->config->get('WBQualityConstraintsInverseConstraintId')
285 285
 					=> new InverseChecker(
286 286
 						$this->lookup,
287 287
 						$this->constraintParameterParser,
288 288
 						$connectionCheckerHelper,
289 289
 						$this->constraintParameterRenderer
290 290
 					),
291
-				$this->config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' )
291
+				$this->config->get('WBQualityConstraintsUsedAsQualifierConstraintId')
292 292
 					=> new QualifierChecker(),
293
-				$this->config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' )
293
+				$this->config->get('WBQualityConstraintsAllowedQualifiersConstraintId')
294 294
 					=> new QualifiersChecker(
295 295
 						$this->constraintParameterParser,
296 296
 						$this->constraintParameterRenderer
297 297
 					),
298
-				$this->config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' )
298
+				$this->config->get('WBQualityConstraintsMandatoryQualifierConstraintId')
299 299
 					=> new MandatoryQualifiersChecker(
300 300
 						$this->constraintParameterParser,
301 301
 						$this->constraintParameterRenderer
302 302
 					),
303
-				$this->config->get( 'WBQualityConstraintsRangeConstraintId' )
303
+				$this->config->get('WBQualityConstraintsRangeConstraintId')
304 304
 					=> new RangeChecker(
305 305
 						$this->propertyDataTypeLookup,
306 306
 						$this->constraintParameterParser,
307 307
 						$rangeCheckerHelper,
308 308
 						$this->constraintParameterRenderer
309 309
 					),
310
-				$this->config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' )
310
+				$this->config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId')
311 311
 					=> new DiffWithinRangeChecker(
312 312
 						$this->constraintParameterParser,
313 313
 						$rangeCheckerHelper,
314 314
 						$this->constraintParameterRenderer,
315 315
 						$this->config
316 316
 					),
317
-				$this->config->get( 'WBQualityConstraintsTypeConstraintId' )
317
+				$this->config->get('WBQualityConstraintsTypeConstraintId')
318 318
 					=> new TypeChecker(
319 319
 						$this->lookup,
320 320
 						$this->constraintParameterParser,
321 321
 						$typeCheckerHelper,
322 322
 						$this->config
323 323
 					),
324
-				$this->config->get( 'WBQualityConstraintsValueTypeConstraintId' )
324
+				$this->config->get('WBQualityConstraintsValueTypeConstraintId')
325 325
 					=> new ValueTypeChecker(
326 326
 						$this->lookup,
327 327
 						$this->constraintParameterParser,
@@ -329,36 +329,36 @@  discard block
 block discarded – undo
329 329
 						$typeCheckerHelper,
330 330
 						$this->config
331 331
 					),
332
-				$this->config->get( 'WBQualityConstraintsSingleValueConstraintId' )
332
+				$this->config->get('WBQualityConstraintsSingleValueConstraintId')
333 333
 					=> new SingleValueChecker(),
334
-				$this->config->get( 'WBQualityConstraintsMultiValueConstraintId' )
334
+				$this->config->get('WBQualityConstraintsMultiValueConstraintId')
335 335
 					=> new MultiValueChecker(),
336
-				$this->config->get( 'WBQualityConstraintsDistinctValuesConstraintId' )
336
+				$this->config->get('WBQualityConstraintsDistinctValuesConstraintId')
337 337
 					=> new UniqueValueChecker(
338 338
 						$this->constraintParameterRenderer,
339 339
 						$sparqlHelper
340 340
 					),
341
-				$this->config->get( 'WBQualityConstraintsFormatConstraintId' )
341
+				$this->config->get('WBQualityConstraintsFormatConstraintId')
342 342
 					=> new FormatChecker(
343 343
 						$this->constraintParameterParser,
344 344
 						$this->constraintParameterRenderer,
345 345
 						$this->config,
346 346
 						$sparqlHelper
347 347
 					),
348
-				$this->config->get( 'WBQualityConstraintsCommonsLinkConstraintId' )
348
+				$this->config->get('WBQualityConstraintsCommonsLinkConstraintId')
349 349
 					=> new CommonsLinkChecker(
350 350
 						$this->constraintParameterParser,
351 351
 						$this->constraintParameterRenderer,
352 352
 						$this->titleParser
353 353
 					),
354
-				$this->config->get( 'WBQualityConstraintsOneOfConstraintId' )
354
+				$this->config->get('WBQualityConstraintsOneOfConstraintId')
355 355
 					=> new OneOfChecker(
356 356
 						$this->constraintParameterParser,
357 357
 						$this->constraintParameterRenderer
358 358
 					),
359
-				$this->config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' )
359
+				$this->config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId')
360 360
 					=> new ValueOnlyChecker(),
361
-				$this->config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' )
361
+				$this->config->get('WBQualityConstraintsUsedAsReferenceConstraintId')
362 362
 					=> new ReferenceChecker(),
363 363
 			];
364 364
 		}
@@ -370,26 +370,26 @@  discard block
 block discarded – undo
370 370
 	 * @return array[]
371 371
 	 */
372 372
 	public function getConstraintParameterMap() {
373
-		if ( $this->constraintParameterMap === null ) {
373
+		if ($this->constraintParameterMap === null) {
374 374
 			$this->constraintParameterMap = [
375
-				'Commons link' => [ 'namespace' ],
376
-				'Conflicts with' => [ 'property', 'item' ],
377
-				'Diff within range' => [ 'property', 'minimum_quantity', 'maximum_quantity' ],
378
-				'Format' => [ 'pattern' ],
379
-				'Inverse' => [ 'property' ],
380
-				'Item' => [ 'property', 'item' ],
381
-				'Mandatory qualifiers' => [ 'property' ],
375
+				'Commons link' => ['namespace'],
376
+				'Conflicts with' => ['property', 'item'],
377
+				'Diff within range' => ['property', 'minimum_quantity', 'maximum_quantity'],
378
+				'Format' => ['pattern'],
379
+				'Inverse' => ['property'],
380
+				'Item' => ['property', 'item'],
381
+				'Mandatory qualifiers' => ['property'],
382 382
 				'Multi value' => [],
383
-				'One of' => [ 'item' ],
383
+				'One of' => ['item'],
384 384
 				'Qualifier' => [],
385
-				'Qualifiers' => [ 'property' ],
386
-				'Range' => [ 'minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date' ],
385
+				'Qualifiers' => ['property'],
386
+				'Range' => ['minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date'],
387 387
 				'Single value' => [],
388 388
 				'Symmetric' => [],
389
-				'Target required claim' => [ 'property', 'item' ],
390
-				'Type' => [ 'class', 'relation' ],
389
+				'Target required claim' => ['property', 'item'],
390
+				'Type' => ['class', 'relation'],
391 391
 				'Unique value' => [],
392
-				'Value type' => [ 'class', 'relation' ]
392
+				'Value type' => ['class', 'relation']
393 393
 			];
394 394
 		}
395 395
 
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	 * @return ConstraintRepository
401 401
 	 */
402 402
 	public function getConstraintRepository() {
403
-		if ( $this->constraintRepository === null ) {
403
+		if ($this->constraintRepository === null) {
404 404
 			$this->constraintRepository = new ConstraintRepository();
405 405
 		}
406 406
 
Please login to merge, or discard this patch.
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @return self
67 67
 	 */
68
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
68
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
69 69
 		$constraintReportFactory = ConstraintReportFactory::getDefaultInstance();
70 70
 		$repo = WikibaseRepo::getDefaultInstance();
71
-		$helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() );
71
+		$helperFactory = $repo->getApiHelperFactory(RequestContext::getMain());
72 72
 		return new self(
73 73
 			$main,
74 74
 			$name,
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 		StatementGuidParser $statementGuidParser,
99 99
 		IBufferingStatsdDataFactory $dataFactory
100 100
 	) {
101
-		parent::__construct( $main, $name, $prefix );
101
+		parent::__construct($main, $name, $prefix);
102 102
 
103
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
103
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
104 104
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
105 105
 		$this->statementGuidParser = $statementGuidParser;
106 106
 		$this->dataFactory = $dataFactory;
@@ -114,39 +114,39 @@  discard block
 block discarded – undo
114 114
 		$params = $this->extractRequestParams();
115 115
 		$result = $this->getResult();
116 116
 
117
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
118
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
117
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
118
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
119 119
 
120
-		$this->checkPropertyIds( $propertyIds, $result );
121
-		$this->checkConstraintIds( $constraintIds, $result );
120
+		$this->checkPropertyIds($propertyIds, $result);
121
+		$this->checkConstraintIds($constraintIds, $result);
122 122
 
123
-		$result->addValue( null, 'success', 1 );
123
+		$result->addValue(null, 'success', 1);
124 124
 	}
125 125
 
126 126
 	/**
127 127
 	 * @param array|null $propertyIdSerializations
128 128
 	 * @return PropertyId[]
129 129
 	 */
130
-	private function parsePropertyIds( $propertyIdSerializations ) {
131
-		if ( $propertyIdSerializations === null ) {
130
+	private function parsePropertyIds($propertyIdSerializations) {
131
+		if ($propertyIdSerializations === null) {
132 132
 			return [];
133
-		} elseif ( empty( $propertyIdSerializations ) ) {
133
+		} elseif (empty($propertyIdSerializations)) {
134 134
 			$this->apiErrorReporter->dieError(
135
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
135
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
136 136
 				'no-data'
137 137
 			);
138 138
 		}
139 139
 
140 140
 		return array_map(
141
-			function( $propertyIdSerialization ) {
141
+			function($propertyIdSerialization) {
142 142
 				try {
143
-					return new PropertyId( $propertyIdSerialization );
144
-				} catch ( InvalidArgumentException $e ) {
143
+					return new PropertyId($propertyIdSerialization);
144
+				} catch (InvalidArgumentException $e) {
145 145
 					$this->apiErrorReporter->dieError(
146 146
 						"Invalid id: $propertyIdSerialization",
147 147
 						'invalid-property-id',
148 148
 						0, // default argument
149
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
149
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
150 150
 					);
151 151
 				}
152 152
 			},
@@ -158,35 +158,35 @@  discard block
 block discarded – undo
158 158
 	 * @param array|null $constraintIds
159 159
 	 * @return string[]
160 160
 	 */
161
-	private function parseConstraintIds( $constraintIds ) {
162
-		if ( $constraintIds === null ) {
161
+	private function parseConstraintIds($constraintIds) {
162
+		if ($constraintIds === null) {
163 163
 			return [];
164
-		} elseif ( empty( $constraintIds ) ) {
164
+		} elseif (empty($constraintIds)) {
165 165
 			$this->apiErrorReporter->dieError(
166
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
166
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
167 167
 				'no-data'
168 168
 			);
169 169
 		}
170 170
 
171 171
 		return array_map(
172
-			function( $constraintId ) {
172
+			function($constraintId) {
173 173
 				try {
174
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
175
-					if ( !$propertyId instanceof PropertyId ) {
174
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
175
+					if (!$propertyId instanceof PropertyId) {
176 176
 						$this->apiErrorReporter->dieError(
177 177
 							"Invalid property ID: {$propertyId->getSerialization()}",
178 178
 							'invalid-property-id',
179 179
 							0, // default argument
180
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
180
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
181 181
 						);
182 182
 					}
183 183
 					return $constraintId;
184
-				} catch ( StatementGuidParsingException $e ) {
184
+				} catch (StatementGuidParsingException $e) {
185 185
 					$this->apiErrorReporter->dieError(
186 186
 						"Invalid statement GUID: $constraintId",
187 187
 						'invalid-guid',
188 188
 						0, // default argument
189
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
189
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
190 190
 					);
191 191
 				}
192 192
 			},
@@ -198,12 +198,12 @@  discard block
 block discarded – undo
198 198
 	 * @param PropertyId[] $propertyIds
199 199
 	 * @param ApiResult $result
200 200
 	 */
201
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ) {
202
-		foreach ( $propertyIds as $propertyId ) {
203
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
204
-			$allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId( $propertyId );
205
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
206
-				$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
201
+	private function checkPropertyIds(array $propertyIds, ApiResult $result) {
202
+		foreach ($propertyIds as $propertyId) {
203
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
204
+			$allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId($propertyId);
205
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
206
+				$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
207 207
 			}
208 208
 		}
209 209
 	}
@@ -212,14 +212,14 @@  discard block
 block discarded – undo
212 212
 	 * @param string[] $constraintIds
213 213
 	 * @param ApiResult $result
214 214
 	 */
215
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ) {
216
-		foreach ( $constraintIds as $constraintId ) {
217
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
215
+	private function checkConstraintIds(array $constraintIds, ApiResult $result) {
216
+		foreach ($constraintIds as $constraintId) {
217
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
218 218
 				// already checked as part of checkPropertyIds()
219 219
 				continue;
220 220
 			}
221
-			$constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId( $constraintId );
222
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
221
+			$constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId($constraintId);
222
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
223 223
 		}
224 224
 	}
225 225
 
@@ -227,17 +227,17 @@  discard block
 block discarded – undo
227 227
 	 * @param PropertyId $propertyId
228 228
 	 * @return string[]
229 229
 	 */
230
-	private function getResultPathForPropertyId( PropertyId $propertyId ) {
231
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
230
+	private function getResultPathForPropertyId(PropertyId $propertyId) {
231
+		return [$this->getModuleName(), $propertyId->getSerialization()];
232 232
 	}
233 233
 
234 234
 	/**
235 235
 	 * @param string $constraintId
236 236
 	 * @return string[]
237 237
 	 */
238
-	private function getResultPathForConstraintId( $constraintId ) {
239
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
240
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
238
+	private function getResultPathForConstraintId($constraintId) {
239
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
240
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
241 241
 	}
242 242
 
243 243
 	/**
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
 	 * @param ConstraintParameterException[]|null $constraintParameterExceptions
248 248
 	 * @param ApiResult $result
249 249
 	 */
250
-	private function addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, ApiResult $result ) {
251
-		$path = $this->getResultPathForConstraintId( $constraintId );
252
-		if ( $constraintParameterExceptions === null ) {
250
+	private function addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, ApiResult $result) {
251
+		$path = $this->getResultPathForConstraintId($constraintId);
252
+		if ($constraintParameterExceptions === null) {
253 253
 			$result->addValue(
254 254
 				$path,
255 255
 				self::KEY_STATUS,
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
 			$result->addValue(
260 260
 				$path,
261 261
 				self::KEY_STATUS,
262
-				empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
262
+				empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
263 263
 			);
264 264
 			$result->addValue(
265 265
 				$path,
266 266
 				self::KEY_PROBLEMS,
267
-				array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions )
267
+				array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions)
268 268
 			);
269 269
 		}
270 270
 	}
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 * @param ConstraintParameterException $e
276 276
 	 * @return array
277 277
 	 */
278
-	private function formatConstraintParameterException( ConstraintParameterException $e ) {
278
+	private function formatConstraintParameterException(ConstraintParameterException $e) {
279 279
 		return [
280 280
 			self::KEY_MESSAGE_HTML => $e->getMessage(),
281 281
 		];
Please login to merge, or discard this patch.