Completed
Push — master ( 2b2977...06c0aa )
by
unknown
02:09
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/Job/CheckConstraintsJob.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -37,25 +37,25 @@  discard block
 block discarded – undo
37 37
 	 * @param Title $title
38 38
 	 * @param string[] $params should contain 'entityId' => 'Q1234'
39 39
 	 */
40
-	public function __construct( Title $title, array $params ) {
41
-		parent::__construct( self::COMMAND, $title, $params );
40
+	public function __construct(Title $title, array $params) {
41
+		parent::__construct(self::COMMAND, $title, $params);
42 42
 		$this->removeDuplicates = true;
43 43
 
44
-		Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' );
44
+		Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']');
45 45
 
46
-		$resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() );
46
+		$resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance());
47 47
 		'@phan-var CachingResultsSource $resultSource';
48 48
 		// This job should only ever be used when caching result sources are used.
49
-		$this->setResultsSource( $resultSource );
49
+		$this->setResultsSource($resultSource);
50 50
 
51
-		$this->setEntityIdParser( WikibaseRepo::getDefaultInstance()->getEntityIdParser() );
51
+		$this->setEntityIdParser(WikibaseRepo::getDefaultInstance()->getEntityIdParser());
52 52
 	}
53 53
 
54
-	public function setResultsSource( CachingResultsSource $resultsSource ) {
54
+	public function setResultsSource(CachingResultsSource $resultsSource) {
55 55
 		$this->resultsSource = $resultsSource;
56 56
 	}
57 57
 
58
-	public function setEntityIdParser( EntityIdParser $parser ) {
58
+	public function setEntityIdParser(EntityIdParser $parser) {
59 59
 		$this->entityIdParser = $parser;
60 60
 	}
61 61
 
@@ -66,19 +66,19 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function run() {
68 68
 		try {
69
-			$entityId = $this->entityIdParser->parse( $this->params['entityId'] );
70
-		} catch ( EntityIdParsingException $e ) {
69
+			$entityId = $this->entityIdParser->parse($this->params['entityId']);
70
+		} catch (EntityIdParsingException $e) {
71 71
 			return false;
72 72
 		}
73 73
 
74
-		$this->checkConstraints( $entityId );
74
+		$this->checkConstraints($entityId);
75 75
 
76 76
 		return true;
77 77
 	}
78 78
 
79
-	private function checkConstraints( EntityId $entityId ) {
79
+	private function checkConstraints(EntityId $entityId) {
80 80
 		$this->resultsSource->getResults(
81
-			[ $entityId ],
81
+			[$entityId],
82 82
 			[],
83 83
 			null,
84 84
 			[]
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
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 
29 29
 	const BATCH_SIZE = 10;
30 30
 
31
-	public static function newFromGlobalState( Title $title, array $params ) {
32
-		Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' );
31
+	public static function newFromGlobalState(Title $title, array $params) {
32
+		Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]');
33 33
 		$repo = WikibaseRepo::getDefaultInstance();
34 34
 		return new UpdateConstraintsTableJob(
35 35
 			$title,
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 			$params['revisionId'] ?? null,
39 39
 			MediaWikiServices::getInstance()->getMainConfig(),
40 40
 			ConstraintsServices::getConstraintRepository(),
41
-			$repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ),
41
+			$repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED),
42 42
 			$repo->getBaseDataModelSerializerFactory()->newSnakSerializer()
43 43
 		);
44 44
 	}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		EntityRevisionLookup $entityRevisionLookup,
94 94
 		Serializer $snakSerializer
95 95
 	) {
96
-		parent::__construct( 'constraintsTableUpdate', $title, $params );
96
+		parent::__construct('constraintsTableUpdate', $title, $params);
97 97
 
98 98
 		$this->propertyId = $propertyId;
99 99
 		$this->revisionId = $revisionId;
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
 		$this->snakSerializer = $snakSerializer;
104 104
 	}
105 105
 
106
-	public function extractParametersFromQualifiers( SnakList $qualifiers ) {
106
+	public function extractParametersFromQualifiers(SnakList $qualifiers) {
107 107
 		$parameters = [];
108
-		foreach ( $qualifiers as $qualifier ) {
108
+		foreach ($qualifiers as $qualifier) {
109 109
 			$qualifierId = $qualifier->getPropertyId()->getSerialization();
110
-			$paramSerialization = $this->snakSerializer->serialize( $qualifier );
110
+			$paramSerialization = $this->snakSerializer->serialize($qualifier);
111 111
 			$parameters[$qualifierId][] = $paramSerialization;
112 112
 		}
113 113
 		return $parameters;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		'@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue';
125 125
 		$entityId = $dataValue->getEntityId();
126 126
 		$constraintTypeQid = $entityId->getSerialization();
127
-		$parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() );
127
+		$parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers());
128 128
 		return new Constraint(
129 129
 			$constraintId,
130 130
 			$propertyId,
@@ -139,17 +139,17 @@  discard block
 block discarded – undo
139 139
 		PropertyId $propertyConstraintPropertyId
140 140
 	) {
141 141
 		$constraintsStatements = $property->getStatements()
142
-			->getByPropertyId( $propertyConstraintPropertyId )
143
-			->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] );
142
+			->getByPropertyId($propertyConstraintPropertyId)
143
+			->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]);
144 144
 		$constraints = [];
