@@ -80,23 +80,23 @@ discard block |
||
80 | 80 | * @return bool |
81 | 81 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
82 | 82 | */ |
83 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
84 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
83 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
84 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
85 | 85 | if ( ++$entitiesChecked > $maxEntities ) { |
86 | - throw new OverflowException( 'Too many entities to check' ); |
|
86 | + throw new OverflowException('Too many entities to check'); |
|
87 | 87 | } |
88 | 88 | |
89 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
90 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
89 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
90 | + if (!($item instanceof StatementListProvider)) { |
|
91 | 91 | return false; // lookup failed, probably because item doesn't exist |
92 | 92 | } |
93 | 93 | |
94 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
94 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
95 | 95 | /** @var Statement $statement */ |
96 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
96 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
97 | 97 | $mainSnak = $statement->getMainSnak(); |
98 | 98 | |
99 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
99 | + if (!($this->hasCorrectType($mainSnak))) { |
|
100 | 100 | continue; |
101 | 101 | } |
102 | 102 | /** @var PropertyValueSnak $mainSnak */ |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | $dataValue = $mainSnak->getDataValue(); |
106 | 106 | $comparativeClass = $dataValue->getEntityId(); |
107 | 107 | |
108 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
108 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
109 | 109 | return true; |
110 | 110 | } |
111 | 111 | |
112 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
112 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
113 | 113 | return true; |
114 | 114 | } |
115 | 115 | } |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | * @return CachedBool |
131 | 131 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
132 | 132 | */ |
133 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
133 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
134 | 134 | try { |
135 | 135 | return new CachedBool( |
136 | - $this->isSubclassOf( $comparativeClass, $classesToCheck ), |
|
136 | + $this->isSubclassOf($comparativeClass, $classesToCheck), |
|
137 | 137 | Metadata::blank() |
138 | 138 | ); |
139 | - } catch ( OverflowException $e ) { |
|
140 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
139 | + } catch (OverflowException $e) { |
|
140 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
141 | 141 | $this->dataFactory->increment( |
142 | 142 | 'wikibase.quality.constraints.sparql.typeFallback' |
143 | 143 | ); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | /* withInstance = */ false |
148 | 148 | ); |
149 | 149 | } else { |
150 | - return new CachedBool( false, Metadata::blank() ); |
|
150 | + return new CachedBool(false, Metadata::blank()); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | * @return CachedBool |
166 | 166 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
167 | 167 | */ |
168 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
168 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
169 | 169 | $metadatas = []; |
170 | 170 | |
171 | - foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
171 | + foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
172 | 172 | $mainSnak = $statement->getMainSnak(); |
173 | 173 | |
174 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
174 | + if (!$this->hasCorrectType($mainSnak)) { |
|
175 | 175 | continue; |
176 | 176 | } |
177 | 177 | /** @var PropertyValueSnak $mainSnak */ |
@@ -180,28 +180,28 @@ discard block |
||
180 | 180 | $dataValue = $mainSnak->getDataValue(); |
181 | 181 | $comparativeClass = $dataValue->getEntityId(); |
182 | 182 | |
183 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
183 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
184 | 184 | // discard $metadatas, we know this is fresh |
185 | - return new CachedBool( true, Metadata::blank() ); |
|
185 | + return new CachedBool(true, Metadata::blank()); |
|
186 | 186 | } |
187 | 187 | |
188 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
188 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
189 | 189 | $metadatas[] = $result->getMetadata(); |
190 | - if ( $result->getBool() ) { |
|
190 | + if ($result->getBool()) { |
|
191 | 191 | return new CachedBool( |
192 | 192 | true, |
193 | - Metadata::merge( $metadatas ) |
|
193 | + Metadata::merge($metadatas) |
|
194 | 194 | ); |
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
198 | 198 | return new CachedBool( |
199 | 199 | false, |
200 | - Metadata::merge( $metadatas ) |
|
200 | + Metadata::merge($metadatas) |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
204 | - private function hasCorrectType( Snak $mainSnak ) { |
|
204 | + private function hasCorrectType(Snak $mainSnak) { |
|
205 | 205 | return $mainSnak instanceof PropertyValueSnak |
206 | 206 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
207 | 207 | } |
@@ -218,12 +218,12 @@ discard block |
||
218 | 218 | ) { |
219 | 219 | $statementArrays = []; |
220 | 220 | |
221 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
222 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
223 | - $statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray(); |
|
221 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
222 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
223 | + $statementArrays[] = $statements->getByPropertyId($propertyId)->toArray(); |
|
224 | 224 | } |
225 | 225 | |
226 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
226 | + return call_user_func_array('array_merge', $statementArrays); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -235,10 +235,10 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return ViolationMessage |
237 | 237 | */ |
238 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
238 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
239 | 239 | $classes = array_map( |
240 | - function( $itemIdSerialization ) { |
|
241 | - return new ItemId( $itemIdSerialization ); |
|
240 | + function($itemIdSerialization) { |
|
241 | + return new ItemId($itemIdSerialization); |
|
242 | 242 | }, |
243 | 243 | $classes |
244 | 244 | ); |
@@ -250,10 +250,10 @@ discard block |
||
250 | 250 | // wbqc-violation-message-valueType-instance |
251 | 251 | // wbqc-violation-message-valueType-subclass |
252 | 252 | // wbqc-violation-message-valueType-instanceOrSubclass |
253 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
254 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
255 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
256 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
253 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
254 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
255 | + ->withEntityId($entityId, Role::SUBJECT) |
|
256 | + ->withEntityIdList($classes, Role::OBJECT); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | } |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | // no parent::__construct() call |
23 | 23 | } |
24 | 24 | |
25 | - public function hasType( $id, array $classes, $withInstance ) { |
|
26 | - throw new LogicException( 'methods of this class should never be called' ); |
|
25 | + public function hasType($id, array $classes, $withInstance) { |
|
26 | + throw new LogicException('methods of this class should never be called'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function findEntitiesWithSameStatement( |
30 | 30 | Statement $statement, |
31 | 31 | $ignoreDeprecatedStatements |
32 | 32 | ) { |
33 | - throw new LogicException( 'methods of this class should never be called' ); |
|
33 | + throw new LogicException('methods of this class should never be called'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | public function findEntitiesWithSameQualifierOrReference( |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | $type, |
40 | 40 | $ignoreDeprecatedStatements |
41 | 41 | ) { |
42 | - throw new LogicException( 'methods of this class should never be called' ); |
|
42 | + throw new LogicException('methods of this class should never be called'); |
|
43 | 43 | } |
44 | 44 | |
45 | - public function matchesRegularExpression( $text, $regex ) { |
|
46 | - throw new LogicException( 'methods of this class should never be called' ); |
|
45 | + public function matchesRegularExpression($text, $regex) { |
|
46 | + throw new LogicException('methods of this class should never be called'); |
|
47 | 47 | } |
48 | 48 | |
49 | - public function runQuery( $query ) { |
|
50 | - throw new LogicException( 'methods of this class should never be called' ); |
|
49 | + public function runQuery($query) { |
|
50 | + throw new LogicException('methods of this class should never be called'); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -64,22 +64,22 @@ discard block |
||
64 | 64 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
65 | 65 | * @return CheckResult |
66 | 66 | */ |
67 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
68 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
69 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
67 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
68 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
69 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $parameters = []; |
73 | 73 | |
74 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
75 | - if ( $context->getType() === 'statement' ) { |
|
74 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
75 | + if ($context->getType() === 'statement') { |
|
76 | 76 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
77 | 77 | $context->getSnakStatement(), |
78 | 78 | true // ignore deprecated statements |
79 | 79 | ); |
80 | 80 | } else { |
81 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
82 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
81 | + if ($context->getSnak()->getType() !== 'value') { |
|
82 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
83 | 83 | } |
84 | 84 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
85 | 85 | $context->getEntity()->getId(), |
@@ -92,27 +92,27 @@ discard block |
||
92 | 92 | $otherEntities = $result->getArray(); |
93 | 93 | $metadata = $result->getMetadata(); |
94 | 94 | |
95 | - if ( $otherEntities === [] ) { |
|
95 | + if ($otherEntities === []) { |
|
96 | 96 | $status = CheckResult::STATUS_COMPLIANCE; |
97 | 97 | $message = null; |
98 | 98 | } else { |
99 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
99 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
100 | 100 | $status = CheckResult::STATUS_VIOLATION; |
101 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
102 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
101 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
102 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | 105 | $status = CheckResult::STATUS_TODO; |
106 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
107 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
106 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
107 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
108 | 108 | $metadata = Metadata::blank(); |
109 | 109 | } |
110 | 110 | |
111 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
112 | - ->withMetadata( $metadata ); |
|
111 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
112 | + ->withMetadata($metadata); |
|
113 | 113 | } |
114 | 114 | |
115 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
115 | + public function checkConstraintParameters(Constraint $constraint) { |
|
116 | 116 | // no parameters |
117 | 117 | return []; |
118 | 118 | } |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | * @throws ConstraintParameterException |
86 | 86 | * @return CheckResult |
87 | 87 | */ |
88 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
88 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
89 | 89 | $parameters = []; |
90 | 90 | $constraintParameters = $constraint->getConstraintParameters(); |
91 | 91 | |
92 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
93 | - $parameters['pattern'] = [ $format ]; |
|
92 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
93 | + $parameters['pattern'] = [$format]; |
|
94 | 94 | |
95 | 95 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
96 | 96 | $constraintParameters |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | |
99 | 99 | $snak = $context->getSnak(); |
100 | 100 | |
101 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
101 | + if (!$snak instanceof PropertyValueSnak) { |
|
102 | 102 | // nothing to check |
103 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
103 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $dataValue = $snak->getDataValue(); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * error handling: |
110 | 110 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
111 | 111 | */ |
112 | - switch ( $dataValue->getType() ) { |
|
112 | + switch ($dataValue->getType()) { |
|
113 | 113 | case 'string': |
114 | 114 | $text = $dataValue->getValue(); |
115 | 115 | break; |
@@ -118,49 +118,49 @@ discard block |
||
118 | 118 | $text = $dataValue->getText(); |
119 | 119 | break; |
120 | 120 | default: |
121 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
122 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
123 | - ->withDataValueType( 'string' ) |
|
124 | - ->withDataValueType( 'monolingualtext' ); |
|
125 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
121 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
122 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
123 | + ->withDataValueType('string') |
|
124 | + ->withDataValueType('monolingualtext'); |
|
125 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | if ( |
129 | - !( $this->sparqlHelper instanceof DummySparqlHelper ) && |
|
130 | - $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) |
|
129 | + !($this->sparqlHelper instanceof DummySparqlHelper) && |
|
130 | + $this->config->get('WBQualityConstraintsCheckFormatConstraint') |
|
131 | 131 | ) { |
132 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
132 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
133 | 133 | $message = null; |
134 | 134 | $status = CheckResult::STATUS_COMPLIANCE; |
135 | 135 | } else { |
136 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
137 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
138 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
139 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
140 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
136 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
137 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
138 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
139 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
140 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
141 | 141 | $status = CheckResult::STATUS_VIOLATION; |
142 | 142 | } |
143 | 143 | } else { |
144 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
145 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
144 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
145 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
146 | 146 | $status = CheckResult::STATUS_TODO; |
147 | 147 | } |
148 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
148 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
149 | 149 | } |
150 | 150 | |
151 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
151 | + public function checkConstraintParameters(Constraint $constraint) { |
|
152 | 152 | $constraintParameters = $constraint->getConstraintParameters(); |
153 | 153 | $exceptions = []; |
154 | 154 | try { |
155 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
156 | - } catch ( ConstraintParameterException $e ) { |
|
155 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
156 | + } catch (ConstraintParameterException $e) { |
|
157 | 157 | $exceptions[] = $e; |
158 | 158 | } |
159 | 159 | try { |
160 | 160 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
161 | 161 | $constraintParameters |
162 | 162 | ); |
163 | - } catch ( ConstraintParameterException $e ) { |
|
163 | + } catch (ConstraintParameterException $e) { |
|
164 | 164 | $exceptions[] = $e; |
165 | 165 | } |
166 | 166 | return $exceptions; |