Completed
Push — master ( 651fc0...41b435 )
by
unknown
21s
created
src/Api/CheckConstraints.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\Api;
6 6
 
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
 		CheckResultsRendererFactory $checkResultsRendererFactory,
85 85
 		StatsFactory $statsFactory
86 86
 	) {
87
-		parent::__construct( $main, $name );
87
+		parent::__construct($main, $name);
88 88
 		$this->entityIdParser = $entityIdParser;
89 89
 		$this->statementGuidValidator = $statementGuidValidator;
90
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
91
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
90
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
91
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
92 92
 		$this->resultsSource = $resultsSource;
93 93
 		$this->checkResultsRendererFactory = $checkResultsRendererFactory;
94 94
 		$this->statsFactory = $statsFactory;
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function execute() {
101 101
 		$baseKey = 'wikibase.quality.constraints.api.checkConstraints.execute';
102
-		$metric = $this->statsFactory->getCounter( 'check_constraints_execute_total' );
103
-		$metric->copyToStatsdAt( $baseKey )->increment();
102
+		$metric = $this->statsFactory->getCounter('check_constraints_execute_total');
103
+		$metric->copyToStatsdAt($baseKey)->increment();
104 104
 
105 105
 		$params = $this->extractRequestParams();
106 106
 
107
-		$this->validateParameters( $params );
108
-		$entityIds = $this->parseEntityIds( $params );
109
-		$claimIds = $this->parseClaimIds( $params );
107
+		$this->validateParameters($params);
108
+		$entityIds = $this->parseEntityIds($params);
109
+		$claimIds = $this->parseClaimIds($params);
110 110
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
111 111
 		$statuses = $params[self::PARAM_STATUS];
112 112
 
113 113
 		$checkResultsRenderer = $this->checkResultsRendererFactory
114
-			->getCheckResultsRenderer( $this->getLanguage(), $this );
114
+			->getCheckResultsRenderer($this->getLanguage(), $this);
115 115
 
116 116
 		$this->getResult()->addValue(
117 117
 			null,
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 				)
126 126
 			)->getArray()
127 127
 		);
128
-		$this->resultBuilder->markSuccess( 1 );
128
+		$this->resultBuilder->markSuccess(1);
129 129
 	}
130 130
 
131 131
 	/**
@@ -133,24 +133,24 @@  discard block
 block discarded – undo
133 133
 	 *
134 134
 	 * @return EntityId[]
135 135
 	 */