145
-		foreach ( $constraintsStatements->getIterator() as $constraintStatement ) {
146
-			$constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement );
147
-			if ( count( $constraints ) >= self::BATCH_SIZE ) {
148
-				$constraintRepo->insertBatch( $constraints );
145
+		foreach ($constraintsStatements->getIterator() as $constraintStatement) {
146
+			$constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement);
147
+			if (count($constraints) >= self::BATCH_SIZE) {
148
+				$constraintRepo->insertBatch($constraints);
149 149
 				$constraints = [];
150 150
 			}
151 151
 		}
152
-		$constraintRepo->insertBatch( $constraints );
152
+		$constraintRepo->insertBatch($constraints);
153 153
 	}
154 154
 
155 155
 	/**
@@ -160,19 +160,19 @@  discard block
 block discarded – undo
160 160
 	public function run() {
161 161
 		// TODO in the future: only touch constraints affected by the edit (requires T163465)
162 162
 
163
-		$propertyId = new PropertyId( $this->propertyId );
163
+		$propertyId = new PropertyId($this->propertyId);
164 164
 		$propertyRevision = $this->entityRevisionLookup->getEntityRevision(
165 165
 			$propertyId,
166 166
 			0, // latest
167 167
 			EntityRevisionLookup::LATEST_FROM_REPLICA
168 168
 		);
169 169
 
170
-		if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) {
171
-			JobQueueGroup::singleton()->push( $this );
170
+		if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) {
171
+			JobQueueGroup::singleton()->push($this);
172 172
 			return true;
173 173
 		}
174 174
 
175
-		$this->constraintRepo->deleteForProperty( $propertyId );
175
+		$this->constraintRepo->deleteForProperty($propertyId);
176 176
 
177 177
 		/** @var Property $property */
178 178
 		$property = $propertyRevision->getEntity();
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		$this->importConstraintsForProperty(
181 181
 			$property,
182 182
 			$this->constraintRepo,
183
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) )
183
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId'))
184 184
 		);
185 185
 
186 186
 		return true;
Please login to merge, or discard this patch.
src/Api/CheckConstraintsRdf.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
 		EntityIdLookup $entityIdLookup,
40 40
 		RdfVocabulary $rdfVocabulary
41 41
 	) {
42
-		parent::__construct( $page, $context );
42
+		parent::__construct($page, $context);
43 43
 		$this->resultsSource = $resultsSource;
44 44
 		$this->entityIdLookup = $entityIdLookup;
45 45
 		$this->rdfVocabulary = $rdfVocabulary;
46 46
 	}
47 47
 
