Completed
Push — master ( 03b155...603cbe )
by
unknown
09:10
created
src/ConstraintCheck/ItemIdSnakValue.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * @param ItemId $itemId
45 45
 	 * @return self
46 46
 	 */
47
-	public static function fromItemId( ItemId $itemId ) {
47
+	public static function fromItemId(ItemId $itemId) {
48 48
 		$ret = new self;
49 49
 		$ret->itemId = $itemId;
50 50
 		return $ret;
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	 * @throws InvalidArgumentException
81 81
 	 * @return self
82 82
 	 */
83
-	public static function fromSnak( Snak $snak ) {
84
-		switch ( true ) {
83
+	public static function fromSnak(Snak $snak) {
84
+		switch (true) {
85 85
 			case $snak instanceof PropertyValueSnak:
86 86
 				$dataValue = $snak->getDataValue();
87
-				if ( $dataValue instanceof EntityIdValue ) {
87
+				if ($dataValue instanceof EntityIdValue) {
88 88
 					$itemId = $dataValue->getEntityId();
89
-					if ( $itemId instanceof ItemId ) {
90
-						return self::fromItemId( $itemId );
89
+					if ($itemId instanceof ItemId) {
90
+						return self::fromItemId($itemId);
91 91
 					}
92 92
 				}
93 93
 				break;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 				return self::noValue();
98 98
 		}
99 99
 
100
-		throw new InvalidArgumentException( 'Snak must contain item ID value or be a somevalue / novalue snak' );
100
+		throw new InvalidArgumentException('Snak must contain item ID value or be a somevalue / novalue snak');
101 101
 	}
102 102
 
103 103
 	/**
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @return ItemId
136 136
 	 */
137 137
 	public function getItemId() {
138
-		if ( !$this->isValue() ) {
139
-			throw new DomainException( 'This value does not contain an item ID.' );
138
+		if (!$this->isValue()) {
139
+			throw new DomainException('This value does not contain an item ID.');
140 140
 		}
141 141
 		return $this->itemId;
142 142
 	}
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
 	 * @param Snak $snak
149 149
 	 * @return bool
150 150
 	 */
151
-	public function matchesSnak( Snak $snak ) {
152
-		switch ( true ) {
151
+	public function matchesSnak(Snak $snak) {
152
+		switch (true) {
153 153
 			case $snak instanceof PropertyValueSnak:
154 154
 				$dataValue = $snak->getDataValue();
155 155
 				return $this->isValue() &&
156 156
 					$dataValue instanceof EntityIdValue &&
157 157
 					$dataValue->getEntityId() instanceof ItemId &&
158
-					$dataValue->getEntityId()->equals( $this->getItemId() );
158
+					$dataValue->getEntityId()->equals($this->getItemId());
159 159
 			case $snak instanceof PropertySomeValueSnak:
160 160
 				return $this->isSomeValue();
161 161
 			case $snak instanceof PropertyNoValueSnak:
Please login to merge, or discard this patch.
src/Api/CheckConstraintsRdf.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		EntityIdLookup $entityIdLookup,
48 48
 		RdfVocabulary $rdfVocabulary
49 49
 	) {
50
-		parent::__construct( $page, $context );
50
+		parent::__construct($page, $context);
51 51
 		$this->resultsSource = $resultsSource;
52 52
 		$this->entityIdLookup = $entityIdLookup;
53 53
 		$this->rdfVocabulary = $rdfVocabulary;
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 	 * @param string $guid
109 109
 	 * @return string
110 110
 	 */
111
-	private function cleanupGuid( $guid ) {
112
-		return preg_replace( '/[^\w-]/', '-', $guid );
111
+	private function cleanupGuid($guid) {
112
+		return preg_replace('/[^\w-]/', '-', $guid);
113 113
 	}
114 114
 
115 115
 	/**
@@ -121,60 +121,60 @@  discard block
 block discarded – undo
121 121
 		$response = $this->getRequest()->response();
122 122
 		$this->getOutput()->disable();
123 123
 
124
-		if ( !$this->resultsSource instanceof CachingResultsSource ) {
124
+		if (!$this->resultsSource instanceof CachingResultsSource) {
125 125
 			// TODO: make configurable whether only cached results are returned
126
-			$response->statusHeader( 501 ); // Not Implemented
126
+			$response->statusHeader(501); // Not Implemented
127 127
 			return null;
128 128
 		}
129 129
 
130
-		$entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() );
131
-		if ( $entityId === null ) {
132
-			$response->statusHeader( 404 ); // Not Found
130
+		$entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle());
131
+		if ($entityId === null) {
132
+			$response->statusHeader(404); // Not Found
133 133
 			return null;
134 134
 		}
135
-		$revId = $this->getRequest()->getInt( 'revision' );
135
+		$revId = $this->getRequest()->getInt('revision');
136 136
 
137
-		$results = $this->resultsSource->getStoredResults( $entityId, $revId );
138
-		if ( $results === null ) {
139
-			$response->statusHeader( 204 ); // No Content
137
+		$results = $this->resultsSource->getStoredResults($entityId, $revId);
138
+		if ($results === null) {
139
+			$response->statusHeader(204); // No Content
140 140
 			return null;
141 141
 		}
142 142
 
143 143
 		$format = 'ttl'; // TODO: make format an option
144 144
 
145 145
 		$writerFactory = new RdfWriterFactory();
146
-		$formatName = $writerFactory->getFormatName( $format );
147
-		$contentType = $writerFactory->getMimeTypes( $formatName )[0];
146
+		$formatName = $writerFactory->getFormatName($format);
147
+		$contentType = $writerFactory->getMimeTypes($formatName)[0];
148 148
 
149
-		$writer = $writerFactory->getWriter( $formatName );
150
-		foreach ( [ RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY ] as $ns ) {
151
-			$writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) );
149
+		$writer = $writerFactory->getWriter($formatName);
150
+		foreach ([RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY] as $ns) {
151
+			$writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns));
152 152
 		}
153 153
 		$writer->start();
154 154
 		$writtenAny = false;
155 155
 
156
-		foreach ( $results->getArray() as $checkResult ) {
157
-			if ( $checkResult instanceof NullResult ) {
156
+		foreach ($results->getArray() as $checkResult) {
157
+			if ($checkResult instanceof NullResult) {
158 158
 				continue;
159 159
 			}
160
-			if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) {
160
+			if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) {
161 161
 				continue;
162 162
 			}
163 163
 			$writtenAny = true;
164
-			$writer->about( RdfVocabulary::NS_STATEMENT,
165
-				$this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) )
166
-				->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' )
167
-				->is( RdfVocabulary::NS_STATEMENT,
168
-					$this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) );
164
+			$writer->about(RdfVocabulary::NS_STATEMENT,
165
+				$this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid()))
166
+				->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint')
167
+				->is(RdfVocabulary::NS_STATEMENT,
168
+					$this->cleanupGuid($checkResult->getConstraint()->getConstraintId()));
169 169
 		}
170 170
 		$writer->finish();
171
-		if ( $writtenAny ) {
172
-			$response->header( "Content-Type: $contentType; charset=UTF-8" );
171
+		if ($writtenAny) {
172
+			$response->header("Content-Type: $contentType; charset=UTF-8");
173 173
 			echo $writer->drain();
174 174
 		} else {
175 175
 			// Do not output RDF if we haven't written any actual statements. Output 204 instead
176 176
 			$writer->drain();
177
-			$response->statusHeader( 204 ); // No Content
177
+			$response->statusHeader(204); // No Content
178 178
 		}
179 179
 		return null;
180 180
 	}
Please login to merge, or discard this patch.
src/Api/CheckResultsRenderer.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -51,11 +51,11 @@  discard block
 block discarded – undo
51 51
 	 * @param CachedCheckResults $checkResults
52 52
 	 * @return CachedCheckConstraintsResponse
53 53
 	 */
54
-	public function render( CachedCheckResults $checkResults ) {
54
+	public function render(CachedCheckResults $checkResults) {
55 55
 		$response = [];
56
-		foreach ( $checkResults->getArray() as $checkResult ) {
57
-			$resultArray = $this->checkResultToArray( $checkResult );
58
-			$checkResult->getContextCursor()->storeCheckResultInArray( $resultArray, $response );
56
+		foreach ($checkResults->getArray() as $checkResult) {
57
+			$resultArray = $this->checkResultToArray($checkResult);
58
+			$checkResult->getContextCursor()->storeCheckResultInArray($resultArray, $response);
59 59
 		}
60 60
 		return new CachedCheckConstraintsResponse(
61 61
 			$response,
@@ -63,19 +63,19 @@  discard block
 block discarded – undo
63 63
 		);
64 64
 	}
65 65
 
66
-	public function checkResultToArray( CheckResult $checkResult ) {
67
-		if ( $checkResult instanceof NullResult ) {
66
+	public function checkResultToArray(CheckResult $checkResult) {
67
+		if ($checkResult instanceof NullResult) {
68 68
 			return null;
69 69
 		}
70 70
 
71 71
 		$constraintId = $checkResult->getConstraint()->getConstraintId();
72 72
 		$typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId();
73
-		$constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() );
73
+		$constraintPropertyId = new PropertyId($checkResult->getContextCursor()->getSnakPropertyId());
74 74
 
75
-		$title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId );
75
+		$title = $this->entityTitleLookup->getTitleForId($constraintPropertyId);
76 76
 		$talkTitle = $title->getTalkPageIfDefined();
77
-		$typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) );
78
-		$link = $title->getFullURL() . '#' . $constraintId;
77
+		$typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId));
78
+		$link = $title->getFullURL().'#'.$constraintId;
79 79
 
80 80
 		$constraint = [
81 81
 			'id' => $constraintId,
@@ -91,14 +91,14 @@  discard block
 block discarded – undo
91 91
 			'constraint' => $constraint
92 92
 		];
93 93
 		$message = $checkResult->getMessage();
94
-		if ( $message ) {
95
-			$result['message-html'] = $this->violationMessageRenderer->render( $message );
94
+		if ($message) {
95
+			$result['message-html'] = $this->violationMessageRenderer->render($message);
96 96
 		}
97
-		if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) {
97
+		if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) {
98 98
 			$result['claim'] = $checkResult->getContextCursor()->getStatementGuid();
99 99
 		}
100 100
 		$cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray();
101
-		if ( $cachingMetadataArray !== null ) {
101
+		if ($cachingMetadataArray !== null) {
102 102
 			$result['cached'] = $cachingMetadataArray;
103 103
 		}
104 104
 
Please login to merge, or discard this patch.
src/ConstraintStore.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 	 * @return bool
17 17
 	 * @throws DBUnexpectedError
18 18
 	 */
19
-	public function insertBatch( array $constraints );
19
+	public function insertBatch(array $constraints);
20 20
 
21 21
 	/**
22 22
 	 * Delete all constraints for the property ID.
@@ -25,6 +25,6 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @throws DBUnexpectedError
27 27
 	 */
28
-	public function deleteForProperty( PropertyId $propertyId );
28
+	public function deleteForProperty(PropertyId $propertyId);
29 29
 
30 30
 }
Please login to merge, or discard this patch.
src/Job/UpdateConstraintsTableJob.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 
33 33
 	const BATCH_SIZE = 10;
34 34
 
35
-	public static function newFromGlobalState( Title $title, array $params ) {
36
-		Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' );
35
+	public static function newFromGlobalState(Title $title, array $params) {
36
+		Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]');
37 37
 		$repo = WikibaseRepo::getDefaultInstance();
38 38
 		return new UpdateConstraintsTableJob(
39 39
 			$title,
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 			$params['revisionId'] ?? null,
43 43
 			MediaWikiServices::getInstance()->getMainConfig(),
44 44
 			ConstraintsServices::getConstraintStore(),
45
-			$repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ),
45
+			$repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED),
46 46
 			$repo->getBaseDataModelSerializerFactory()->newSnakSerializer()
47 47
 		);
48 48
 	}
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		EntityRevisionLookup $entityRevisionLookup,
98 98
 		Serializer $snakSerializer
99 99
 	) {
100
-		parent::__construct( 'constraintsTableUpdate', $title, $params );
100
+		parent::__construct('constraintsTableUpdate', $title, $params);
101 101
 
102 102
 		$this->propertyId = $propertyId;
103 103
 		$this->revisionId = $revisionId;
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 		$this->snakSerializer = $snakSerializer;
108 108
 	}
109 109
 
110
-	public function extractParametersFromQualifiers( SnakList $qualifiers ) {
110
+	public function extractParametersFromQualifiers(SnakList $qualifiers) {
111 111
 		$parameters = [];
112
-		foreach ( $qualifiers as $qualifier ) {
112
+		foreach ($qualifiers as $qualifier) {
113 113
 			$qualifierId = $qualifier->getPropertyId()->getSerialization();
114
-			$paramSerialization = $this->snakSerializer->serialize( $qualifier );
114
+			$paramSerialization = $this->snakSerializer->serialize($qualifier);
115 115
 			$parameters[$qualifierId][] = $paramSerialization;
116 116
 		}
117 117
 		return $parameters;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		'@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue';
129 129
 		$entityId = $dataValue->getEntityId();
130 130
 		$constraintTypeQid = $entityId->getSerialization();
131
-		$parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() );
131
+		$parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers());
132 132
 		return new Constraint(
133 133
 			$constraintId,
134 134
 			$propertyId,
@@ -143,17 +143,17 @@  discard block
 block discarded – undo
143 143
 		PropertyId $propertyConstraintPropertyId
144 144
 	) {
145 145
 		$constraintsStatements = $property->getStatements()
146
-			->getByPropertyId( $propertyConstraintPropertyId )
147
-			->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] );
146
+			->getByPropertyId($propertyConstraintPropertyId)
147
+			->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]);
148 148
 		$constraints = [];
149
-		foreach ( $constraintsStatements->getIterator() as $constraintStatement ) {
150
-			$constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement );
151
-			if ( count( $constraints ) >= self::BATCH_SIZE ) {
152
-				$constraintStore->insertBatch( $constraints );
149
+		foreach ($constraintsStatements->getIterator() as $constraintStatement) {
150
+			$constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement);
151
+			if (count($constraints) >= self::BATCH_SIZE) {
152
+				$constraintStore->insertBatch($constraints);
153 153
 				$constraints = [];
154 154
 			}
155 155
 		}
156
-		$constraintStore->insertBatch( $constraints );
156
+		$constraintStore->insertBatch($constraints);
157 157
 	}
158 158
 
159 159
 	/**
@@ -164,19 +164,19 @@  discard block
 block discarded – undo
164 164
 	public function run() {
165 165
 		// TODO in the future: only touch constraints affected by the edit (requires T163465)
166 166
 
167
-		$propertyId = new PropertyId( $this->propertyId );
167
+		$propertyId = new PropertyId($this->propertyId);
168 168
 		$propertyRevision = $this->entityRevisionLookup->getEntityRevision(
169 169
 			$propertyId,
170 170
 			0, // latest
171 171
 			LookupConstants::LATEST_FROM_REPLICA
172 172
 		);
173 173
 
174
-		if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) {
175
-			JobQueueGroup::singleton()->push( $this );
174
+		if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) {
175
+			JobQueueGroup::singleton()->push($this);
176 176
 			return true;
177 177
 		}
178 178
 
179
-		$this->constraintStore->deleteForProperty( $propertyId );
179
+		$this->constraintStore->deleteForProperty($propertyId);
180 180
 
181 181
 		/** @var Property $property */
182 182
 		$property = $propertyRevision->getEntity();
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		$this->importConstraintsForProperty(
185 185
 			$property,
186 186
 			$this->constraintStore,
187
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) )
187
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId'))
188 188
 		);
189 189
 
190 190
 		return true;
Please login to merge, or discard this patch.
src/ConstraintRepositoryStore.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -24,16 +24,16 @@  discard block
 block discarded – undo
24 24
 	 * then using the main DBLoadBalancer service may be incorrect.
25 25
 	 * @param string|false $dbName Database name ($domain for ILoadBalancer methods).
26 26
 	 */
27
-	public function __construct( ILoadBalancer $lb, $dbName ) {
27
+	public function __construct(ILoadBalancer $lb, $dbName) {
28 28
 		$this->lb = $lb;
29 29
 		$this->dbName = $dbName;
30 30
 	}
31 31
 
32
-	private function encodeConstraintParameters( array $constraintParameters ) {
33
-		$json = json_encode( $constraintParameters, JSON_FORCE_OBJECT );
32
+	private function encodeConstraintParameters(array $constraintParameters) {
33
+		$json = json_encode($constraintParameters, JSON_FORCE_OBJECT);
34 34
 
35
-		if ( strlen( $json ) > 50000 ) {
36
-			$json = json_encode( [ '@error' => [ 'toolong' => true ] ] );
35
+		if (strlen($json) > 50000) {
36
+			$json = json_encode(['@error' => ['toolong' => true]]);
37 37
 		}
38 38
 
39 39
 		return $json;
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 * @throws DBUnexpectedError
46 46
 	 * @return bool
47 47
 	 */
48
-	public function insertBatch( array $constraints ) {
48
+	public function insertBatch(array $constraints) {
49 49
 		$accumulator = array_map(
50
-			function ( Constraint $constraint ) {
50
+			function(Constraint $constraint) {
51 51
 				return [
52 52
 					'constraint_guid' => $constraint->getConstraintId(),
53 53
 					'pid' => $constraint->getPropertyId()->getNumericId(),
54 54
 					'constraint_type_qid' => $constraint->getConstraintTypeItemId(),
55
-					'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() )
55
+					'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters())
56 56
 				];
57 57
 			},
58 58
 			$constraints
59 59
 		);
60 60
 
61
-		$dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName );
62
-		return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ );
61
+		$dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName);
62
+		return $dbw->insert('wbqc_constraints', $accumulator, __METHOD__);
63 63
 	}
64 64
 
65 65
 	/**
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @throws DBUnexpectedError
71 71
 	 */
72
-	public function deleteForProperty( PropertyId $propertyId ) {
73
-		$dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName );
72
+	public function deleteForProperty(PropertyId $propertyId) {
73
+		$dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName);
74 74
 		$dbw->delete(
75 75
 			'wbqc_constraints',
76 76
 			[
Please login to merge, or discard this patch.
src/ConstraintRepositoryLookup.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * then using the main DBLoadBalancer service may be incorrect.
26 26
 	 * @param string|false $dbName Database name ($domain for ILoadBalancer methods).
27 27
 	 */
28
-	public function __construct( ILoadBalancer $lb, $dbName ) {
28
+	public function __construct(ILoadBalancer $lb, $dbName) {
29 29
 		$this->lb = $lb;
30 30
 		$this->dbName = $dbName;
31 31
 	}
@@ -35,17 +35,17 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @return Constraint[]
37 37
 	 */
38
-	public function queryConstraintsForProperty( PropertyId $propertyId ) {
39
-		$dbr = $this->lb->getConnectionRef( ILoadBalancer::DB_REPLICA, [], $this->dbName );
38
+	public function queryConstraintsForProperty(PropertyId $propertyId) {
39
+		$dbr = $this->lb->getConnectionRef(ILoadBalancer::DB_REPLICA, [], $this->dbName);
40 40
 
41 41
 		$results = $dbr->select(
42 42
 			'wbqc_constraints',
43 43
 			'*',
44
-			[ 'pid' => $propertyId->getNumericId() ],
44
+			['pid' => $propertyId->getNumericId()],
45 45
 			__METHOD__
46 46
 		);
47 47
 
48
-		return $this->convertToConstraints( $results );
48
+		return $this->convertToConstraints($results);
49 49
 	}
50 50
 
51 51
 	/**
@@ -53,26 +53,26 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return Constraint[]
55 55
 	 */
56
-	private function convertToConstraints( IResultWrapper $results ) {
56
+	private function convertToConstraints(IResultWrapper $results) {
57 57
 		$constraints = [];
58
-		$logger = LoggerFactory::getInstance( 'WikibaseQualityConstraints' );
59
-		foreach ( $results as $result ) {
58
+		$logger = LoggerFactory::getInstance('WikibaseQualityConstraints');
59
+		foreach ($results as $result) {
60 60
 			$constraintTypeItemId = $result->constraint_type_qid;
61
-			$constraintParameters = json_decode( $result->constraint_parameters, true );
61
+			$constraintParameters = json_decode($result->constraint_parameters, true);
62 62
 
63
-			if ( $constraintParameters === null ) {
63
+			if ($constraintParameters === null) {
64 64
 				// T171295
65
-				$logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [
65
+				$logger->warning('Constraint {constraintId} has invalid constraint parameters.', [
66 66
 					'method' => __METHOD__,
67 67
 					'constraintId' => $result->constraint_guid,
68 68
 					'constraintParameters' => $result->constraint_parameters,
69
-				] );
70
-				$constraintParameters = [ '@error' => [ /* unknown */ ] ];
69
+				]);
70
+				$constraintParameters = ['@error' => [/* unknown */]];
71 71
 			}
72 72
 
73 73
 			$constraints[] = new Constraint(
74 74
 				$result->constraint_guid,
75
-				PropertyId::newFromNumber( $result->pid ),
75
+				PropertyId::newFromNumber($result->pid),
76 76
 				$constraintTypeItemId,
77 77
 				$constraintParameters
78 78
 			);
Please login to merge, or discard this patch.
maintenance/ImportConstraintEntities.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 use Wikibase\Repo\WikibaseRepo;
18 18
 
19 19
 // @codeCoverageIgnoreStart
20
-$basePath = getenv( "MW_INSTALL_PATH" ) !== false
21
-	? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../..";
20
+$basePath = getenv("MW_INSTALL_PATH") !== false
21
+	? getenv("MW_INSTALL_PATH") : __DIR__."/../../..";
22 22
 
23
-require_once $basePath . "/maintenance/Maintenance.php";
23
+require_once $basePath."/maintenance/Maintenance.php";
24 24
 // @codeCoverageIgnoreEnd
25 25
 
26 26
 /**
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
 		parent::__construct();
60 60
 
61 61
 		$this->addDescription(
62
-			'Import entities needed for constraint checks ' .
62
+			'Import entities needed for constraint checks '.
63 63
 			'from Wikidata into the local repository.'
64 64
 		);
65 65
 		$this->addOption(
66 66
 			'config-format',
67
-			'The format in which the resulting configuration will be omitted: ' .
68
-			'"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' .
67
+			'The format in which the resulting configuration will be omitted: '.
68
+			'"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '.
69 69
 			'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.'
70 70
 		);
71 71
 		$this->addOption(
72 72
 			'dry-run',
73 73
 			'Don’t actually import entities, just print which ones would be imported.'
74 74
 		);
75
-		$this->requireExtension( 'WikibaseQualityConstraints' );
75
+		$this->requireExtension('WikibaseQualityConstraints');
76 76
 	}
77 77
 
78 78
 	/**
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 		$this->entityDeserializer = $repo->getInternalFormatEntityDeserializer();
85 85
 		$this->entityStore = $repo->getEntityStore();
86 86
 		$this->httpRequestFactory = MediaWikiServices::getInstance()->getHttpRequestFactory();
87
-		if ( !$this->getOption( 'dry-run', false ) ) {
88
-			$this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' );
87
+		if (!$this->getOption('dry-run', false)) {
88
+			$this->user = User::newSystemUser('WikibaseQualityConstraints importer');
89 89
 		}
90 90
 	}
91 91
 
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
 
95 95
 		$configUpdates = [];
96 96
 
97
-		$extensionJsonFile = __DIR__ . '/../extension.json';
98
-		$extensionJsonText = file_get_contents( $extensionJsonFile );
99
-		$extensionJson = json_decode( $extensionJsonText, /* assoc = */ true );
97
+		$extensionJsonFile = __DIR__.'/../extension.json';
98
+		$extensionJsonText = file_get_contents($extensionJsonFile);
99
+		$extensionJson = json_decode($extensionJsonText, /* assoc = */ true);
100 100
 		// @phan-suppress-next-line PhanTypeArraySuspiciousNullable
101
-		$wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() );
101
+		$wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig());
102 102
 
103
-		foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) {
104
-			$localEntityId = $this->importEntityFromWikidata( $wikidataEntityId );
103
+		foreach ($wikidataEntityIds as $key => $wikidataEntityId) {
104
+			$localEntityId = $this->importEntityFromWikidata($wikidataEntityId);
105 105
 			$configUpdates[$key] = [
106 106
 				'wikidata' => $wikidataEntityId,
107 107
 				'local' => $localEntityId,
108 108
 			];
109 109
 		}
110 110
 
111
-		$this->outputConfigUpdates( $configUpdates );
111
+		$this->outputConfigUpdates($configUpdates);
112 112
 	}
113 113
 
114 114
 	/**
@@ -116,18 +116,18 @@  discard block
 block discarded – undo
116 116
 	 * @param Config $wikiConfig
117 117
 	 * @return string[]
118 118
 	 */
119
-	private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) {
119
+	private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) {
120 120
 		$wikidataEntityIds = [];
121 121
 
122
-		foreach ( $extensionJsonConfig as $key => $value ) {
123
-			if ( !preg_match( '/Id$/', $key ) ) {
122
+		foreach ($extensionJsonConfig as $key => $value) {
123
+			if (!preg_match('/Id$/', $key)) {
124 124
 				continue;
125 125
 			}
126 126
 
127 127
 			$wikidataEntityId = $value['value'];
128
-			$localEntityId = $wikiConfig->get( $key );
128
+			$localEntityId = $wikiConfig->get($key);
129 129
 
130
-			if ( $localEntityId === $wikidataEntityId ) {
130
+			if ($localEntityId === $wikidataEntityId) {
131 131
 				$wikidataEntityIds[$key] = $wikidataEntityId;
132 132
 			}
133 133
 		}
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
 	 * @param string $wikidataEntityId
140 140
 	 * @return string local entity ID
141 141
 	 */
142
-	private function importEntityFromWikidata( $wikidataEntityId ) {
142
+	private function importEntityFromWikidata($wikidataEntityId) {
143 143
 		$wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json";
144
-		$wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ );
145
-		return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson );
144
+		$wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__);
145
+		return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson);
146 146
 	}
147 147
 
148 148
 	/**
@@ -150,24 +150,24 @@  discard block
 block discarded – undo
150 150
 	 * @param string $wikidataEntitiesJson
151 151
 	 * @return string local entity ID
152 152
 	 */
153
-	private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) {
153
+	private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) {
154 154
 		// @phan-suppress-next-line PhanTypeArraySuspiciousNullable
155
-		$wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId];
156
-		$wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray );
155
+		$wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId];
156
+		$wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray);
157 157
 
158
-		$wikidataEntity->setId( null );
158
+		$wikidataEntity->setId(null);
159 159
 
160
-		if ( $wikidataEntity instanceof StatementListProvider ) {
160
+		if ($wikidataEntity instanceof StatementListProvider) {
161 161
 			$wikidataEntity->getStatements()->clear();
162 162
 		}
163 163
 
164
-		if ( $wikidataEntity instanceof Item ) {
165
-			$wikidataEntity->setSiteLinkList( new SiteLinkList() );
164
+		if ($wikidataEntity instanceof Item) {
165
+			$wikidataEntity->setSiteLinkList(new SiteLinkList());
166 166
 		}
167 167
 
168
-		if ( $this->getOption( 'dry-run', false ) ) {
169
-			$wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) );
170
-			$this->output( $wikidataEntityJson . "\n" );
168
+		if ($this->getOption('dry-run', false)) {
169
+			$wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity));
170
+			$this->output($wikidataEntityJson."\n");
171 171
 			return "-$wikidataEntityId";
172 172
 		}
173 173
 
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
 			)->getEntity();
181 181
 
182 182
 			return $localEntity->getId()->getSerialization();
183
-		} catch ( StorageException $storageException ) {
184
-			return $this->storageExceptionToEntityId( $storageException );
183
+		} catch (StorageException $storageException) {
184
+			return $this->storageExceptionToEntityId($storageException);
185 185
 		}
186 186
 	}
187 187
 
188
-	private function storageExceptionToEntityId( StorageException $storageException ) {
188
+	private function storageExceptionToEntityId(StorageException $storageException) {
189 189
 		$message = $storageException->getMessage();
190 190
 		// example messages:
191 191
 		// * Item [[Item:Q475|Q475]] already has label "as references"
@@ -195,25 +195,25 @@  discard block
 block discarded – undo
195 195
 		// * Property [[Property:P694|P694]] already has label "instance of"
196 196
 		//   associated with language code en.
197 197
 		$pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/';
198
-		if ( preg_match( $pattern, $message, $matches ) ) {
198
+		if (preg_match($pattern, $message, $matches)) {
199 199
 			return $matches[1];
200 200
 		} else {
201 201
 			throw $storageException;
202 202
 		}
203 203
 	}
204 204
 
205
-	private function outputConfigUpdates( array $configUpdates ) {
206
-		$configFormat = $this->getOption( 'config-format', 'globals' );
207
-		switch ( $configFormat ) {
205
+	private function outputConfigUpdates(array $configUpdates) {
206
+		$configFormat = $this->getOption('config-format', 'globals');
207
+		switch ($configFormat) {
208 208
 			case 'globals':
209
-				$this->outputConfigUpdatesGlobals( $configUpdates );
209
+				$this->outputConfigUpdatesGlobals($configUpdates);
210 210
 				break;
211 211
 			case 'wgConf':
212
-				$this->outputConfigUpdatesWgConf( $configUpdates );
212
+				$this->outputConfigUpdatesWgConf($configUpdates);
213 213
 				break;
214 214
 			default:
215
-				$this->error( "Invalid config format \"$configFormat\", using \"globals\"" );
216
-				$this->outputConfigUpdatesGlobals( $configUpdates );
215
+				$this->error("Invalid config format \"$configFormat\", using \"globals\"");
216
+				$this->outputConfigUpdatesGlobals($configUpdates);
217 217
 				break;
218 218
 		}
219 219
 	}
@@ -221,22 +221,22 @@  discard block
 block discarded – undo
221 221
 	/**
222 222
 	 * @param array[] $configUpdates
223 223
 	 */
224
-	private function outputConfigUpdatesGlobals( array $configUpdates ) {
225
-		foreach ( $configUpdates as $key => $value ) {
226
-			$localValueCode = var_export( $value['local'], true );
227
-			$this->output( "\$wg$key = $localValueCode;\n" );
224
+	private function outputConfigUpdatesGlobals(array $configUpdates) {
225
+		foreach ($configUpdates as $key => $value) {
226
+			$localValueCode = var_export($value['local'], true);
227
+			$this->output("\$wg$key = $localValueCode;\n");
228 228
 		}
229 229
 	}
230 230
 
231 231
 	/**
232 232
 	 * @param array[] $configUpdates
233 233
 	 */
234
-	private function outputConfigUpdatesWgConf( array $configUpdates ) {
235
-		foreach ( $configUpdates as $key => $value ) {
236
-			$keyCode = var_export( "wg$key", true );
237
-			$wikidataValueCode = var_export( $value['wikidata'], true );
238
-			$localValueCode = var_export( $value['local'], true );
239
-			$wikiIdCode = var_export( wfWikiID(), true );
234
+	private function outputConfigUpdatesWgConf(array $configUpdates) {
235
+		foreach ($configUpdates as $key => $value) {
236
+			$keyCode = var_export("wg$key", true);
237
+			$wikidataValueCode = var_export($value['wikidata'], true);
238
+			$localValueCode = var_export($value['local'], true);
239
+			$wikiIdCode = var_export(wfWikiID(), true);
240 240
 			$block = <<< EOF
241 241
 $keyCode => [
242 242
 	'default' => $wikidataValueCode,
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 
246 246
 
247 247
 EOF;
248
-			$this->output( $block );
248
+			$this->output($block);
249 249
 		}
250 250
 	}
251 251
 
Please login to merge, or discard this patch.
src/WikibaseQualityConstraintsHooks.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -28,25 +28,25 @@  discard block
 block discarded – undo
28 28
 	/**
29 29
 	 * @param DatabaseUpdater $updater
30 30
 	 */
31
-	public static function onCreateSchema( DatabaseUpdater $updater ) {
31
+	public static function onCreateSchema(DatabaseUpdater $updater) {
32 32
 		$updater->addExtensionTable(
33 33
 			'wbqc_constraints',
34
-			__DIR__ . '/../sql/create_wbqc_constraints.sql'
34
+			__DIR__.'/../sql/create_wbqc_constraints.sql'
35 35
 		);
36 36
 		$updater->addExtensionField(
37 37
 			'wbqc_constraints',
38 38
 			'constraint_id',
39
-			__DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql'
39
+			__DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql'
40 40
 		);
41 41
 		$updater->addExtensionIndex(
42 42
 			'wbqc_constraints',
43 43
 			'wbqc_constraints_guid_uniq',
44
-			__DIR__ . '/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql'
44
+			__DIR__.'/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql'
45 45
 		);
46 46
 	}
47 47
 
48
-	public static function onWikibaseChange( Change $change ) {
49
-		if ( !( $change instanceof EntityChange ) ) {
48
+	public static function onWikibaseChange(Change $change) {
49
+		if (!($change instanceof EntityChange)) {
50 50
 			return;
51 51
 		}
52 52
 
@@ -55,48 +55,48 @@  discard block
 block discarded – undo
55 55
 
56 56
 		// If jobs are enabled and the results would be stored in some way run a job.
57 57
 		if (
58
-			$config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) &&
59
-			$config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) &&
58
+			$config->get('WBQualityConstraintsEnableConstraintsCheckJobs') &&
59
+			$config->get('WBQualityConstraintsCacheCheckConstraintsResults') &&
60 60
 			self::isSelectedForJobRunBasedOnPercentage()
61 61
 		) {
62
-			$params = [ 'entityId' => $change->getEntityId()->getSerialization() ];
62
+			$params = ['entityId' => $change->getEntityId()->getSerialization()];
63 63
 			JobQueueGroup::singleton()->push(
64
-				new JobSpecification( CheckConstraintsJob::COMMAND, $params )
64
+				new JobSpecification(CheckConstraintsJob::COMMAND, $params)
65 65
 			);
66 66
 		}
67 67
 
68
-		if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) &&
69
-			self::isConstraintStatementsChange( $config, $change )
68
+		if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') &&
69
+			self::isConstraintStatementsChange($config, $change)
70 70
 		) {
71
-			$params = [ 'propertyId' => $change->getEntityId()->getSerialization() ];
71
+			$params = ['propertyId' => $change->getEntityId()->getSerialization()];
72 72
 			$metadata = $change->getMetadata();
73
-			if ( array_key_exists( 'rev_id', $metadata ) ) {
73
+			if (array_key_exists('rev_id', $metadata)) {
74 74
 				$params['revisionId'] = $metadata['rev_id'];
75 75
 			}
76 76
 			JobQueueGroup::singleton()->push(
77
-				new JobSpecification( 'constraintsTableUpdate', $params )
77
+				new JobSpecification('constraintsTableUpdate', $params)
78 78
 			);
79 79
 		}
80 80
 	}
81 81
 
82 82
 	private static function isSelectedForJobRunBasedOnPercentage() {
83 83
 		$config = MediaWikiServices::getInstance()->getMainConfig();
84
-		$percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' );
84
+		$percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio');
85 85
 
86
-		return mt_rand( 1, 100 ) <= $percentage;
86
+		return mt_rand(1, 100) <= $percentage;
87 87
 	}
88 88
 
89
-	public static function isConstraintStatementsChange( Config $config, Change $change ) {
90
-		if ( !( $change instanceof EntityChange ) ||
89
+	public static function isConstraintStatementsChange(Config $config, Change $change) {
90
+		if (!($change instanceof EntityChange) ||
91 91
 			 $change->getAction() !== EntityChange::UPDATE ||
92
-			 !( $change->getEntityId() instanceof PropertyId )
92
+			 !($change->getEntityId() instanceof PropertyId)
93 93
 		) {
94 94
 			return false;
95 95
 		}
96 96
 
97 97
 		$info = $change->getInfo();
98 98
 
99
-		if ( !array_key_exists( 'compactDiff', $info ) ) {
99
+		if (!array_key_exists('compactDiff', $info)) {
100 100
 			// the non-compact diff ($info['diff']) does not contain statement diffs (T110996),
101 101
 			// so we only know that the change *might* affect the constraint statements
102 102
 			return true;
@@ -105,47 +105,47 @@  discard block
 block discarded – undo
105 105
 		/** @var EntityDiffChangedAspects $aspects */
106 106
 		$aspects = $info['compactDiff'];
107 107
 
108
-		$propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' );
109
-		return in_array( $propertyConstraintId, $aspects->getStatementChanges() );
108
+		$propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId');
109
+		return in_array($propertyConstraintId, $aspects->getStatementChanges());
110 110
 	}
111 111
 
112
-	public static function onArticlePurge( WikiPage $wikiPage ) {
112
+	public static function onArticlePurge(WikiPage $wikiPage) {
113 113
 		$repo = WikibaseRepo::getDefaultInstance();
114 114
 
115 115
 		$entityContentFactory = $repo->getEntityContentFactory();
116
-		if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) {
116
+		if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) {
117 117
 			$entityIdLookup = $repo->getEntityIdLookup();
118
-			$entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() );
119
-			if ( $entityId !== null ) {
118
+			$entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle());
119
+			if ($entityId !== null) {
120 120
 				$resultsCache = ResultsCache::getDefaultInstance();
121
-				$resultsCache->delete( $entityId );
121
+				$resultsCache->delete($entityId);
122 122
 			}
123 123
 		}
124 124
 	}
125 125
 
126
-	public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
126
+	public static function onBeforePageDisplay(OutputPage $out, Skin $skin) {
127 127
 		$repo = WikibaseRepo::getDefaultInstance();
128 128
 
129 129
 		$lookup = $repo->getEntityNamespaceLookup();
130 130
 		$title = $out->getTitle();
131
-		if ( $title === null ) {
131
+		if ($title === null) {
132 132
 			return;
133 133
 		}
134 134
 
135
-		if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) {
135
+		if (!$lookup->isNamespaceWithEntities($title->getNamespace())) {
136 136
 			return;
137 137
 		}
138
-		if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) {
138
+		if (empty($out->getJsConfigVars()['wbIsEditView'])) {
139 139
 			return;
140 140
 		}
141 141
 
142
-		$out->addModules( 'wikibase.quality.constraints.suggestions' );
142
+		$out->addModules('wikibase.quality.constraints.suggestions');
143 143
 
144
-		if ( !$out->getUser()->isLoggedIn() ) {
144
+		if (!$out->getUser()->isLoggedIn()) {
145 145
 			return;
146 146
 		}
147 147
 
148
-		$out->addModules( 'wikibase.quality.constraints.gadget' );
148
+		$out->addModules('wikibase.quality.constraints.gadget');
149 149
 	}
150 150
 
151 151
 }
Please login to merge, or discard this patch.