136
-	private function parseEntityIds( array $params ): array {
136
+	private function parseEntityIds(array $params): array {
137 137
 		$ids = $params[self::PARAM_ID];
138 138
 
139
-		if ( $ids === null ) {
139
+		if ($ids === null) {
140 140
 			return [];
141
-		} elseif ( $ids === [] ) {
141
+		} elseif ($ids === []) {
142 142
 			$this->errorReporter->dieError(
143
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
143
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
144 144
 		}
145 145
 
146
-		return array_map( function ( $id ) {
146
+		return array_map(function($id) {
147 147
 			try {
148
-				return $this->entityIdParser->parse( $id );
149
-			} catch ( EntityIdParsingException ) {
148
+				return $this->entityIdParser->parse($id);
149
+			} catch (EntityIdParsingException) {
150 150
 				$this->errorReporter->dieError(
151
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
151
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
152 152
 			}
153
-		}, $ids );
153
+		}, $ids);
154 154
 	}
155 155
 
156 156
 	/**
@@ -158,35 +158,35 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @return string[]
160 160
 	 */
161
-	private function parseClaimIds( array $params ): array {
161
+	private function parseClaimIds(array $params): array {
162 162
 		$ids = $params[self::PARAM_CLAIM_ID];
163 163
 
164
-		if ( $ids === null ) {
164
+		if ($ids === null) {
165 165
 			return [];
166
-		} elseif ( $ids === [] ) {
166
+		} elseif ($ids === []) {
167 167
 			$this->errorReporter->dieError(
168
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
168
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
169 169
 		}
170 170
 
171
-		foreach ( $ids as $id ) {
172
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
171
+		foreach ($ids as $id) {
172
+			if (!$this->statementGuidValidator->validate($id)) {
173 173
 				$this->errorReporter->dieError(
174
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
174
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
175 175
 			}
176 176
 		}
177 177
 
178 178
 		return $ids;
179 179
 	}
180 180
 
181
-	private function validateParameters( array $params ): void {
182
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
183
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
181
+	private function validateParameters(array $params): void {
182
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
183
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
184 184
 		) {
185 185
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
186 186
 			$this->errorReporter->dieError(
187 187
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
188 188
 		}
189
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
189
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
190 190
 			$paramId = self::PARAM_ID;
191 191
 			$paramClaimId = self::PARAM_CLAIM_ID;
192 192
 			$this->errorReporter->dieError(
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 				],
228 228
 				ParamValidator::PARAM_ISMULTI => true,
229 229
 				ParamValidator::PARAM_ALL => true,
230
-				ParamValidator::PARAM_DEFAULT => implode( '|', CachingResultsSource::CACHED_STATUSES ),
230
+				ParamValidator::PARAM_DEFAULT => implode('|', CachingResultsSource::CACHED_STATUSES),
231 231
 				ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
232 232
 			],
233 233
 		];
Please login to merge, or discard this patch.
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\Api;
6 6
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 		StatementGuidParser $statementGuidParser,
80 80
 		IBufferingStatsdDataFactory $dataFactory
81 81
 	) {
82
-		parent::__construct( $main, $name );
82
+		parent::__construct($main, $name);
83 83
 
84
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
84
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
85 85
 		$this->languageFallbackChainFactory = $languageFallbackChainFactory;
86 86
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
87 87
 		$this->violationMessageRendererFactory = $violationMessageRendererFactory;
@@ -97,39 +97,39 @@  discard block
 block discarded – undo
97 97
 		$params = $this->extractRequestParams();
98 98
 		$result = $this->getResult();
99 99
 
100
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
101
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
100
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
101
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
102 102
 
103
-		$this->checkPropertyIds( $propertyIds, $result );
104
-		$this->checkConstraintIds( $constraintIds, $result );
103
+		$this->checkPropertyIds($propertyIds, $result);
104
+		$this->checkConstraintIds($constraintIds, $result);
105 105
 
106
-		$result->addValue( null, 'success', 1 );
106
+		$result->addValue(null, 'success', 1);
107 107
 	}
108 108
 
109 109
 	/**
110 110
 	 * @param array|null $propertyIdSerializations
111 111
 	 * @return NumericPropertyId[]
112 112
 	 */
113
-	private function parsePropertyIds( ?array $propertyIdSerializations ): array {
114
-		if ( $propertyIdSerializations === null ) {
113
+	private function parsePropertyIds(?array $propertyIdSerializations): array {
114
+		if ($propertyIdSerializations === null) {
115 115
 			return [];
116
-		} elseif ( $propertyIdSerializations === [] ) {
116
+		} elseif ($propertyIdSerializations === []) {
117 117
 			$this->apiErrorReporter->dieError(
118
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
118
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
119 119
 				'no-data'
120 120
 			);
121 121
 		}
122 122
 
123 123
 		return array_map(
124
-			function ( $propertyIdSerialization ) {
124
+			function($propertyIdSerialization) {
125 125
 				try {
126
-					return new NumericPropertyId( $propertyIdSerialization );
127
-				} catch ( InvalidArgumentException ) {
126
+					return new NumericPropertyId($propertyIdSerialization);
127
+				} catch (InvalidArgumentException) {
128 128
 					$this->apiErrorReporter->dieError(
129 129
 						"Invalid id: $propertyIdSerialization",
130 130
 						'invalid-property-id',
131 131
 						0, // default argument
132
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
132
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
133 133
 					);
134 134
 				}
135 135
 			},
@@ -141,35 +141,35 @@  discard block
 block discarded – undo
141 141
 	 * @param array|null $constraintIds
142 142
 	 * @return string[]
143 143
 	 */
144
-	private function parseConstraintIds( ?array $constraintIds ): array {
145
-		if ( $constraintIds === null ) {
144
+	private function parseConstraintIds(?array $constraintIds): array {
145
+		if ($constraintIds === null) {
146 146
 			return [];
147
-		} elseif ( $constraintIds === [] ) {
147
+		} elseif ($constraintIds === []) {
148 148
 			$this->apiErrorReporter->dieError(
149
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
149
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
150 150
 				'no-data'
151 151
 			);
152 152
 		}
153 153
 
154 154
 		return array_map(
155
-			function ( $constraintId ) {
155
+			function($constraintId) {
156 156
 				try {
157
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
158
-					if ( !$propertyId instanceof NumericPropertyId ) {
157
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
158
+					if (!$propertyId instanceof NumericPropertyId) {
159 159
 						$this->apiErrorReporter->dieError(
160 160
 							"Invalid property ID: {$propertyId->getSerialization()}",
161 161
 							'invalid-property-id',
162 162
 							0, // default argument
163
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
163
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
164 164
 						);
165 165
 					}
166 166
 					return $constraintId;
167
-				} catch ( StatementGuidParsingException ) {
167
+				} catch (StatementGuidParsingException) {
168 168
 					$this->apiErrorReporter->dieError(
169 169
 						"Invalid statement GUID: $constraintId",
170 170
 						'invalid-guid',
171 171
 						0, // default argument
172
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
172
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
173 173
 					);
174 174
 				}
175 175
 			},
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
 	 * @param NumericPropertyId[] $propertyIds
182 182
 	 * @param ApiResult $result
183 183
 	 */
184
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ): void {
185
-		foreach ( $propertyIds as $propertyId ) {
186
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
184
+	private function checkPropertyIds(array $propertyIds, ApiResult $result): void {
185
+		foreach ($propertyIds as $propertyId) {
186
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
187 187
 			$allConstraintExceptions = $this->delegatingConstraintChecker
188
-				->checkConstraintParametersOnPropertyId( $propertyId );
189
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
188
+				->checkConstraintParametersOnPropertyId($propertyId);
189
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
190 190
 				$this->addConstraintParameterExceptionsToResult(
191 191
 					$constraintId,
192 192
 					$constraintParameterExceptions,
@@ -200,15 +200,15 @@  discard block
 block discarded – undo
200 200
 	 * @param string[] $constraintIds
201 201
 	 * @param ApiResult $result
202 202
 	 */
203
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ): void {
204
-		foreach ( $constraintIds as $constraintId ) {
205
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
203
+	private function checkConstraintIds(array $constraintIds, ApiResult $result): void {
204
+		foreach ($constraintIds as $constraintId) {
205
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
206 206
 				// already checked as part of checkPropertyIds()
207 207
 				continue;
208 208
 			}
209 209
 			$constraintParameterExceptions = $this->delegatingConstraintChecker
210
-				->checkConstraintParametersOnConstraintId( $constraintId );
211
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
210
+				->checkConstraintParametersOnConstraintId($constraintId);
211
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
212 212
 		}
213 213
 	}
214 214
 
@@ -216,18 +216,18 @@  discard block
 block discarded – undo
216 216
 	 * @param NumericPropertyId $propertyId
217 217
 	 * @return string[]
218 218
 	 */
219
-	private function getResultPathForPropertyId( NumericPropertyId $propertyId ): array {
220
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
219
+	private function getResultPathForPropertyId(NumericPropertyId $propertyId): array {
220
+		return [$this->getModuleName(), $propertyId->getSerialization()];
221 221
 	}
222 222
 
223 223
 	/**
224 224
 	 * @param string $constraintId
225 225
 	 * @return string[]
226 226
 	 */
227
-	private function getResultPathForConstraintId( string $constraintId ): array {
228
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
227
+	private function getResultPathForConstraintId(string $constraintId): array {
228
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
229 229
 		'@phan-var NumericPropertyId $propertyId';
230
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
230
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
231 231
 	}
232 232
 
233 233
 	/**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
 		?array $constraintParameterExceptions,
243 243
 		ApiResult $result
244 244
 	): void {
245
-		$path = $this->getResultPathForConstraintId( $constraintId );
246
-		if ( $constraintParameterExceptions === null ) {
245
+		$path = $this->getResultPathForConstraintId($constraintId);
246
+		if ($constraintParameterExceptions === null) {
247 247
 			$result->addValue(
248 248
 				$path,
249 249
 				self::KEY_STATUS,
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
 			$violationMessageRenderer = $this->violationMessageRendererFactory
261 261
 				->getViolationMessageRenderer(
262 262
 					$language,
263
-					$this->languageFallbackChainFactory->newFromLanguage( $language ),
263
+					$this->languageFallbackChainFactory->newFromLanguage($language),
264 264
 					$this
265 265
 				);
266 266
 			$problems = [];
267
-			foreach ( $constraintParameterExceptions as $constraintParameterException ) {
267
+			foreach ($constraintParameterExceptions as $constraintParameterException) {
268 268
 				$problems[] = [
269 269
 					self::KEY_MESSAGE_HTML => $violationMessageRenderer->render(
270 270
 						$constraintParameterException->getViolationMessage() ),
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
 		return [
304 304
 			'action=wbcheckconstraintparameters&propertyid=P247'
305 305
 				=> 'apihelp-wbcheckconstraintparameters-example-propertyid-1',
306
-			'action=wbcheckconstraintparameters&' .
307
-			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' .
306
+			'action=wbcheckconstraintparameters&'.
307
+			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'.
308 308
 			'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f'
309 309
 				=> 'apihelp-wbcheckconstraintparameters-example-constraintid-2',
310 310
 		];
Please login to merge, or discard this patch.
src/Api/ExpiryLock.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\Api;
6 6
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 	private BagOStuff $cache;
23 23
 
24
-	public function __construct( BagOStuff $cache ) {
24
+	public function __construct(BagOStuff $cache) {
25 25
 		$this->cache = $cache;
26 26
 	}
27 27
 
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @throws \Wikimedia\Assert\ParameterTypeException
34 34
 	 */
35
-	private function makeKey( string $id ): string {
36
-		if ( trim( $id ) === '' ) {
37
-			throw new ParameterTypeException( '$id', 'non-empty string' );
35
+	private function makeKey(string $id): string {
36
+		if (trim($id) === '') {
37
+			throw new ParameterTypeException('$id', 'non-empty string');
38 38
 		}
39 39
 
40 40
 		return $this->cache->makeKey(
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @throws \Wikimedia\Assert\ParameterTypeException
54 54
 	 */
55
-	public function lock( string $id, ConvertibleTimestamp $expiryTimestamp ): bool {
55
+	public function lock(string $id, ConvertibleTimestamp $expiryTimestamp): bool {
56 56
 
57
-		$cacheId = $this->makeKey( $id );
57
+		$cacheId = $this->makeKey($id);
58 58
 
59
-		if ( !$this->isLockedInternal( $cacheId ) ) {
59
+		if (!$this->isLockedInternal($cacheId)) {
60 60
 			return $this->cache->set(
61 61
 				$cacheId,
62
-				$expiryTimestamp->getTimestamp( TS_UNIX ),
63
-				(int)$expiryTimestamp->getTimestamp( TS_UNIX )
62
+				$expiryTimestamp->getTimestamp(TS_UNIX),
63
+				(int) $expiryTimestamp->getTimestamp(TS_UNIX)
64 64
 			);
65 65
 		} else {
66 66
 			return false;
@@ -74,20 +74,20 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @throws \Wikimedia\Assert\ParameterTypeException
76 76
 	 */
77
-	private function isLockedInternal( string $cacheId ): bool {
78
-		$expiryTime = $this->cache->get( $cacheId );
79
-		if ( !$expiryTime ) {
77
+	private function isLockedInternal(string $cacheId): bool {
78
+		$expiryTime = $this->cache->get($cacheId);
79
+		if (!$expiryTime) {
80 80
 			return false;
81 81
 		}
82 82
 
83 83
 		try {
84
-			$lockExpiryTimeStamp = new ConvertibleTimestamp( $expiryTime );
85
-		} catch ( TimestampException ) {
84
+			$lockExpiryTimeStamp = new ConvertibleTimestamp($expiryTime);
85
+		} catch (TimestampException) {
86 86
 			return false;
87 87
 		}
88 88
 
89 89
 		$now = new ConvertibleTimestamp();
90
-		if ( $now->timestamp < $lockExpiryTimeStamp->timestamp ) {
90
+		if ($now->timestamp < $lockExpiryTimeStamp->timestamp) {
91 91
 			return true;
92 92
 		} else {
93 93
 			return false;
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 *
102 102
 	 * @throws \Wikimedia\Assert\ParameterTypeException
103 103
 	 */
104
-	public function isLocked( string $id ): bool {
105
-		return $this->isLockedInternal( $this->makeKey( $id ) );
104
+	public function isLocked(string $id): bool {
105
+		return $this->isLockedInternal($this->makeKey($id));
106 106
 	}
107 107
 
108 108
 }
Please login to merge, or discard this patch.