48
-	public static function newFromGlobalState( Page $page, IContextSource $context ) {
48
+	public static function newFromGlobalState(Page $page, IContextSource $context) {
49 49
 		$repo = WikibaseRepo::getDefaultInstance();
50 50
 
51 51
 		return new static(
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	 * @param string $guid
93 93
 	 * @return string
94 94
 	 */
95
-	private function cleanupGuid( $guid ) {
96
-		return preg_replace( '/[^\w-]/', '-', $guid );
95
+	private function cleanupGuid($guid) {
96
+		return preg_replace('/[^\w-]/', '-', $guid);
97 97
 	}
98 98
 
99 99
 	/**
@@ -105,60 +105,60 @@  discard block
 block discarded – undo
105 105
 		$response = $this->getRequest()->response();
106 106
 		$this->getOutput()->disable();
107 107
 
108
-		if ( !$this->resultsSource instanceof CachingResultsSource ) {
108
+		if (!$this->resultsSource instanceof CachingResultsSource) {
109 109
 			// TODO: make configurable whether only cached results are returned
110
-			$response->statusHeader( 501 ); // Not Implemented
110
+			$response->statusHeader(501); // Not Implemented
111 111
 			return null;
112 112
 		}
113 113
 
114
-		$entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() );
115
-		if ( $entityId === null ) {
116
-			$response->statusHeader( 404 ); // Not Found
114
+		$entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle());
115
+		if ($entityId === null) {
116
+			$response->statusHeader(404); // Not Found
117 117
 			return null;
118 118
 		}
119
-		$revId = $this->getRequest()->getInt( 'revision' );
119
+		$revId = $this->getRequest()->getInt('revision');
120 120
 
121
-		$results = $this->resultsSource->getStoredResults( $entityId, $revId );
122
-		if ( $results === null ) {
123
-			$response->statusHeader( 204 ); // No Content
121
+		$results = $this->resultsSource->getStoredResults($entityId, $revId);
122
+		if ($results === null) {
123
+			$response->statusHeader(204); // No Content
124 124
 			return null;
125 125
 		}
126 126
 
127 127
 		$format = 'ttl'; // TODO: make format an option
128 128
 
129 129
 		$writerFactory = new RdfWriterFactory();
130
-		$formatName = $writerFactory->getFormatName( $format );
131
-		$contentType = $writerFactory->getMimeTypes( $formatName )[0];
130
+		$formatName = $writerFactory->getFormatName($format);
131
+		$contentType = $writerFactory->getMimeTypes($formatName)[0];
132 132
 
133
-		$writer = $writerFactory->getWriter( $formatName );
134
-		foreach ( [ RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY ] as $ns ) {
135
-			$writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) );
133
+		$writer = $writerFactory->getWriter($formatName);
134
+		foreach ([RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY] as $ns) {
135
+			$writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns));
136 136
 		}
137 137
 		$writer->start();
138 138
 		$writtenAny = false;
139 139
 
140
-		foreach ( $results->getArray() as $checkResult ) {
141
-			if ( $checkResult instanceof NullResult ) {
140
+		foreach ($results->getArray() as $checkResult) {
141
+			if ($checkResult instanceof NullResult) {
142 142
 				continue;
143 143
 			}
144
-			if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) {
144
+			if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) {
145 145
 				continue;
146 146
 			}
147 147
 			$writtenAny = true;
148
-			$writer->about( RdfVocabulary::NS_STATEMENT,
149
-				$this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) )
150
-				->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' )
151
-				->is( RdfVocabulary::NS_STATEMENT,
152
-					$this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) );
148
+			$writer->about(RdfVocabulary::NS_STATEMENT,
149
+				$this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid()))
150
+				->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint')
151
+				->is(RdfVocabulary::NS_STATEMENT,
152
+					$this->cleanupGuid($checkResult->getConstraint()->getConstraintId()));
153 153
 		}
154 154
 		$writer->finish();
155
-		if ( $writtenAny ) {
156
-			$response->header( "Content-Type: $contentType; charset=UTF-8" );
155
+		if ($writtenAny) {
156
+			$response->header("Content-Type: $contentType; charset=UTF-8");
157 157
 			echo $writer->drain();
158 158
 		} else {
159 159
 			// Do not output RDF if we haven't written any actual statements. Output 204 instead
160 160
 			$writer->drain();
161
-			$response->statusHeader( 204 ); // No Content
161
+			$response->statusHeader(204); // No Content
162 162
 		}
163 163
 		return null;
164 164
 	}
Please login to merge, or discard this patch.